コード例 #1
0
 /**
  * Constructor
  *
  * @param string $elementName Element name
  * @param mixed $elementLabel Label(s) for an element
  * @param array $options Options to control the element's display
  * @param mixed $attributes Either a typical HTML attribute string or an associative array.
  */
 public function __construct($elementName = null, $elementLabel = null, $options = array(), $attributes = null)
 {
     global $OUTPUT;
     if ($elementName == null) {
         // This is broken quickforms messing with the constructors.
         return;
     }
     if (!isset($options['courseid'])) {
         throw new coding_exception('Course id is required for the course_competencies form element');
     }
     $courseid = $options['courseid'];
     if (!empty($options['cmid'])) {
         $current = \core_competency\api::list_course_module_competencies_in_course_module($options['cmid']);
         $ids = array();
         foreach ($current as $coursemodulecompetency) {
             array_push($ids, $coursemodulecompetency->get_competencyid());
         }
         $this->setValue($ids);
     }
     $competencies = api::list_course_competencies($courseid);
     $validoptions = array();
     $context = context_course::instance($courseid);
     foreach ($competencies as $competency) {
         // We don't need to show the description as part of the options, so just set this to null.
         $competency['competency']->set_description(null);
         $exporter = new competency_exporter($competency['competency'], array('context' => $context));
         $templatecontext = array('competency' => $exporter->export($OUTPUT));
         $id = $competency['competency']->get_id();
         $validoptions[$id] = $OUTPUT->render_from_template('tool_lp/competency_summary', $templatecontext);
     }
     $attributes['tags'] = false;
     $attributes['multiple'] = 'multiple';
     parent::__construct($elementName, $elementLabel, $validoptions, $attributes);
 }
コード例 #2
0
ファイル: autocomplete_test.php プロジェクト: evltuma/moodle
 /**
  * Testcase for validation
  */
 public function test_validation()
 {
     // A default select with single values validates the data.
     $options = array('1' => 'One', 2 => 'Two');
     $element = new MoodleQuickForm_autocomplete('testel', null, $options);
     $submission = array('testel' => 2);
     $this->assertEquals($element->exportValue($submission), 2);
     $submission = array('testel' => 3);
     $this->assertNull($element->exportValue($submission));
     // A select with multiple values validates the data.
     $options = array('1' => 'One', 2 => 'Two');
     $element = new MoodleQuickForm_autocomplete('testel', null, $options, array('multiple' => 'multiple'));
     $submission = array('testel' => array(2, 3));
     $this->assertEquals($element->exportValue($submission), array(2));
     // A select where the values are fetched via ajax does not validate the data.
     $element = new MoodleQuickForm_autocomplete('testel', null, array(), array('multiple' => 'multiple', 'ajax' => 'anything'));
     $submission = array('testel' => array(2, 3));
     $this->assertEquals($element->exportValue($submission), array(2, 3));
 }
コード例 #3
0
ファイル: course.php プロジェクト: rushi963/moodle
 /**
  * Constructor
  *
  * @param string $elementname Element name
  * @param mixed $elementlabel Label(s) for an element
  * @param array $options Options to control the element's display
  *                       Valid options are:
  *                       'multiple' - boolean multi select
  *                       'exclude' - array or int, list of course ids to never show
  *                       'requiredcapabilities' - array of capabilities. Uses ANY to combine them.
  */
 public function __construct($elementname = null, $elementlabel = null, $options = array())
 {
     if (isset($options['multiple'])) {
         $this->multiple = $options['multiple'];
     }
     if (isset($options['exclude'])) {
         $this->exclude = $options['exclude'];
         if (!is_array($this->exclude)) {
             $this->exclude = array($this->exclude);
         }
     }
     if (isset($options['requiredcapabilities'])) {
         $this->requiredcapabilities = $options['requiredcapabilities'];
     }
     $validattributes = array('ajax' => 'core/form-course-selector', 'data-requiredcapabilities' => implode(',', $this->requiredcapabilities), 'data-exclude' => implode(',', $this->exclude));
     if ($this->multiple) {
         $validattributes['multiple'] = 'multiple';
     }
     parent::__construct($elementname, $elementlabel, array(), $validattributes);
 }
