Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, biapar, Willr, Ingo, swaiba, simon_w

Weird output from DataObject


Reply


6 Posts   1105 Views

Avatar
Tigerlilly

Community Member, 16 Posts

1 March 2010 at 12:39am

Edited: 01/03/2010 12:40am

Hi there

I am trying to generate a "tooltip" of an event title using the Event_Calendar module I have used the following code to extract the title
$Where="StartDate='$check_date'";
       $TitleDetails= DataObject::get("CalendarDateTime", $Where);
       if($TitleDetails){
       $Title=$TitleDetails;
              }
       else
       $Title="There are No Event Listed";
       return $Title;

This is what it outputs on my template
<ul id="Menu1">
<li onclick="location.href = this.getElementsByTagName('a')[0].href"><a href="">Pirates Picnic Christchurch</a></li>
</ul>

If I try to use
$Where="StartDate='$check_date'";
       $TitleDetails= DataObject::get("CalendarDateTime", $Where);
       if($TitleDetails){
       $Title=$TitleDetails->Title;
              }
       else
       $Title="There are No Event Listed";
       return $Title;

Then I get nothing show up.

All I want is for the field "Title" in the CalendarDateTime table to show without the ul menu??

Please help

Thanks

Avatar
UncleCheese

Forum Moderator, 4096 Posts

1 March 2010 at 4:56am

That's because you're not returning a DataObject at all. You're returning a DataObjectSet. The output that you're getting is the forTempate() method of a DataObject set -- show all of its components in a UL. Usually only used for debugging.

Where is the rest of this function, and how is it being called on the template?

Avatar
Tigerlilly

Community Member, 16 Posts

1 March 2010 at 7:36am

Edited: 01/03/2010 7:37am

Thanks for your prompt reply

Basically it is part of the class LiveCalendarWidget extends ViewableData, getWeeks() function in the CalendarUI.class.php. It checks the dates and returns information about whether or not they have an event on that day and outputs to the calendar. I have extended the CalendarDateTime class to include a title which I would like to show when a person rolls over a date on the calendar, so I have added the following:
private function getWeeks()
{
$weeks = new DataObjectSet();
$today = new sfDate();
$today->clearTime();
$this->date_counter->firstDayOfMonth()->firstDayOfWeek();
$view_start = new sfDate($this->date_counter->get());
$view_end = new sfDate($view_start->addDay($this->rows*7)->subtractDay()->get());
$view_start->reset();
$this->start_date->reset();
$event_map = $this->getEventsFor($view_start, $view_end);
// $title_details = $this->getDetails($view_start, $view_end);
   
      for($i=0; $i < $this->rows; $i++)
      {
       $days = new DataObjectSet();
       $week_range_start = $this->date_counter->format('Ymd');
         for($j=0; $j < 7; $j++)
         {
            $current_day = "";
            if(!$this->default_view) {
             if( ($this->date_counter->get() >= $this->anchor_start->get()) && ($this->date_counter->get() <= $this->anchor_end->get()) )
             $current_day = "currentDay";
            $Title="";
       $check_date=$this->date_counter->date();
       $Title=$this->getTitle($check_date); # This is the function call to get the title information

}      
            $days->push(new ArrayData(array(
             'Today' => $this->date_counter->get() == $today->get() ? "calendarToday" : "",
             'OutOfMonth' => $this->date_counter->format('m') != $this->start_date->format('m') ? "calendarOutOfMonth" : "",
             'CurrentDay' => $current_day,
             'HasEvent' => in_array($this->date_counter->date(), $event_map) ? "hasEvent" : "",
             'ShowDayLink' => $this->calendar->Link($this->date_counter->format('Ymd')),
             'Number' => $this->date_counter->format('d'),
             'Title' => $Title#This is my title information
            )));
            $this->date_counter->addDay();
         }
         $week_range_end = $this->date_counter->subtractDay()->format('Ymd');
         $this->date_counter->addDay();
         $weeks->push(new ArrayData(array(
          'Days' => $days,
          'ShowWeekLink' => $this->calendar->Link($week_range_start."/".$week_range_end)
         )));
      }
      return $weeks;
}

In the LiveCalendarWidget.ss file I have the following:
   <tbody>
<% control Weeks %>
      <tr>
      <% control Days %>
         <td class="$Today $OutOfMonth $CurrentDay $HasEvent">
          <a href="$ShowDayLink" onmouseover="TagToTip($Number)" onmouseout="UnTip()" id="tooltip">$Number</a><span id="$Number" class="pop_up"> $Title</span>
         </td>
<% end_control %>
         </tr>
<% end_control %>
   </tbody>

The getTitle function is out lined previously

Avatar
Tigerlilly

Community Member, 16 Posts

1 March 2010 at 8:03am

With your comments above I have figured it out changed function to:

private function getTitle($check_date){
       $Where="StartDate='$check_date'";
       $TitleDetails= DataObject::get("CalendarDateTime", $Where);
       if($TitleDetails){
       foreach($TitleDetails as $TitleDetail) {
       $Title=$TitleDetail->Title;
       }
              }
       else
       $Title="There are No Event Listed";
       return $Title;
}
Thanks Heaps!!!!

Avatar
UncleCheese

Forum Moderator, 4096 Posts

1 March 2010 at 9:18am

That looks better, there ya go.

It's pretty concerning that you're modifying all that core code, though. That could have been done a lot more cleanly with a subclass and a custom template in your theme dir.

Avatar
Tigerlilly

Community Member, 16 Posts

1 March 2010 at 9:24am

Yey, I just wasn't sure how to do it, here the date is generated and info created based on that date. How would I link the exact title to the date (I dunno couldn't get my head around it??)

Cheers
Denise