Last active
January 3, 2016 18:58
-
-
Save objectivehtml/8505185 to your computer and use it in GitHub Desktop.
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 | |
// This is a module method. Use it like so... | |
// {exp:module_name:class_achievements course_url_title="{segment_3}"} | |
public function class_achievements() | |
{ | |
// Course is a model I created. findUrlTitle() is an inherited static method | |
if(!$course = Course::findByUrlTitle($this->param('course_url_title'))) | |
{ | |
// If no course is found, return the noResults() method. | |
return ChannelEntriesParser::noResults(); | |
} | |
// Achievements is another model that is related to courses. Course | |
// has a method name achievements to fetch these related models. | |
if(!$achievements = $course->achievements()) | |
{ | |
// And if no achievements, return noResults() method. | |
return ChannelEntriesParser::noResults(); | |
} | |
// If all is successfully, return the related achievements as a Channel Entries loop | |
return $achievements->entries(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment