/** * Return contents of moodec_courses block * * @return stdClass contents of block */ public function get_content() { global $USER, $CFG, $DB; require_once $CFG->dirroot . '/local/moodec/lib.php'; if ($this->content !== NULL) { return $this->content; } // $config = get_config('block_moodec_courses'); $this->content = new stdClass(); $this->content->text = ''; $this->content->footer = ''; if (!empty($this->config)) { // Check config for which courses to select if ((int) $this->config->course_selection === 0) { // Return latest courses $products = local_moodec_get_products(-1, null, 'timecreated', 'DESC'); $products = array_slice($products, 0, $this->config->courses_shown); } elseif ((int) $this->config->course_selection === 1) { // Return random courses $products = local_moodec_get_random_products($this->config->courses_shown); } else { // TODO: Add return manual courses $products = array(); for ($i = 1; $i <= $this->config->courses_shown; $i++) { $manual = 'manual_course_' . $i; $newProduct = local_moodec_get_product((int) $this->config->{$manual}); if (!!$newProduct) { $products[] = $newProduct; } } } // Render HTML $renderer = $this->page->get_renderer('block_moodec_courses'); $this->content->text = $renderer->output_products($products, $this->config); } return $this->content; }
/** * Return array of related products * @param int $limit the max number of related products to be returned * @return array products */ public function get_related($limit = 3) { // TODO: Figure out where to set limit // Perhaps plugin settings? // Or just stay as parameter? // We get random products that are in the same category as this product return local_moodec_get_random_products($limit, $this->_categoryid, $this->_id); }