/** * Validate that the enrolment count excludes inactive users when the site is not configured to show inactive users */ public function test_usercountexcludesinactivewhenexcludinginactive() { require_once elispm::lib('lib.php'); // Set up all the data needed for the listing. $this->load_csv_data(); // Disable showing of inactive users. pm_set_config('legacy_show_inactive_users', 0); elis::$config = new elis_config(); // Obtain the listing. $listing = track_assignment_get_listing(1); // Validate the number of rows. $count = 0; foreach ($listing as $entity) { $count++; // Validate the aggregated count in the first row. $this->assertEquals(1, $entity->enrolments); } unset($listing); $this->assertEquals(1, $count); }
/** * Dynamically loads child menu items for a track entity * * @param int $id The entity id * @param int $parent_cluster_id The last cluster passed going down the elisadmin tree, or 0 if none * @param int $parent_curriculum_id The last curriculum passed going down the elisadmin tree, or 0 if none * @param int $num_block_icons Max number of entries to display * @param string $parent_path Path of parent curriculum elements in the tree * @return menuitem array The appropriate child items */ function block_elisadmin_load_menu_children_track($id, $parent_cluster_id, $parent_curriculum_id, $num_block_icons, $parent_path = '') { global $CFG; //page dependencies require_once elispm::file('pmclasspage.class.php'); $result_items = array(); /***************************************** * Track - Class Associations *****************************************/ $class_css_class = block_elisadmin_get_item_css_class('class_instance'); //permissions filter $class_filter = array('contexts' => pmclasspage::get_contexts('local/elisprogram:class_view')); $listing = track_assignment_get_listing($id, 'cls.idnumber', 'ASC', 0, $num_block_icons, '', '', $class_filter); foreach ($listing as $item) { $item->id = $item->classid; $params = array('id' => $item->id, 'action' => 'view'); $result_items[] = block_elisadmin_get_menu_item('pmclass', $item, 'root', $class_css_class, $parent_cluster_id, $parent_curriculum_id, $params, false, $parent_path); } unset($listing); //summary item $num_records = track_assignment_count_records($id, '', '', $class_filter); if ($num_block_icons < $num_records) { $params = array('id' => $id); $result_items[] = block_elisadmin_get_menu_summary_item('trackassignment', $class_css_class, $num_records - $num_block_icons, $params, '', $parent_path); } /***************************************** * Track - Cluster Associations *****************************************/ $cluster_css_class = block_elisadmin_get_item_css_class('cluster_instance'); //permissions filter $cluster_filter = array('contexts' => usersetpage::get_contexts('local/elisprogram:userset_view')); $clusters = clustertrack::get_clusters($id, $parent_cluster_id, 'name', 'ASC', 0, $num_block_icons, $cluster_filter); //$clusters = clustertrack::get_clusters($id, 0, 'priority, name', 'ASC', $num_block_icons, $parent_cluster_id); if (!empty($clusters)) { foreach ($clusters as $cluster) { $cluster->id = $cluster->clusterid; $params = array('id' => $cluster->id, 'action' => 'view'); $result_items[] = block_elisadmin_get_menu_item('cluster', $cluster, 'root', $cluster_css_class, $cluster->id, $parent_curriculum_id, $params, false, $parent_path); } } //summary item $num_records = clustertrack::count_clusters($id, $parent_cluster_id, $cluster_filter); if ($num_block_icons < $num_records) { $params = array('id' => $id); //add extra param if appropriate if (!empty($parent_cluster_id)) { $params['parent_clusterid'] = $parent_cluster_id; } $result_items[] = block_elisadmin_get_menu_summary_item('trackcluster', $cluster_css_class, $num_records - $num_block_icons, $params, 'clustertrackpage.class.php', $parent_path); } return $result_items; }
/** * Clone a track * @param array $options options for cloning. Valid options are: * - 'targetcurriculum': the curriculum id to associate the clones with * (default: same as original track) * - 'classmap': a mapping of class IDs to use from the original track to * the cloned track. If a class from the original track is not mapped, a * new class will be created * - 'moodlecourse': whether or not to clone Moodle courses (if they were * autocreated). Values can be (default: "copyalways"): * - "copyalways": always copy course * - "copyautocreated": only copy autocreated courses * - "autocreatenew": autocreate new courses from course template * - "link": link to existing course * @return array array of array of object IDs created. Key in outer array * is type of object (plural). Key in inner array is original object ID, * value is new object ID. Outer array also has an entry called 'errors', * which is an array of any errors encountered when duplicating the * object. */ function duplicate(array $options = array()) { $objs = array('errors' => array()); if (isset($options['targetcluster'])) { $userset = $options['targetcluster']; if (!is_object($userset) || !is_a($userset, 'userset')) { $options['targetcluster'] = $userset = new userset($userset); } } // Due to lazy loading, we need to pre-load this object $this->load(); // clone main track object $clone = new track($this); unset($clone->id); if (isset($options['targetcurriculum'])) { $clone->curid = $options['targetcurriculum']; } $idnumber = $clone->idnumber; $name = $clone->name; if (isset($userset)) { $to_append = ' - ' . $userset->name; // if cluster specified, append cluster's name to course $idnumber = append_once($idnumber, $to_append, array('maxlength' => 95)); $name = append_once($name, $to_append, array('maxlength' => 250)); } //get a unique idnumber $clone->idnumber = generate_unique_identifier(track::TABLE, 'idnumber', $idnumber, array('idnumber' => $idnumber)); if ($clone->idnumber != $idnumber) { //get the suffix appended and add it to the name $parts = explode('.', $clone->idnumber); $suffix = end($parts); $clone->name = $name . '.' . $suffix; } else { $clone->name = $name; } $clone->autocreate = false; // avoid warnings $clone->save(); $objs['tracks'] = array($this->id => $clone->id); // associate with target cluster (if any) if (isset($userset)) { clustertrack::associate($userset->id, $clone->id); } // copy classes $clstrks = track_assignment_get_listing($this->id); if ($clstrks->valid() === true) { $objs['classes'] = array(); if (!isset($options['classmap'])) { $options['classmap'] = array(); } foreach ($clstrks as $clstrkdata) { $newclstrk = new trackassignment($clstrkdata); $newclstrk->trackid = $clone->id; unset($newclstrk->id); if (isset($options['classmap'][$clstrkdata->clsid])) { // use existing duplicate class $class = new pmclass($options['classmap'][$clstrkdata->clsid]); } else { // no existing duplicate -> duplicate class $class = new pmclass($clstrkdata->clsid); $rv = $class->duplicate($options); if (isset($rv['errors']) && !empty($rv['errors'])) { $objs['errors'] = array_merge($objs['errors'], $rv['errors']); } if (isset($rv['classes'])) { $objs['classes'] = $objs['classes'] + $rv['classes']; } } $newclstrk->classid = $class->id; $newclstrk->courseid = $class->courseid; $newclstrk->save(); } } unset($clstrks); return $objs; }
/** * Clone a track * @param array $options options for cloning. Valid options are: * - 'targetcurriculum': the curriculum id to associate the clones with * (default: same as original track) * - 'classmap': a mapping of class IDs to use from the original track to * the cloned track. If a class from the original track is not mapped, a * new class will be created * - 'moodlecourse': whether or not to clone Moodle courses (if they were * autocreated). Values can be (default: "copyalways"): * - "copyalways": always copy course * - "copyautocreated": only copy autocreated courses * - "autocreatenew": autocreate new courses from course template * - "link": link to existing course * @return array array of array of object IDs created. Key in outer array * is type of object (plural). Key in inner array is original object ID, * value is new object ID. Outer array also has an entry called 'errors', * which is an array of any errors encountered when duplicating the * object. */ function duplicate($options = array()) { global $CURMAN; $objs = array('errors' => array()); if (isset($options['targetcluster'])) { $cluster = $options['targetcluster']; if (!is_object($cluster) || !is_a($cluster, 'cluster')) { $options['targetcluster'] = $cluster = new cluster($cluster); } } // clone main track object $clone = new track($this); unset($clone->id); if (isset($options['targetcurriculum'])) { $clone->curid = $options['targetcurriculum']; } if (isset($cluster)) { // if cluster specified, append cluster's name to track $clone->idnumber = $clone->idnumber . ' - ' . $cluster->name; $clone->name = $clone->name . ' - ' . $cluster->name; } $clone = new track(addslashes_recursive($clone)); $clone->autocreate = false; // avoid warnings if (!$clone->add()) { $objs['errors'][] = get_string('failclustcpytrk', 'block_curr_admin', $this); return $objs; } $objs['tracks'] = array($this->id => $clone->id); // associate with target cluster (if any) if (isset($cluster)) { clustertrack::associate($cluster->id, $clone->id); } // copy classes $clstrks = track_assignment_get_listing($this->id); if (!empty($clstrks)) { $objs['classes'] = array(); if (!isset($options['classmap'])) { $options['classmap'] = array(); } foreach ($clstrks as $clstrkdata) { $newclstrk = new trackassignmentclass($clstrkdata); $newclstrk->trackid = $clone->id; unset($newclstrk->id); if (isset($options['classmap'][$clstrkdata->clsid])) { // use existing duplicate class $class = new cmclass($options['classmap'][$clstrkdata->clsid]); } else { // no existing duplicate -> duplicate class $class = new cmclass($clstrkdata->clsid); $rv = $class->duplicate($options); if (isset($rv['errors']) && !empty($rv['errors'])) { $objs['errors'] = array_merge($objs['errors'], $rv['errors']); } if (isset($rv['classes'])) { $objs['classes'] = $objs['classes'] + $rv['classes']; } } $newclstrk->classid = $class->id; $newclstrk->courseid = $class->courseid; $newclstrk->add(); } } return $objs; }
function get_body() { global $CFG, $CURMAN; $action = cm_get_param('action', ''); $confirm = cm_get_param('confirm', ''); //md5 confirmation hash $confirmuser = cm_get_param('confirmuser', 0); $trackid = cm_get_param('trackid', 0); $id = cm_get_param('id', 0); $sort = cm_get_param('sort', 'idnumber'); $dir = cm_get_param('dir', 'ASC'); $page = cm_get_param('page', 0); $perpage = cm_get_param('perpage', 30); // how many per page $namesearch = trim(cm_get_param('search', '')); $alpha = cm_get_param('alpha', ''); if (!($track = new track($trackid))) { return ' (' . $trackid . ')'; } switch ($action) { case 'add': return $this->get_add_form($trackid); break; case 'confirm': $tk = new trackassignmentclass($id); if (md5($tk->id) != $confirm) { echo cm_error('Invalid confirmation code!'); } else { if (!$tk->delete()) { echo cm_error('Course "name: ' . $tk->track->name . '" not deleted.'); } } break; case 'delete': return $this->get_delete_form($id); break; case 'edit': return $this->get_edit_form($id); break; case 'update': $id = cm_get_param('id', 0); $autoenrol = cm_get_param('autoenrol', 0); $trkassign = new trackassignmentclass($id); $trkassign->autoenrol = $autoenrol; $trkassign->data_update_record(); break; case 'savenew': $classes = cm_get_param('classes', ''); $classes = is_array($classes) ? $classes : array(); $trackid = cm_get_param('trackid', 0, PARAM_INT); if (!empty($classes) and !empty($trackid)) { $param = array('trackid' => $trackid); $trackobj = new track($trackid); foreach ($classes as $classid) { $classobj = new cmclass($classid); $param['classid'] = $classid; $param['courseid'] = $classobj->courseid; $param['autoenrol'] = 0; $param['required'] = 0; // Pull up the curricula assignment record(s) $curcourse = curriculumcourse_get_list_by_curr($trackobj->curid); // Traverse though curricula's courses until the the course the - // selected classs is assigned to comes up foreach ($curcourse as $recid => $curcourec) { // Only interested in the course that the class is assigned to if ($curcourec->courseid == $classobj->courseid) { if ($curcourec->required) { $param['required'] = 1; // Only one class assigned to course to enable auto enrol if (1 == cmclass::count_course_assignments($curcourec->courseid)) { $param['autoenrol'] = 1; } } } } // Assign class to track now $trkassignobj = new trackassignmentclass($param); $trkassignobj->assign_class_to_track(); } } break; } $columns = array('clsname' => get_string('class_id_number', 'block_curr_admin'), 'autoenrol' => get_string('auto_enrol', 'block_curr_admin')); foreach ($columns as $column => $cdesc) { if ($sort != $column) { $columnicon = ""; $columndir = "ASC"; } else { $columndir = $dir == "ASC" ? "DESC" : "ASC"; $columnicon = $dir == "ASC" ? "down" : "up"; $columnicon = " <img src=\"{$CFG->pixpath}/t/{$columnicon}.gif\" alt=\"\" />"; } ${$column} = "<a href=\"index.php?s=trkcls&section=curr&sort={$column}&" . "dir={$columndir}&search=" . urlencode(stripslashes($namesearch)) . "&alpha={$alpha}&trackid={$trackid}\">" . $cdesc . "</a>{$columnicon}"; $table->head[] = ${$column}; $table->align[] = 'left'; $table->wrap[] = false; } $table->head[] = ''; $table->align[] = 'center'; $table->wrap[] = true; $trks = track_assignment_get_listing($trackid, $sort, $dir, $page * $perpage, $perpage, $namesearch, $alpha); $numtrk = track_assignment_count_records($trackid, $namesearch, $alpha); $alphabet = explode(',', get_string('alphabet')); $strall = get_string('all'); /// Nav bar information: $bc = '<div style="float:right;">' . $numtrk . ' track(s) found.</div>' . '<span class="breadcrumb">' . get_string('trackasso_manage_crumb', 'block_curr_admin', $track->name) . '</span>'; echo cm_print_heading_block($bc, '', true); echo '<br />' . "\n"; /// Bar of first initials echo "<p style=\"text-align:center\">"; echo 'Name' . " : "; if ($alpha) { echo " <a href=\"index.php?s=trkcls&section=curr&sort=name&dir=ASC&" . "perpage={$perpage}&trackid={$trackid}\">{$strall}</a> "; } else { echo " <b>{$strall}</b> "; } foreach ($alphabet as $letter) { if ($letter == $alpha) { echo " <b>{$letter}</b> "; } else { echo " <a href=\"index.php?s=trkcls&section=curr&sort=idnumber&dir=ASC&" . "perpage={$perpage}&trackid={$trackid}&alpha={$letter}\">{$letter}</a> "; } } echo "</p>"; print_paging_bar($numtrk, $page, $perpage, "index.php?s=trkm&section=curr&sort={$sort}&dir={$dir}&perpage={$perpage}&" . "alpha={$alpha}&trackid={$trackid}&search=" . urlencode(stripslashes($namesearch)) . "&"); if (!$trks) { $match = array(); if ($namesearch !== '') { $match[] = s($namesearch); } if ($alpha) { $match[] = 'idnumber' . ": {$alpha}" . "___"; } $matchstring = implode(", ", $match); echo get_string('no_matching_track_assign', 'block_curr_admin') . $matchstring; $table = NULL; } else { $table->width = "95%"; foreach ($trks as $trk) { $deletebutton = '<a href="index.php?s=trkcls&section=curr&action=delete&' . 'id=' . $trk->id . '">' . '<img src="pix/delete.gif" alt="Delete" title="Delete" /></a>'; $editbutton = '<a href="index.php?s=trkcls&section=curr&action=edit&id=' . $trk->id . '">' . '<img src="pix/edit.gif" alt="Edit" title="Edit" /></a>'; /*$tagbutton = '<a href="index.php?s=tagins&section=curr&t=cur&i='.$trk->id.'">'. '<img src="pix/tag.gif" alt="Tags" title="Tags" /></a>'; $clusterbutton = '<a href="index.php?s=clutrk&section=curr&mode=trk&' . 'track=' . $trk->id . '"><img src="pix/cluster.gif" alt="Clusters" '. 'title="Clusters" /></a>';*/ $newarr = array(); foreach ($columns as $column => $cdesc) { if ($column == 'clsname') { $newarr[] = '<a href="index.php?s=cls§ion=curr&action=edit&id=' . $trk->classid . '">' . $trk->{$column} . '</a>'; } else { $newarr[] = $trk->{$column}; } } $newarr[] = $editbutton . ' ' . $deletebutton; $table->data[] = $newarr; } } echo "<table class=\"searchbox\" style=\"margin-left:auto;margin-right:auto\" cellpadding=\"10\"><tr><td>"; echo "<form action=\"index.php\" method=\"get\"><fieldset class=\"invisiblefieldset\">"; echo '<input type="hidden" name="s" value="trkcls" />'; echo '<input type="hidden" name="section" value="curr" />'; echo '<input type="hidden" name="sort" value="' . $sort . '" />'; echo '<input type="hidden" name="dir" value="' . $dir . '" />'; echo '<input type="hidden" name="perpage" value="' . $perpage . '" />'; echo '<input type="hidden" name="trackid" value="' . $trackid . '" />'; echo "<input type=\"text\" name=\"search\" value=\"" . s($namesearch, true) . "\" size=\"40\" />"; echo "<input type=\"submit\" value=\"" . get_string('search', 'block_curr_admin') . "\" />"; if ($namesearch) { echo "<input type=\"button\" onclick=\"document.location='index.php?s=trkcls&" . "section=curr&sort={$sort}&dir={$dir}&perpage={$perpage}&alpha={$alpha}&trackid={$trackid}';\" " . "value=\"" . get_string('show_all_curricula', 'block_curr_admin') . "\" />"; } echo "</fieldset></form>"; echo "</td></tr></table>"; if (!empty($table)) { print_heading('<a href="index.php?s=trkcls&section=curr&action=add&trackid=' . $trackid . '">' . get_string('trackasso_add_asso', 'block_curr_admin', $track->name) . '</a>'); print_table($table); print_paging_bar($numtrk, $page, $perpage, "index.php?s=trkcls&section=curr&sort={$sort}&dir={$dir}&perpage={$perpage}" . "&alpha={$alpha}&trackid={$trackid}&search=" . urlencode(stripslashes($namesearch)) . "&"); } print_heading('<a href="index.php?s=trkcls&section=curr&action=add&trackid=' . $trackid . '">' . get_string('trackasso_add_asso', 'block_curr_admin', $track->name) . '</a>'); }