public function definition()
 {
     global $USER;
     parent::definition();
     $mform = $this->_form;
     $ratingdata = $this->ratingallocate->get_rating_data_for_user($USER->id);
     foreach ($ratingdata as $data) {
         $headerelem = 'head_ratingallocate_' . $data->choiceid;
         $elemprefix = 'data[' . $data->choiceid . ']';
         $ratingelem = $elemprefix . '[rating]';
         $groupsidelem = $elemprefix . '[choiceid]';
         // choiceid ablegen
         $mform->addElement('hidden', $groupsidelem, $data->choiceid);
         $mform->setType($groupsidelem, PARAM_INT);
         // title anzeigen
         $mform->addElement('header', $headerelem, $data->title);
         $mform->setExpanded($headerelem);
         // Show max. number of allocations.
         // TODO add setting in order to make this optional, as requested in issue #14.
         $mform->addElement('html', '<div class="mod-ratingallocate-choice-maxno">' . '<span class="mod-ratingallocate-choice-maxno-desc">' . get_string('choice_maxsize_display', ratingallocate_MOD_NAME) . ':</span> <span class="mod-ratingallocate-choice-maxno-value">' . $data->maxsize . '</span></div>');
         // Use explanation as title/label of group to align with other strategies.
         $mform->addElement('text', $ratingelem, $data->explanation);
         $mform->setType($ratingelem, PARAM_INT);
         // try to restore previous ratings
         if (is_numeric($data->rating) && $data->rating >= 0) {
             $mform->setDefault($ratingelem, $data->rating);
         } else {
             $mform->setDefault($ratingelem, 1);
         }
     }
 }
 public function definition()
 {
     global $USER;
     parent::definition();
     $mform = $this->_form;
     $ratingdata = $this->ratingallocate->get_rating_data_for_user($USER->id);
     foreach ($ratingdata as $data) {
         $headerelem = 'head_ratingallocate_' . $data->choiceid;
         $elemprefix = 'data[' . $data->choiceid . ']';
         $ratingelem = $elemprefix . '[rating]';
         $groupsidelem = $elemprefix . '[choiceid]';
         // choiceid ablegen
         $mform->addElement('hidden', $groupsidelem, $data->choiceid);
         $mform->setType($groupsidelem, PARAM_INT);
         // title anzeigen
         $mform->addElement('header', $headerelem, $data->title);
         $mform->setExpanded($headerelem);
         // Beschreibungstext anzeigen
         $mform->addElement('html', '<div>' . $data->explanation . '</div>');
         $mform->addElement('text', $ratingelem, '');
         $mform->setType($ratingelem, PARAM_INT);
         // try to restore previous ratings
         if (is_numeric($data->rating) && $data->rating >= 0) {
             $mform->setDefault($ratingelem, $data->rating);
         } else {
             $mform->setDefault($ratingelem, 1);
         }
     }
 }
 /**
  * Defines forms elements
  */
 public function definition()
 {
     global $USER;
     parent::definition();
     $mform = $this->_form;
     $ratingdata = $this->ratingallocate->get_rating_data_for_user($USER->id);
     foreach ($ratingdata as $data) {
         $headerelem = 'head_ratingallocate_' . $data->choiceid;
         $elemprefix = 'data[' . $data->choiceid . ']';
         $ratingelem = $elemprefix . '[rating]';
         $groupsidelem = $elemprefix . '[choiceid]';
         // Save choiceid.
         $mform->addElement('hidden', $groupsidelem, $data->choiceid);
         $mform->setType($groupsidelem, PARAM_INT);
         // Show title.
         $mform->addElement('header', $headerelem, $data->title);
         $mform->setExpanded($headerelem);
         // Show max. number of allocations.
         // TODO add setting in order to make this optional, as requested in issue #14.
         $mform->addElement('html', '<div class="mod-ratingallocate-choice-maxno">' . '<span class="mod-ratingallocate-choice-maxno-desc">' . get_string('choice_maxsize_display', ratingallocate_MOD_NAME) . ':</span> <span class="mod-ratingallocate-choice-maxno-value">' . $data->maxsize . '</span></div>');
         // Options for each choice.
         $choiceoptions = $this->get_choiceoptions();
         $radioarray = array();
         foreach ($choiceoptions as $id => $option) {
             $radioarray[] =& $mform->createElement('radio', $ratingelem, '', $option, $id);
         }
         // Adding static elements to support css.
         $radioarray = $this->ratingallocate->prepare_horizontal_radio_choice($radioarray, $mform);
         // It is important to set a group name, so that later on errors can be displayed at the correct spot.
         // Furthermore, use explanation as title/label of group.
         $mform->addGroup($radioarray, 'radioarr_' . $data->choiceid, $data->explanation, null, false);
         $maxrating = max(array_keys($choiceoptions));
         // Try to restore previous ratings.
         if (is_numeric($data->rating) && $data->rating >= 0 && $data->rating <= $maxrating) {
             $mform->setDefault($ratingelem, $data->rating);
         } else {
             $mform->setDefault($ratingelem, $maxrating);
         }
         // $mform->setType($ratingelem, PARAM_INT);
     }
 }
 public function definition()
 {
     global $USER;
     parent::definition();
     $mform = $this->_form;
     $ratingdata = $this->ratingallocate->get_rating_data_for_user($USER->id);
     $choicecounter = $this->get_strategysetting(strategy::COUNTOPTIONS);
     $choices = array();
     foreach ($ratingdata as $data) {
         $choices[$data->choiceid] = $data->title;
     }
     for ($i = 1; $i <= $choicecounter; $i++) {
         $mform->addElement('select', 'choice[' . $i . ']', get_string(strategy::STRATEGYID . '_no_choice', ratingallocate_MOD_NAME, $i), $choices);
     }
     foreach ($ratingdata as $data) {
         // If there is a valid value in the databse, choose the according rating
         // from the dropdown.
         // Else use a default value.
         if (is_numeric($data->rating) && $data->rating >= 0 && $mform->elementExists('choice[' . ($choicecounter - ($data->rating - 1)) . ']')) {
             $mform->getElement('choice[' . ($choicecounter - ($data->rating - 1)) . ']')->setSelected($data->choiceid);
         }
     }
 }
 public function definition()
 {
     global $USER;
     parent::definition();
     $mform = $this->_form;
     $ratingdata = $this->ratingallocate->get_rating_data_for_user($USER->id);
     $choicecounter = $this->get_strategysetting(strategy::COUNTOPTIONS);
     $choices = array();
     foreach ($ratingdata as $data) {
         $choices[$data->choiceid] = $data->title;
     }
     for ($i = 1; $i <= $choicecounter; $i++) {
         $mform->addElement('select', 'choice[' . $i . ']', get_string(strategy::STRATEGYID . '_no_choice', ratingallocate_MOD_NAME, $i), $choices);
     }
     foreach ($ratingdata as $data) {
         // If there is a valid value in the databse, choose the according rating
         // from the dropdown.
         // Else use a default value.
         if (is_numeric($data->rating) && $data->rating >= 0 && $mform->elementExists('choice[' . ($choicecounter - ($data->rating - 1)) . ']')) {
             $mform->getElement('choice[' . ($choicecounter - ($data->rating - 1)) . ']')->setSelected($data->choiceid);
         }
     }
     $mform->addElement('header', 'choice_descriptions', get_string(strategy::STRATEGYID . '_header_description', ratingallocate_MOD_NAME));
     foreach ($ratingdata as $data) {
         // Show max. number of allocations.
         // TODO add setting in order to make this optional, as requested in issue #14.
         $mform->addElement('html', '<div class="mod-ratingallocate-choice-maxno">' . '<span class="mod-ratingallocate-choice-maxno-desc">' . get_string('choice_maxsize_display', ratingallocate_MOD_NAME) . ':</span> <span class="mod-ratingallocate-choice-maxno-value">' . $data->maxsize . '</span></div>');
         $mform->addElement('static', 'description_' . $data->choiceid, $data->title, $data->explanation);
     }
 }