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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

All other Modules /

Discuss all other Modules here.

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

Calendar Event Module Events only showing if logged in


Go to End


3 Posts   967 Views

Avatar
Vix

Community Member, 60 Posts

25 June 2013 at 5:11pm

Hello, I have a site in 2.4.10 and I have numerous Calendars through out the site, which are all good.

However I have one quirky problem that I just can't figure out.

I have extended the Calendar with the following code:

class SocialEventHolder extends Calendar {
	static $has_one = array (
		'CalendarPDF' => 'File'
	);
	
	static $has_many = array (
		'SocialEvents' => 'SocialEvent'
	);
	
    static $allowed_children = array('SocialEvent');

    //static $hide_ancestor = 'Calendar';
	
	public function getCMSFields() {
        $f = parent::getCMSFields();
        $f->addFieldToTab("Root.Content.Files", new FileIFrameField('CalendarPDF',_t('SocialEventHolder.CALENDARPDF','PDF')));
        return $f;
    }

}
class SocialEventHolder_Controller extends Calendar_Controller {
	
	public function AllSocialEvents() {
		if(!isset($_GET['start']) || !is_numeric($_GET['start']) || (int)$_GET['start'] < 1) $_GET['start'] = 0;
		$SQL_start = (int)$_GET['start'];
		$events = DataObject::get("CalendarDateTime","StartDate > NOW() AND CalendarDateTime.ClassName = 'SocialEventDateTime'","StartDate, StartTime", "LEFT JOIN SiteTree ON CalendarDateTime.EventID=SiteTree.ID LEFT JOIN SocialEvent ON CalendarDateTime.ID=SocialEvent.ID");
		
		$doSet = new DataObjectSet();
		foreach ($events as $event) {
			if ($event->canView()) {
				$doSet->push($event);
				      }
				}
			$doSet->setPageLimits($SQL_start, 3, $doSet->Count());
			return $doSet;
	}

....

And in my template I have this:

<% if AllSocialEvents %>
            
               	<% control AllSocialEvents.Pagination %>
                	<div class="news_box">
                    	<div class="info<% control Event %><% if EventImage %> withimage<% end_if %><% end_control %>">
                          <h2><a href="$Link">$EventTitle</a></h2>
                          <p class="dates">DATE: $StartDate.format(l jS F Y)</p>
                          <% control Event %>
                          	
                          	$Summary
                            
                            <% if EventFlyer %>
                          	<p><a href="$EventFlyer.Link" class="more" target="_blank">View the Flyer &gt;</a></p>
                          	<% end_if %>
                          <% end_control %>
                          
                          
                        </div>
                        
                        <% control Event %>
                        	<% if EventImage %>
                        		<div class="news_thumbnail">
                            		$EventImage.SetWidth(220)
                            	</div>
                        	<% end_if %>
                        <% end_control %>
                        
                        <div class="clear"></div>
                    </div>
                <% end_control %>
                
                <% if AllSocialEvents.MoreThanOnePage %>
                  <div class="pagination">
                  	<% if AllSocialEvents.PrevLink %><a href="$AllSocialEvents.PrevLink">&lt; Prev</a><% end_if %>
                    
                    <% control AllSocialEvents.Pages %>
                    	<% if CurrentBool %><strong>$PageNum</strong><% else %><a href="$Link" title="Go to page $PageNum">$PageNum</a><% end_if %>
                    <% end_control %>
                    
                    <% if AllSocialEvents.NextLink %><a href="$AllSocialEvents.NextLink">Next &gt;</a><% end_if %>
                    
                  </div>
               <% end_if %>
               
            <% end_if %>

This all works great... IF I am logged into the CMS. If not, it just displays a blank area where the social events belong. Is there something I need to set in order for this to be viewable by anyone? There is nothing about this page that should restrict viewing it to anyone. I have not set any restrictions for this page anywhere.

The function itself still runs (I echoed an alert with the ID of each record and they all popped up), and I have tried changing the function to only have

$events = DataObject::get("CalendarDateTime","StartDate > NOW() AND CalendarDateTime.ClassName = 'SocialEventDateTime'","StartDate, StartTime", "LEFT JOIN SiteTree ON CalendarDateTime.EventID=SiteTree.ID LEFT JOIN SocialEvent ON CalendarDateTime.ID=SocialEvent.ID");
return $events;

And this still does not display if not logged in.

If anyone can point me in the right direction that would be much appreciated.

Thanks

Avatar
Vix

Community Member, 60 Posts

3 July 2013 at 3:21pm

Has anyone got any ideas?

Avatar
Vix

Community Member, 60 Posts

9 July 2013 at 4:23pm

in case anyone else ever has the same problem...

When this occurred on a different site I was able to determine what the problem was. It comes from the function setting up the pagination.

foreach ($events as $event) { 
         if ($event->canView()) { 
            $doSet->push($event); 
             } 
            } 

I removed the 'if($event->canView()){' and this has allowed it to be visible when not logged in.