Ejemplo n.º 1
0
 /**
  * Return the HTML to edit a specific instructor.
  * This could be extended to allow for application specific editing, for example
  * a Moodle interface to its formslib.
  *
  * @param int $classid The class ID.
  * @param string $sort Field to sort on.
  * @param string $dir Direction of sort.
  * @param int $page The page to start at.
  * @param int $perpage Number of records per page.
  * @param string $namesearch Search string for item name.
  * @param string $alpha Start initial of item name filter.
  * @return string The form HTML, without the form.
  */
 public function edit_form_html($classid, $sort = 'name', $dir = 'ASC', $page = 0, $perpage = 30, $namesearch = '', $alpha = '')
 {
     global $CFG, $OUTPUT, $SESSION, $PAGE;
     $action = optional_param('action', '', PARAM_ALPHA);
     $this->classid = $classid;
     $output = '';
     ob_start();
     if (empty($this->id)) {
         $columns = array('assign' => array('header' => get_string('assign', self::LANG_FILE), 'display_function' => 'htmltab_display_function', 'sortable' => false), 'idnumber' => array('header' => get_string('class_idnumber', self::LANG_FILE), 'display_function' => 'htmltab_display_function'), 'name' => array('header' => get_string('tag_name', self::LANG_FILE), 'display_function' => 'htmltab_display_function'), 'assigntime' => array('header' => get_string('assigntime', self::LANG_FILE), 'display_function' => 'htmltab_display_function', 'sortable' => false), 'completetime' => array('header' => get_string('completion_time', self::LANG_FILE), 'display_function' => 'htmltab_display_function', 'sortable' => false));
     } else {
         $columns = array('idnumber' => array('header' => get_string('class_idnumber', self::LANG_FILE), 'display_function' => 'htmltab_display_function'), 'name' => array('header' => get_string('tag_name', self::LANG_FILE), 'display_function' => 'htmltab_display_function'), 'assigntime' => array('header' => get_string('assigntime', self::LANG_FILE), 'display_function' => 'htmltab_display_function', 'sortable' => false), 'completetime' => array('header' => get_string('completion_time', self::LANG_FILE), 'display_function' => 'htmltab_display_function', 'sortable' => false));
     }
     if ($dir !== 'DESC') {
         $dir = 'ASC';
     }
     if (isset($columns[$sort])) {
         $columns[$sort]['sortable'] = $dir;
     } else {
         $sort = 'name';
         $columns[$sort]['sortable'] = $dir;
     }
     $newarr = array();
     $users = array();
     if (empty($this->id)) {
         $users = $this->get_users_avail($sort, $dir, $page * $perpage, $perpage, $namesearch, $alpha);
         $usercount = $this->count_users_avail($namesearch, $alpha);
         pmalphabox(new moodle_url('/local/elisprogram/index.php', array('s' => 'ins', 'section' => 'curr', 'action' => 'add', 'id' => $classid, 'sort' => $sort, 'dir' => $dir, 'perpage' => $perpage)), 'alpha', get_string('tag_name', self::LANG_FILE) . ':');
         $pagingbar = new paging_bar($usercount, $page, $perpage, "index.php?s=ins&section=curr&id={$classid}&action=add&" . "sort={$sort}&dir={$dir}&perpage={$perpage}&alpha={$alpha}&" . "search=" . urlencode($namesearch));
         // TBD: .'&'
         echo $OUTPUT->render($pagingbar);
         flush();
     } else {
         //error_log("instructor.class.php::edit_form_html(); userid = {$this->userid}");
         $user = new stdClass();
         $user->name = '?';
         if ($tmpuser = new user($this->userid)) {
             $tmpuser->load();
             $user = $tmpuser->to_object();
             $user->name = $tmpuser->moodle_fullname();
         }
         $users[] = $user;
         $usercount = 0;
         // TBD: 1 ???
     }
     $has_users = is_array($users) && !empty($users) || $users instanceof Iterator && $users->valid() === true ? true : false;
     if (empty($this->id) && $has_users === false) {
         $table = NULL;
     } else {
         $insobj = new instructor();
         //$table->width = "100%";
         foreach ($users as $user) {
             $tabobj = new stdClass();
             $assigntime = $this->assigntime;
             $completetime = $this->completetime;
             $selection = json_decode(retrieve_session_selection($user->id, 'add'));
             if ($selection) {
                 $assigntime = pm_timestamp(0, 0, 0, $selection->enrolment_date->month, $selection->enrolment_date->day, $selection->enrolment_date->year);
                 $completetime = pm_timestamp(0, 0, 0, $selection->completion_date->month, $selection->completion_date->day, $selection->completion_date->year);
             }
             /* **** debug code
                  ob_start();
                  var_dump($user);
                  $tmp = ob_get_contents();
                  ob_end_clean();
                  error_log("instructor.class.php::edit_form_html() user = $tmp");
                **** */
             foreach ($columns as $column => $cdesc) {
                 switch ($column) {
                     case 'assign':
                         $tabobj->{$column} = '<input type="checkbox" id="checkbox' . $user->id . '" onClick="select_item(' . $user->id . ')" name="users[' . $user->id . '][assign]" value="1" ' . ($selection ? 'checked="checked"' : '') . '/>' . '<input type="hidden" name="users[' . $user->id . '][idnumber]" ' . 'value="' . $user->idnumber . '" />';
                         break;
                     case 'name':
                     case 'idnumber':
                     case 'description':
                         $tabobj->{$column} = $user->{$column};
                         break;
                     case 'assigntime':
                         $tabobj->{$column} = cm_print_date_selector('users[' . $user->id . '][startday]', 'users[' . $user->id . '][startmonth]', 'users[' . $user->id . '][startyear]', $assigntime, true);
                         break;
                     case 'completetime':
                         $tabobj->{$column} = cm_print_date_selector('users[' . $user->id . '][endday]', 'users[' . $user->id . '][endmonth]', 'users[' . $user->id . '][endyear]', $completetime, true);
                         break;
                     default:
                         $tabobj->{$column} = '';
                         break;
                 }
             }
             $newarr[] = $tabobj;
             //$table->data[] = $newarr;
         }
         $table = new display_table($newarr, $columns, get_pm_url(), 'sort', 'dir', array('id' => 'selectiontbl'));
     }
     unset($users);
     print_checkbox_selection($classid, 'ins', 'add');
     if (empty($this->id)) {
         pmsearchbox(null, 'search', 'get', get_string('show_all_users', self::LANG_FILE));
         echo '<form method="post" action="index.php?s=ins&amp;section=curr&amp;id=' . $classid . '" >' . "\n";
         echo '<input type="hidden" name="action" value="savenew" />' . "\n";
     } else {
         echo '<form method="post" action="index.php?s=ins&amp;section=curr&amp;id=' . $classid . '" >' . "\n";
         echo '<input type="hidden" name="action" value="update" />' . "\n";
         echo '<input type="hidden" name="association_id" value="' . $this->id . '" />' . "\n";
         echo '<input type="hidden" name="id" value="' . $this->classid . '" />' . "\n";
         echo '<input type="hidden" name="userid" value="' . $this->userid . '" />' . "\n";
     }
     if (!empty($table) && !empty($newarr)) {
         if ($action == 'add') {
             $PAGE->requires->js('/local/elisprogram/js/classform.js');
             echo '<input type="button" onclick="checkbox_select(true,\'[assign]\')" value="' . get_string('selectall') . '" /> ';
             echo '<input type="button" onclick="checkbox_select(false,\'[assign]\')" value="' . get_string('deselectall') . '" /> ';
         }
         echo $table->get_html();
         $pagingbar = new paging_bar($usercount, $page, $perpage, "index.php?s=ins&amp;section=curr&amp;id={$classid}&amp;action=add&amp;" . "sort={$sort}&amp;dir={$dir}&amp;perpage={$perpage}&amp;alpha={$alpha}&amp;" . "search=" . urlencode($namesearch));
         // TBD: .'&amp;'
         echo $OUTPUT->render($pagingbar);
     }
     if (empty($this->id)) {
         if ($has_users === false) {
             pmshowmatches($alpha, $namesearch);
         }
         echo '<br /><input type="submit" value="' . get_string('assign_selected', self::LANG_FILE) . '">' . "\n";
     } else {
         echo '<br /><input type="submit" value="' . get_string('update_assignment', self::LANG_FILE) . '">' . "\n";
     }
     echo '</form>' . "\n";
     $output = ob_get_contents();
     ob_end_clean();
     return $output;
 }
