Ejemplo n.º 1
0
    /**
     * Builds a result form containing inputs for all students with a given course_code
     */
    protected function build_result_add_form()
    {
        $renderer =& $this->defaultRenderer();
        $renderer->setFormTemplate('<form{attributes}>
		      <table class="data_table">
              {content}
		      </table>
		   </form>');
        $tblusers = GradebookUtils::get_users_in_course($this->evaluation_object->get_course_code());
        $nr_users = 0;
        //extra field for check on maxvalue
        $this->addElement('hidden', 'maxvalue', $this->evaluation_object->get_max());
        $this->addElement('hidden', 'minvalue', 0);
        $this->addElement('header', get_lang('AddResult'));
        if (api_is_western_name_order()) {
            $renderer->setHeaderTemplate('<tr>
                   <th>' . get_lang('OfficialCode') . '</th>
                  <th>' . get_lang('UserName') . '</th>
                  <th>' . get_lang('FirstName') . '</th>
                  <th>' . get_lang('LastName') . '</th>
                  <th>' . get_lang('Qualify') . '</th>
               </tr>');
        } else {
            $renderer->setHeaderTemplate('<tr>
                   <th>' . get_lang('OfficialCode') . '</th>
                  <th>' . get_lang('UserName') . '</th>
                  <th>' . get_lang('LastName') . '</th>
                  <th>' . get_lang('FirstName') . '</th>
                  <th>' . get_lang('Qualify') . '</th>
               </tr>');
        }
        $firstUser = true;
        foreach ($tblusers as $user) {
            $element_name = 'score[' . $user[0] . ']';
            $scoreColumnProperties = array('maxlength' => 5);
            if ($firstUser) {
                $scoreColumnProperties['autofocus'] = '';
                $firstUser = false;
            }
            //user_id, user.username, lastname, firstname
            $this->addText($element_name, $this->build_stud_label($user[0], $user[1], $user[2], $user[3]), false, $scoreColumnProperties);
            $this->addRule($element_name, get_lang('OnlyNumbers'), 'numeric');
            $this->addRule(array($element_name, 'maxvalue'), get_lang('OverMax'), 'compare', '<=');
            $this->addRule(array($element_name, 'minvalue'), get_lang('UnderMin'), 'compare', '>=');
            if (api_is_western_name_order()) {
                $user_info = '<td align="left" >' . $user[3] . '</td>';
                $user_info .= '<td align="left" >' . $user[2] . '</td>';
            } else {
                $user_info = '<td align="left" >' . $user[2] . '</td>';
                $user_info .= '<td align="left" >' . $user[3] . '</td>';
            }
            $nr_users++;
            $template = '<tr>
		      <td align="left" >' . $user[4] . '</td>
		      <td align="left" >' . $user[1] . '</td>
		      ' . $user_info . '
		       <td align="left">{element} / ' . $this->evaluation_object->get_max() . '
		         <!-- BEGIN error --><br /><span style="color: #ff0000;font-size:10px">{error}</span><!-- END error -->
		      </td>
            </tr>';
            $renderer->setElementTemplate($template, $element_name);
        }
        $this->addElement('hidden', 'nr_users', $nr_users);
        $this->addElement('hidden', 'evaluation_id', $this->result_object->get_evaluation_id());
        $this->addButtonSave(get_lang('AddResult'), 'submit');
        $template_submit = '<tr>
                <td colspan="4" ></td>
                <td >
                {element}
                    <!-- BEGIN error --><br /><span style="color: #ff0000;font-size:10px">{error}</span><!-- END error -->
                </td>
            </tr>';
        $renderer->setElementTemplate($template_submit, 'submit');
    }
Ejemplo n.º 2
0
 /**
  * @param array $evals
  * @param array $links
  * @return array
  */
 public static function get_all_users($evals = array(), $links = array())
 {
     $coursecodes = array();
     $users = array();
     // By default add all user in course
     $coursecodes[api_get_course_id()] = '1';
     $users = GradebookUtils::get_users_in_course(api_get_course_id());
     foreach ($evals as $eval) {
         $coursecode = $eval->get_course_code();
         // evaluation in course
         if (isset($coursecode) && !empty($coursecode)) {
             if (!array_key_exists($coursecode, $coursecodes)) {
                 $coursecodes[$coursecode] = '1';
                 $users = array_merge($users, GradebookUtils::get_users_in_course($coursecode));
             }
         } else {
             // course independent evaluation
             $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
             $tbl_res = Database::get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
             $sql = 'SELECT user.user_id, lastname, firstname, user.official_code
                     FROM ' . $tbl_res . ' as res, ' . $tbl_user . ' as user
                     WHERE
                         res.evaluation_id = ' . intval($eval->get_id()) . ' AND
                         res.user_id = user.user_id
                     ';
             $sql .= ' ORDER BY lastname, firstname';
             if (api_is_western_name_order()) {
                 $sql .= ' ORDER BY firstname, lastname';
             }
             $result = Database::query($sql);
             $users = array_merge($users, GradebookUtils::get_user_array_from_sql_result($result));
         }
     }
     foreach ($links as $link) {
         // links are always in a course
         $coursecode = $link->get_course_code();
         if (!array_key_exists($coursecode, $coursecodes)) {
             $coursecodes[$coursecode] = '1';
             $users = array_merge($users, GradebookUtils::get_users_in_course($coursecode));
         }
     }
     return $users;
 }