コード例 #4
0
ファイル: tags.php プロジェクト: rushi963/moodle
 /**
  * Returns a 'safe' element's value
  *
  * @param  array  $submitValues array of submitted values to search
  * @param  bool   $assoc        whether to return the value as associative array
  * @return mixed
  */
 public function exportValue(&$submitValues, $assoc = false)
 {
     if (!$this->is_tagging_enabled()) {
         return $assoc ? array($this->getName() => array()) : array();
     }
     return parent::exportValue($submitValues, $assoc);
 }
コード例 #5
0
ファイル: course.php プロジェクト: evltuma/moodle
 /**
  * Constructor
  *
  * @param string $elementname Element name
  * @param mixed $elementlabel Label(s) for an element
  * @param array $options Options to control the element's display
  *                       Valid options are:
  *                       'multiple' - boolean multi select
  *                       'exclude' - array or int, list of course ids to never show
  *                       'requiredcapabilities' - array of capabilities. Uses ANY to combine them.
  *                       'limittoenrolled' - boolean Limits to enrolled courses.
  *                       'includefrontpage' - boolean Enables the frontpage to be selected.
  */
 public function __construct($elementname = null, $elementlabel = null, $options = array())
 {
     if (isset($options['multiple'])) {
         $this->multiple = $options['multiple'];
     }
     if (isset($options['exclude'])) {
         $this->exclude = $options['exclude'];
         if (!is_array($this->exclude)) {
             $this->exclude = array($this->exclude);
         }
     }
     if (isset($options['requiredcapabilities'])) {
         $this->requiredcapabilities = $options['requiredcapabilities'];
     }
     if (isset($options['limittoenrolled'])) {
         $this->limittoenrolled = $options['limittoenrolled'];
     }
     $validattributes = array('ajax' => 'core/form-course-selector', 'data-requiredcapabilities' => implode(',', $this->requiredcapabilities), 'data-exclude' => implode(',', $this->exclude), 'data-limittoenrolled' => (int) $this->limittoenrolled);
     if ($this->multiple) {
         $validattributes['multiple'] = 'multiple';
     }
     if (isset($options['noselectionstring'])) {
         $validattributes['noselectionstring'] = $options['noselectionstring'];
     }
     if (isset($options['placeholder'])) {
         $validattributes['placeholder'] = $options['placeholder'];
     }
     if (!empty($options['includefrontpage'])) {
         $validattributes['data-includefrontpage'] = SITEID;
     }
     parent::__construct($elementname, $elementlabel, array(), $validattributes);
 }
コード例 #6
0
ファイル: tags.php プロジェクト: nitinnagaraja/moodle
 /**
  * Returns HTML for select form element.
  *
  * @return string
  */
 function toHtml()
 {
     global $CFG, $OUTPUT;
     if (empty($CFG->usetags)) {
         debugging('A tags formslib field has been created even thought $CFG->usetags is false.', DEBUG_DEVELOPER);
     }
     $managelink = '';
     if (has_capability('moodle/tag:manage', context_system::instance()) && $this->showingofficial) {
         $url = $CFG->wwwroot . '/tag/manage.php';
         $managelink = ' ' . $OUTPUT->action_link($url, get_string('manageofficialtags', 'tag'));
     }
     return parent::toHTML() . $managelink;
 }
コード例 #7
0
ファイル: tags.php プロジェクト: gabrielrosset/moodle
 public function export_for_template(renderer_base $output)
 {
     $context = parent::export_for_template($output);
     if (has_capability('moodle/tag:manage', context_system::instance()) && $this->showstandard) {
         $url = new moodle_url('/tag/manage.php', array('tc' => $this->get_tag_collection()));
         $context['managestandardtagsurl'] = $url->out(false);
     }
     return $context;
 }
コード例 #8
0
 /**
  * Constructor
  *
  * @param string $elementname Element name
  * @param mixed $elementlabel Label(s) for an element
  * @param array $options List of valid options for the select
  * @param array $attributes List of HTML attributes for the select
  */
 public function __construct($elementname = null, $elementlabel = null, $options = [], $attributes = [])
 {
     unset($options['']);
     $options = ['' => get_string('noselection', 'form')] + $options;
     parent::__construct($elementname, $elementlabel, $options, $attributes);
 }