Ejemplo n.º 2
0
 /**
  * Return the HTML to edit a specific student.
  * This could be extended to allow for application specific editing,
  * for example a Moodle interface to its formslib.
  *
  * @param int $classid The class ID.
  * @param string $type The entity type.
  * @param string $sort Field to sort on.
  * @param string $dir Direction of sort.
  * @param int $page The page to start at.
  * @param int $perpage Number of records per page.
  * @param string $namesearch Search string for item name.
  * @param string $alpha Start initial of item name filter.
  * @return string The form HTML, without the form.
  */
 public function edit_form_html($classid, $type = '', $sort = 'idnumber', $dir = 'ASC', $page = 0, $perpage = 30, $namesearch = '', $alpha = '')
 {
     global $CFG, $OUTPUT, $PAGE, $SESSION;
     $output = '';
     ob_start();
     $newarr = array();
     if (empty($this->id)) {
         $columns = array('enrol' => array('header' => get_string('enrol', self::LANG_FILE), 'display_function' => 'htmltab_display_function', 'sortable' => false), 'idnumber' => array('header' => get_string('student_idnumber', self::LANG_FILE), 'display_function' => 'htmltab_display_function'), 'name' => array('header' => get_string('student_name_1', self::LANG_FILE), 'display_function' => 'htmltab_display_function'), 'enrolmenttime' => array('header' => get_string('enrolment_time', self::LANG_FILE), 'display_function' => 'htmltab_display_function', 'sortable' => false), 'completetime' => array('header' => get_string('completion_time', self::LANG_FILE), 'display_function' => 'htmltab_display_function', 'sortable' => false), 'completestatusid' => array('header' => get_string('student_status', self::LANG_FILE), 'display_function' => 'htmltab_display_function', 'sortable' => false), 'grade' => array('header' => get_string('student_grade', self::LANG_FILE), 'display_function' => 'htmltab_display_function', 'sortable' => false), 'credits' => array('header' => get_string('student_credits', self::LANG_FILE), 'display_function' => 'htmltab_display_function', 'sortable' => false), 'locked' => array('header' => get_string('student_locked', self::LANG_FILE), 'display_function' => 'htmltab_display_function', 'sortable' => false));
     } else {
         $columns = array('idnumber' => array('header' => get_string('student_idnumber', self::LANG_FILE), 'display_function' => 'htmltab_display_function', 'sortable' => false), 'name' => array('header' => get_string('student_name_1', self::LANG_FILE), 'display_function' => 'htmltab_display_function', 'sortable' => false), 'enrolmenttime' => array('header' => get_string('enrolment_time', self::LANG_FILE), 'display_function' => 'htmltab_display_function', 'sortable' => false), 'completetime' => array('header' => get_string('completion_time', self::LANG_FILE), 'display_function' => 'htmltab_display_function', 'sortable' => false), 'completestatusid' => array('header' => get_string('student_status', self::LANG_FILE), 'display_function' => 'htmltab_display_function', 'sortable' => false), 'grade' => array('header' => get_string('student_grade', self::LANG_FILE), 'display_function' => 'htmltab_display_function', 'sortable' => false), 'credits' => array('header' => get_string('student_credits', self::LANG_FILE), 'display_function' => 'htmltab_display_function', 'sortable' => false), 'locked' => array('header' => get_string('student_locked', self::LANG_FILE), 'display_function' => 'htmltab_display_function', 'sortable' => false));
     }
     // ELIS-6468
     if ($dir !== 'DESC') {
         $dir = 'ASC';
     }
     if (isset($columns[$sort])) {
         $columns[$sort]['sortable'] = $dir;
     } else {
         $sort = 'name';
         $columns[$sort]['sortable'] = $dir;
     }
     $users = array();
     if (empty($this->id)) {
         $users = $this->get_users_avail($sort, $dir, $page * $perpage, $perpage, $namesearch, $alpha);
         $usercount = $this->count_users_avail($namesearch, $alpha);
         // TBD
         pmalphabox(new moodle_url('/local/elisprogram/index.php', array('s' => 'stu', 'section' => 'curr', 'action' => 'add', 'id' => $classid, 'search' => $namesearch, 'sort' => $sort, 'dir' => $dir, 'perpage' => $perpage)), 'alpha', get_string('tag_name', self::LANG_FILE) . ':');
         $pagingbar = new paging_bar($usercount, $page, $perpage, "index.php?s=stu&amp;section=curr&amp;id={$classid}&amp;class={$classid}&amp;&amp;action=add&amp;" . "sort={$sort}&amp;dir={$dir}&amp;perpage={$perpage}&amp;alpha={$alpha}&amp;stype={$type}" . "&amp;search=" . urlencode($namesearch));
         // TBD: .'&amp;'
         echo $OUTPUT->render($pagingbar);
         flush();
         pmsearchbox(null, 'search', 'get', get_string('show_all_users', self::LANG_FILE));
         // TBD: moved from below
     } else {
         $newuser = new stdClass();
         $newuser->name = '?';
         if ($user = new user($this->userid)) {
             $user->load();
             $newuser = $user->to_object();
             $newuser->name = $user->moodle_fullname();
         }
         $users[] = $newuser;
         $usercount = 0;
     }
     $has_users = is_array($users) && !empty($users) || $users instanceof Iterator && $users->valid() === true ? true : false;
     if (empty($this->id) && $has_users === false) {
         pmshowmatches($alpha, $namesearch);
         $table = NULL;
     } else {
         $stuobj = new student();
         foreach ($users as $user) {
             $locked = $this->locked;
             $credits = $this->credits;
             $grade = $this->grade;
             $status = $this->completestatusid;
             $enrolmenttime = $this->enrolmenttime;
             $completetime = $this->completetime;
             $selection = json_decode(retrieve_session_selection($user->id, 'add'));
             if ($selection) {
                 $locked = $selection->locked;
                 $credits = $selection->credits;
                 $grade = $selection->grade;
                 $status = $selection->status;
                 $enrolmenttime = pm_timestamp(0, 0, 0, $selection->enrolment_date->month, $selection->enrolment_date->day, $selection->enrolment_date->year);
                 $completetime = pm_timestamp(0, 0, 0, $selection->completion_date->month, $selection->completion_date->day, $selection->completion_date->year);
             }
             $tabobj = new stdClass();
             foreach ($columns as $column => $cdesc) {
                 switch ($column) {
                     case 'enrol':
                         $tabobj->{$column} = '<input type="checkbox" id="checkbox' . $user->id . '"
                         name="users[' . $user->id . '][enrol]" value="1" onClick="select_item(' . $user->id . ')" ' . ($selection ? 'checked="checked"' : '') . '/>' . '<input type="hidden" name="users[' . $user->id . '][idnumber]" ' . 'value="' . $user->idnumber . '" />';
                         break;
                     case 'name':
                     case 'idnumber':
                     case 'description':
                         $tabobj->{$column} = isset($user->{$column}) ? $user->{$column} : '';
                         break;
                     case 'enrolmenttime':
                         $tabobj->{$column} = cm_print_date_selector('users[' . $user->id . '][startday]', 'users[' . $user->id . '][startmonth]', 'users[' . $user->id . '][startyear]', $enrolmenttime, true);
                         break;
                     case 'completetime':
                         $tabobj->{$column} = cm_print_date_selector('users[' . $user->id . '][endday]', 'users[' . $user->id . '][endmonth]', 'users[' . $user->id . '][endyear]', $completetime, true);
                         break;
                     case 'completestatusid':
                         $choices = array();
                         foreach (student::$completestatusid_values as $key => $csidv) {
                             $choices[$key] = get_string($csidv, self::LANG_FILE);
                             // TBD
                         }
                         $tabobj->{$column} = cm_choose_from_menu($choices, 'users[' . $user->id . '][completestatusid]', $status, '', '', '', true);
                         break;
                     case 'grade':
                         $tabobj->{$column} = '<input type="text" id="grade' . $user->id . '" name="users[' . $user->id . '][grade]" ' . 'value="' . $grade . '" size="5" />';
                         break;
                     case 'credits':
                         $tabobj->{$column} = '<input type="text" id="credits' . $user->id . '" name="users[' . $user->id . '][credits]" ' . 'value="' . $credits . '" size="5" />';
                         break;
                     case 'locked':
                         $tabobj->{$column} = '<input type="checkbox" id="locked' . $user->id . '" name="users[' . $user->id . '][locked]" ' . 'value="1" ' . ($locked ? 'checked="checked"' : '') . '/>';
                         break;
                     default:
                         $tabobj->{$column} = '';
                         break;
                 }
             }
             $newarr[] = $tabobj;
             //$table->data[] = $newarr;
         }
         // TBD: student_table() ???
         $table = new display_table($newarr, $columns, $this->get_base_url(), 'sort', 'dir', array('id' => 'selectiontbl'));
     }
     unset($users);
     print_checkbox_selection($classid, 'stu', 'add');
     if (empty($this->id)) {
         echo '<form method="post" action="index.php?s=stu&amp;section=curr&amp;id=' . $classid . '" >' . "\n";
         echo '<input type="hidden" name="action" value="savenew" />' . "\n";
         echo '<input type="hidden" name="sesskey" value="' . sesskey() . '"/>';
     } else {
         echo '<form method="post" action="index.php?s=stu&amp;section=curr&amp;id=' . $classid . '" >' . "\n";
         echo '<input type="hidden" name="action" value="update" />' . "\n";
         echo '<input type="hidden" name="association_id" value="' . $this->id . '" />' . "\n";
         echo '<input type="hidden" name="id" value="' . $this->classid . '" />' . "\n";
         echo '<input type="hidden" name="userid" value="' . $this->userid . '" />' . "\n";
         echo '<input type="hidden" name="sesskey" value="' . sesskey() . '"/>';
     }
     if (!empty($newarr)) {
         // TBD: $newarr or $table
         if (empty($this->id)) {
             $PAGE->requires->js('/local/elisprogram/js/classform.js');
             echo '<input type="button" onclick="checkbox_select(true,\'[enrol]\')" value="' . get_string('selectall') . '" /> ';
             echo '<input type="button" onclick="checkbox_select(false,\'[enrol]\')" value="' . get_string('deselectall') . '" /> ';
         }
         echo $table->get_html();
     }
     if (isset($this->id)) {
         $columns = array('idnumber' => array('header' => get_string('grade_element', self::LANG_FILE), 'display_function' => 'htmltab_display_function'), 'grade' => array('header' => get_string('grade', self::LANG_FILE), 'display_function' => 'htmltab_display_function'), 'locked' => array('header' => get_string('student_locked', self::LANG_FILE), 'display_function' => 'htmltab_display_function'), 'timegraded' => array('header' => get_string('date_graded', self::LANG_FILE), 'display_function' => 'htmltab_display_function'));
         if ($dir !== 'DESC') {
             $dir = 'ASC';
         }
         if (isset($columns[$sort])) {
             $columns[$sort]['sortable'] = $dir;
         } else {
             $sort = 'idnumber';
             $columns[$sort]['sortable'] = $dir;
         }
         $elements = self::retrieve_grade_elements($this->pmclass->course->get_course_id(), $this->classid, $this->userid, $sort, $dir);
         if (!empty($elements) && $elements->valid() === true) {
             //$table->width = "100%"; // TBD
             $newarr = array();
             foreach ($elements as $element) {
                 $tabobj = new stdClass();
                 foreach ($element as $column => $cdesc) {
                     switch ($column) {
                         case 'idnumber':
                             if (isset($element->studentgradeid)) {
                                 $name = 'element[' . $element->studentgradeid . ']';
                                 $value = $element->id;
                             } else {
                                 $name = 'newelement[' . $element->id . ']';
                                 $value = $element->id;
                             }
                             $tabobj->{$column} = '<input type="hidden" name="' . $name . '" ' . 'value="' . $value . '" />' . s($element->idnumber);
                             break;
                         case 'timegraded':
                             if (isset($element->studentgradeid)) {
                                 $name = 'timegraded[' . $element->studentgradeid . ']';
                                 $value = $element->timegraded;
                             } else {
                                 $name = 'newtimegraded[' . $element->id . ']';
                                 $value = 0;
                             }
                             $tabobj->{$column} = cm_print_date_selector($name . '[startday]', $name . '[startmonth]', $name . '[startyear]', $value, true);
                             break;
                         case 'grade':
                             if (isset($element->studentgradeid)) {
                                 $name = 'grade[' . $element->studentgradeid . ']';
                                 $value = $element->grade;
                             } else {
                                 $name = 'newgrade[' . $element->id . ']';
                                 $value = 0;
                             }
                             $tabobj->{$column} = '<input type="text" name="' . $name . '" ' . 'value="' . $value . '" size="5" />';
                             break;
                         case 'locked':
                             if (isset($element->studentgradeid)) {
                                 $name = 'locked[' . $element->studentgradeid . ']';
                                 $value = $element->locked;
                             } else {
                                 $name = 'newlocked[' . $element->id . ']';
                                 $value = 0;
                             }
                             $tabobj->{$column} = '<input type="checkbox" name="' . $name . '" ' . 'value="1" ' . ($value ? 'checked="checked"' : '') . '/>';
                             break;
                         default:
                             $tabobj->{$column} = '';
                             break;
                     }
                 }
                 $newarr[] = $tabobj;
                 //$table->data[] = $newarr;
             }
             // TBD: student_table() ???
             $table = new display_table($newarr, $columns, $this->get_base_url());
             if (!empty($newarr)) {
                 // TBD: $table or $newarr?
                 echo '<br />';
                 echo $table->get_html();
                 print_string('grade_update_warning', self::LANG_FILE);
             }
         }
         unset($elements);
     }
     if (empty($this->id)) {
         echo '<br /><input type="submit" value="' . get_string('enrol_selected', self::LANG_FILE) . '">' . "\n";
     } else {
         echo '<br /><input type="submit" value="' . get_string('update_enrolment', self::LANG_FILE) . '">' . "\n";
     }
     echo '</form>' . "\n";
     $output = ob_get_contents();
     ob_end_clean();
     return $output;
 }
