Last active
August 29, 2015 14:23
-
-
Save jonom/9b42115a21107e2e3537 to your computer and use it in GitHub Desktop.
SilverStripe code competition entry
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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