Exemplo n.º 1
0
 /**
  * Perform a search based on the provided filters and return a paginated list of records.
  *
  * Requires moodle/competency:templateview capability at the system context.
  *
  * @param string $sort The column to sort on
  * @param string $order ('ASC' or 'DESC')
  * @param int $skip Number of records to skip (pagination)
  * @param int $limit Max of records to return (pagination)
  * @param context $context The parent context of the frameworks.
  * @param string $includes Defines what other contexts to fetch frameworks from.
  *                         Accepted values are:
  *                          - children: All descendants
  *                          - parents: All parents, grand parents, etc...
  *                          - self: Context passed only.
  * @param bool $onlyvisible If should list only visible templates
  * @return array of competency_framework
  */
 public static function list_templates($sort, $order, $skip, $limit, $context, $includes = 'children', $onlyvisible = false)
 {
     global $DB;
     static::require_enabled();
     // Get all the relevant contexts.
     $contexts = self::get_related_contexts($context, $includes, array('moodle/competency:templateview', 'moodle/competency:templatemanage'));
     // First we do a permissions check.
     if (empty($contexts)) {
         throw new required_capability_exception($context, 'moodle/competency:templateview', 'nopermissions', '');
     }
     // Make the order by.
     $orderby = '';
     if (!empty($sort)) {
         $orderby = $sort . ' ' . $order;
     }
     // OK - all set.
     $template = new template();
     list($insql, $params) = $DB->get_in_or_equal(array_keys($contexts), SQL_PARAMS_NAMED);
     $select = "contextid {$insql}";
     if ($onlyvisible) {
         $select .= " AND visible = :visible";
         $params['visible'] = 1;
     }
     return $template->get_records_select($select, $params, $orderby, '*', $skip, $limit);
 }