. /** * Class containing data for my overview block. * * @package block_myoverview * @copyright 2017 Ryan Wyllie * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace block_myoverview\output; defined('MOODLE_INTERNAL') || die(); use renderable; use renderer_base; use templatable; require_once($CFG->dirroot . '/blocks/myoverview/lib.php'); /** * Class containing data for my overview block. * * @copyright 2018 Bas Brands * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class main implements renderable, templatable { /** * Store the grouping preference * * @var string String matching the grouping constants defined in myoverview/lib.php */ private $grouping; /** * Store the sort preference * * @var string String matching the sort constants defined in myoverview/lib.php */ private $sort; /** * Store the view preference * * @var string String matching the view/display constants defined in myoverview/lib.php */ private $view; /** * Store the paging preference * * @var string String matching the paging constants defined in myoverview/lib.php */ private $paging; /** * Store the display categories config setting * * @var boolean */ private $displaycategories; /** * main constructor. * Initialize the user preferences * * @param string $grouping Grouping user preference * @param string $sort Sort user preference * @param string $view Display user preference */ public function __construct($grouping, $sort, $view, $paging) { $this->grouping = $grouping ? $grouping : BLOCK_MYOVERVIEW_GROUPING_ALL; $this->sort = $sort ? $sort : BLOCK_MYOVERVIEW_SORTING_TITLE; $this->view = $view ? $view : BLOCK_MYOVERVIEW_VIEW_CARD; $this->paging = $paging ? $paging : BLOCK_MYOVERVIEW_PAGING_12; $config = get_config('block_myoverview'); if (!$config->displaycategories) { $this->displaycategories = BLOCK_MYOVERVIEW_DISPLAY_CATEGORIES_OFF; } else { $this->displaycategories = BLOCK_MYOVERVIEW_DISPLAY_CATEGORIES_ON; } } /** * Get the user preferences as an array to figure out what has been selected * * @return array $preferences Array with the pref as key and value set to true */ public function get_preferences_as_booleans() { $preferences = []; $preferences[$this->view] = true; $preferences[$this->sort] = true; $preferences[$this->grouping] = true; return $preferences; } /** * Export this data so it can be used as the context for a mustache template. * * @param \renderer_base $output * @return array Context variables for the template */ public function export_for_template(renderer_base $output) { $nocoursesurl = $output->image_url('courses', 'block_myoverview')->out(); $defaultvariables = [ 'nocoursesimg' => $nocoursesurl, 'grouping' => $this->grouping, 'sort' => $this->sort == BLOCK_MYOVERVIEW_SORTING_TITLE ? 'fullname' : 'ul.timeaccess desc', 'view' => $this->view, 'paging' => $this->paging, 'displaycategories' => $this->displaycategories, ]; $preferences = $this->get_preferences_as_booleans(); return array_merge($defaultvariables, $preferences); } }