Ejemplo n.º 3
0
 /**
  * Tests the print_checkbox_selection() function.
  * Tests printing out saved checkboxes for use by javascript.
  */
 public function test_print_checkbox_selection()
 {
     global $SESSION;
     $page = 'test';
     $classid = 1;
     $target = 'test';
     $pagename = $page . $classid . $target;
     $id1 = new stdClass();
     $id1->id = 2;
     $id2 = new stdClass();
     $id2->id = 3;
     $id3 = new stdClass();
     $id3->id = 4;
     $id4 = new stdClass();
     $id4->id = 5;
     $SESSION->associationpage[$pagename] = array(json_encode($id1), json_encode($id2), json_encode($id3), json_encode($id4));
     ob_start();
     print_checkbox_selection($classid, $page, $target);
     $actual = ob_get_contents();
     ob_end_clean();
     // Generate expected output.
     $baseurl = get_pm_url()->out_omit_querystring() . '?&id=' . $classid . '&s=' . $page . '&target=' . $target;
     $expected = '<input type="hidden" id="baseurl" value="' . $baseurl . '" /> ';
     $ids = '2,3,4,5';
     $expected .= '<input type="hidden" id="selected_checkboxes" value="' . $ids . '" /> ';
     // Assert.
     $this->assertEquals($expected, $actual);
 }