コード例 #1
0
 /**
  * Set the value of this element.
  *
  * @param  string|array $value The value to set.
  * @return boolean
  */
 public function setValue($value)
 {
     global $DB;
     $values = (array) $value;
     $ids = array();
     foreach ($values as $onevalue) {
         if (!$this->optionExists($onevalue) && $onevalue !== '_qf__force_multiselect_submission') {
             array_push($ids, $onevalue);
         }
     }
     if (empty($ids)) {
         return $this->setSelected(array());
     }
     // Logic here is simulating API.
     $toselect = array();
     list($insql, $inparams) = $DB->get_in_or_equal($ids, SQL_PARAMS_NAMED, 'param');
     $frameworks = competency_framework::get_records_select("id {$insql}", $inparams, 'shortname');
     foreach ($frameworks as $framework) {
         if (!has_any_capability(array('moodle/competency:competencyview', 'moodle/competency:competencymanage'), $framework->get_context())) {
             continue;
         } else {
             if ($this->onlyvisible && !$framework->get_visible()) {
                 continue;
             }
         }
         $this->addOption($framework->get_shortname() . ' ' . $framework->get_idnumber(), $framework->get_id());
         array_push($toselect, $framework->get_id());
     }
     return $this->setSelected($toselect);
 }
コード例 #2
0
ファイル: api.php プロジェクト: gabrielrosset/moodle
 /**
  * Perform a search based on the provided filters and return a paginated list of records.
  *
  * Requires moodle/competency:competencyview 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 true return only visible frameworks
  * @param string $query A string to use to filter down the frameworks.
  * @return array of competency_framework
  */
 public static function list_frameworks($sort, $order, $skip, $limit, $context, $includes = 'children', $onlyvisible = false, $query = '')
 {
     global $DB;
     static::require_enabled();
     // Get all the relevant contexts.
     $contexts = self::get_related_contexts($context, $includes, array('moodle/competency:competencyview', 'moodle/competency:competencymanage'));
     if (empty($contexts)) {
         throw new required_capability_exception($context, 'moodle/competency:competencyview', 'nopermissions', '');
     }
     // OK - all set.
     list($insql, $inparams) = $DB->get_in_or_equal(array_keys($contexts), SQL_PARAMS_NAMED);
     $select = "contextid {$insql}";
     if ($onlyvisible) {
         $select .= " AND visible = :visible";
         $inparams['visible'] = 1;
     }
     if (!empty($query) || is_numeric($query)) {
         $sqlnamelike = $DB->sql_like('shortname', ':namelike', false);
         $sqlidnlike = $DB->sql_like('idnumber', ':idnlike', false);
         $select .= " AND ({$sqlnamelike} OR {$sqlidnlike}) ";
         $inparams['namelike'] = '%' . $DB->sql_like_escape($query) . '%';
         $inparams['idnlike'] = '%' . $DB->sql_like_escape($query) . '%';
     }
     return competency_framework::get_records_select($select, $inparams, $sort . ' ' . $order, '*', $skip, $limit);
 }