Jump to:

10994 Posts in 2728 Topics by 1819 members

All other Modules

SilverStripe Forums » All other Modules » Use Event Calendar module in Includes for custom sidebar

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 1171 Views
  • vegetav
    Avatar
    Community Member
    23 Posts

    Use Event Calendar module in Includes for custom sidebar Link to this post

    I've installed the Events Calendar module, which is working fine. The site I'm building has various items such as a booking form and events diary which are included in the sidebar. I need have an include which displays the $MonthNavigator with a set amount of upcoming events under it which I can include on any page that required it throught the site.

    Does anyone know how this can be achieved?

  • UncleCheese
    Avatar
    4085 Posts

    Re: Use Event Calendar module in Includes for custom sidebar Link to this post

    The functions UpcomingEvents(), RecentEvents(), CalendarWidget() and LiveCalendarWidget() are all decorated into your SiteTree class, so you can call them anywhere. MonthNavigator() was not, but I have added it into the trunk (2.4 only).

    It's easy enough to do it yourself, though..

    return new MonthNavigator($your_calendar_object, new sfDate());

  • vegetav
    Avatar
    Community Member
    23 Posts

    Re: Use Event Calendar module in Includes for custom sidebar Link to this post

    Thanks for the reply. But I still can't seem to acheive what I'm looking for.

    In my Page_Controller in Code/Page.php i have

    function EventsDiary(){
    MonthNavigator($(this), new sfDate());
    }

    and in my includes/sidebar.ss I have

    <div>
    $EventsDiary
    </div>

    This displays the drop down box, but tried to redirect me to another page. I wan't to be able to select a month and it show me events in that month inside my sidebar, I've attached a png of what I'm trying to acheive.

    Thanks.

    Attached Files
  • UncleCheese
    Avatar
    4085 Posts

    Re: Use Event Calendar module in Includes for custom sidebar Link to this post

    This is not PHP syntax:

    $(this)

    That's jQuery.

    Your function isn't returning anything.

    public function EventsDiary(){
    return new MonthNavigator($this, new sfDate());
    }

    But if you're going to have this globally accessible, you can't use $this, because you don't know what page you're going to be on. So you need to pass it an object of the calendar you want to use.

    DataObject::get_one("Calendar") for instance.. or whatever you're using.

  • mattclegg
    Avatar
    Community Member
    56 Posts

    Re: Use Event Calendar module in Includes for custom sidebar Link to this post

    When including lists of events its useful to be able to filter which ones will appear through the cms. This can be done by changing getEventIds() to the following;

       protected function getEventIds()
       {
          $ids = array();
          if($children = $this->Children()) {
             if(!$this->site_mode='cms'){
                foreach($children as $child)
                   $ids[] = $child->ID;
                return $ids;
             }else{
             // 'I dont trust you with my children'
             //or joined if($children = DataObject::get("SiteTree", "ParentID='".$this->ID."' AND ShowInSearch=1","Created")) {
                $sqlQuery = new SQLQuery("ID","SiteTree","ParentID='".$this->ID."' AND ShowInSearch=1");
                $results=$sqlQuery->execute();
                foreach($results as $child)
                    $ids[] = $child['ID'];
                return $ids;
             }
          } else {
             return false;
          }
       }

    Can something like this be put into the next release?

  • UncleCheese
    Avatar
    4085 Posts

    Re: Use Event Calendar module in Includes for custom sidebar Link to this post

    That whole function is ugly. I can't see how getEventIDs() would make it into the next release in any form. It's just bad practice.

    1171 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.