Skip to content

Instantly share code, notes, and snippets.

@jonom
Last active August 29, 2015 14:23
Show Gist options
  • Save jonom/9b42115a21107e2e3537 to your computer and use it in GitHub Desktop.
Save jonom/9b42115a21107e2e3537 to your computer and use it in GitHub Desktop.
SilverStripe code competition entry
<?php
/**
* Hello Page.
* Landing page for users when they log in to the website
* @author jonom
*/
class HelloPage_controller extends Page_controller {
/**
* Restrict access to logged in users at a minimum
* @return bool
*/
public function canView($member = null) {
return (!parent::canView($member) || !Member::currentUserID()) ? false : true;
}
/**
* Provide a personalised welcome message for logged in users
* @return string
*/
public function WelcomeMessage() {
$member = Member::currentUser();
if ($member->isBirthday()) return "Happy Birthday $member->FirstName!";
else return "Welcome $member->FirstName! Make yourself at home.";
}
/**
* Produce a combined list of public announcements and personal notifications
* @return DataList
*/
public function Notifications() {
return Notification::get()->filterAny(array(
'MemberID' => $this->Member::currentUserID(),
'Public' => true
))->exclude('Dismissed', true)->sort('Created DESC');
}
/**
* Display a random special offer to the user
* @return SpecialOffer | bool False
*/
public function RandomOffer() {
return SpecialOffer::get()->sort('RAND()')->first();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment