/** * Adds controls specific to this filter in the form. * @param object $mform a MoodleForm object to setup */ function setupForm(&$mform) { global $USER; $choices_array = array(); //figure out which capability to check if ($this->execution_mode == php_report::EXECUTION_MODE_SCHEDULED) { $capability = 'block/php_report:schedule'; } else { $capability = 'block/php_report:view'; } //obtain all course contexts where this user can view reports $contexts = get_contexts_by_capability_for_user('user', $capability, $USER->id); $context_array = array('contexts' => $contexts); if ($records = cluster_get_listing('name', 'ASC', 0, 0, '', '', $context_array)) { foreach ($records as $record) { if ($record->parent == 0) { $choices_array[$record->id] = $record->name; $child_array = $this->find_child_clusters($records, $record->id); $choices_array = $this->merge_array_keep_keys($choices_array, $child_array); } } } //explicitly set the list of available options $this->_options = $choices_array; parent::setupForm($mform); }
/** * Dynamically loads child menu items for a cluster entity (similar to block_elisadmin_load_menu_children * but only includes clusters and always includes all children) * * @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 string $parent_path Path of parent curriculum elements in the tree * @param int $execution_mode The constant representing the execution mode * @return menuitem array The appropriate child items */ function clustertree_load_menu_children_cluster($id, $parent_cluster_id, $parent_curriculum_id, $parent_path, $execution_mode) { $result_items = array(new menuitem('root')); /***************************************** * Cluster - Child Cluster Associations *****************************************/ $cluster_css_class = block_elisadmin_get_item_css_class('cluster_instance'); //get all child clusters $listing = cluster_get_listing('priority, name', 'ASC', 0, 0, '', '', array('parent' => $id)); if (!empty($listing)) { foreach ($listing as $item) { $params = array('id' => $item->id, 'action' => 'viewreport', 'execution_mode' => $execution_mode); //don't need permissions checking because custom contexts don't support //prevents / prohibits $cluster_count = cluster_count_records('', '', array('parent' => $item->id)); $isLeaf = empty($cluster_count); $result_items[] = block_elisadmin_get_menu_item('cluster', $item, 'root', $cluster_css_class, $item->id, $parent_curriculum_id, $params, $isLeaf, $parent_path); } } return $result_items; }
/** * Dynamically loads child menu items for a cluster 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_userset($id, $parent_cluster_id, $parent_curriculum_id, $num_block_icons, $parent_path = '') { global $CFG; //page dependencies require_once elispm::file('coursepage.class.php'); $result_items = array(); /***************************************** * Cluster - Child Cluster Associations *****************************************/ //note - no need to worry about permissions since there is no prevents/prohibits in ELIS $cluster_css_class = block_elisadmin_get_item_css_class('cluster_instance'); $listing = cluster_get_listing('name', 'ASC', 0, $num_block_icons, '', '', array('parent' => $id)); //$listing = cluster_get_listing('priority, name', 'ASC', 0, $num_block_icons, '', '', array('parent' => $id)); if (!empty($listing)) { foreach ($listing as $item) { $params = array('id' => $item->id, 'action' => 'view'); $cluster_count = cluster_count_records('', '', array('parent' => $item->id)); $curriculum_count = clustercurriculum::count_curricula($item->id); $isLeaf = empty($cluster_count) && empty($curriculum_count); $result_items[] = block_elisadmin_get_menu_item('userset', $item, 'root', $cluster_css_class, $item->id, $parent_curriculum_id, $params, $isLeaf, $parent_path); } } //summary item $num_records = cluster_count_records('', '', array('parent' => $id)); if ($num_block_icons < $num_records) { $params = array('id' => $parent_cluster_id); $result_items[] = block_elisadmin_get_menu_summary_item('userset', $cluster_css_class, $num_records - $num_block_icons, $params, '', $parent_path); } /***************************************** * Cluster - Curriculum *****************************************/ $curriculum_css_class = block_elisadmin_get_item_css_class('curriculum_instance'); //permissions filter $curriculum_filter = array('contexts' => curriculumpage::get_contexts('local/elisprogram:program_view')); $curricula = clustercurriculum::get_curricula($id, 0, $num_block_icons, 'cur.priority ASC, cur.name ASC', $curriculum_filter); if (!empty($curricula)) { foreach ($curricula as $curriculum) { $curriculum->id = $curriculum->curriculumid; $params = array('id' => $curriculum->id, 'action' => 'view'); //count associated courses $course_filter = array('contexts' => coursepage::get_contexts('local/elisprogram:course_view')); $course_count = curriculumcourse_count_records($curriculum->id, '', '', $course_filter); //count associated tracks $track_contexts = trackpage::get_contexts('local/elisprogram:track_view'); $track_count = track_count_records('', '', $curriculum->id, $parent_cluster_id, $track_contexts); //count associated clusters $cluster_filter = array('contexts' => usersetpage::get_contexts('local/elisprogram:userset_view')); $cluster_count = clustercurriculum::count_clusters($curriculum->id, $parent_cluster_id, $cluster_filter); $isLeaf = empty($course_count) && empty($track_count) && empty($cluster_count); $result_items[] = block_elisadmin_get_menu_item('curriculum', $curriculum, 'root', $curriculum_css_class, $parent_cluster_id, $curriculum->id, $params, $isLeaf, $parent_path); } } //summary item $num_records = clustercurriculum::count_curricula($id, $curriculum_filter); if ($num_block_icons < $num_records) { $params = array('id' => $id); $result_items[] = block_elisadmin_get_menu_summary_item('clustercurriculum', $curriculum_css_class, $num_records - $num_block_icons, $params, '', $parent_path); } return $result_items; }
function get_content() { global $CFG, $ADMIN, $USER, $CURMAN, $HTTPSPAGEREQUIRED; require_once $CFG->libdir . '/adminlib.php'; require_once $CFG->dirroot . '/my/pagelib.php'; // dependencies on page classes require_once $CFG->dirroot . '/curriculum/clusterpage.class.php'; require_once $CFG->dirroot . '/curriculum/curriculumpage.class.php'; require_once $CFG->dirroot . '/curriculum/coursepage.class.php'; require_once $CFG->dirroot . '/curriculum/trackpage.class.php'; // ELIS-1251 - Don't display a useless message if in the center column // if ($this->instance->position == BLOCK_POS_CENTRE) { // $this->content = new stdClass; // $output = "This is content to display if in the middle..."; // $this->content->text = $output; // $this->content->footer = ''; // return $this->content; // } /// Display a link to the admin interface if on the main site index page and the current user has /// admin or developer access. // if ($this->instance->pageid == SITEID && // has_capability('block/curr_admin:config', get_context_instance(CONTEXT_SYSTEM, SITEID))) { // // $this->content = new stdClass; // $this->content->text = '<a href="' . $CFG->wwwroot . '/curriculum/index.php">' . // get_string('accesscurriculumadmin', 'block_curr_admin') . '</a>'; // $this->content->footer = ''; // } /// Determine the users CM access level. $access = cm_determine_access($USER->id); $this->title = get_string("blocktitle{$access}", 'block_curr_admin'); if (empty($access) || $this->content !== NULL) { return $this->content; } //if we are not on a CM "newpage", disable the expansion of //entities in the curr admin tree (logic in curriculum/index.php) if (!isset($CURMAN->page)) { unset($USER->currentitypath); } //include the necessary javascript libraries for the YUI TreeView require_js(array('yui_yahoo', 'yui_dom', 'yui_event', 'yui_treeview')); //for converting tree representation require_js('yui_json'); //for asynch request dynamic loading require_js('yui_connection'); //include our custom code that handles the YUI Treeview menu if (!empty($HTTPSPAGEREQUIRED)) { $wwwroot = $CFG->httpswwwroot; } else { $wwwroot = $CFG->wwwroot; } require_js($wwwroot . '/curriculum/js/menuitem.js'); //CM entities for placement at the top of the menu $cm_entity_pages = array(); $cm_entity_pages[] = new menuitem('root'); $num_block_icons = isset($CURMAN->config->num_block_icons) ? $CURMAN->config->num_block_icons : 5; /***************************************** * Clusters *****************************************/ if (!isset($CURMAN->config->display_clusters_at_top_level) || !empty($CURMAN->config->display_clusters_at_top_level)) { $manageclusters_css_class = block_curr_admin_get_item_css_class('manageclusters'); $cluster_css_class = block_curr_admin_get_item_css_class('cluster_instance'); require_once CURMAN_DIRLOCATION . '/lib/contexts.php'; $context_result = cm_context_set::for_user_with_capability('cluster', 'block/curr_admin:cluster:view', $USER->id); $extrafilters = array('contexts' => $context_result, 'parent' => 0); $num_records = cluster_count_records('', '', $extrafilters); if ($clusters = cluster_get_listing('priority, name', 'ASC', 0, $num_block_icons, '', '', $extrafilters)) { foreach ($clusters as $cluster) { $params = array('id' => $cluster->id, 'action' => 'view'); // count sub-clusters $cluster_filter = array('contexts' => clusterpage::get_contexts('block/curr_admin:cluster:view'), 'parent' => $cluster->id); $cluster_count = cluster_count_records('', '', $cluster_filter); // count associated curricula $curriculum_filter = array('contexts' => curriculumpage::get_contexts('block/curr_admin:curriculum:view')); $curriculum_count = clustercurriculum::count_curricula($cluster->id, $curriculum_filter); $isLeaf = empty($cluster_count) && empty($curriculum_count); $cm_entity_pages[] = block_curr_admin_get_menu_item('cluster', $cluster, 'root', $manageclusters_css_class, $cluster->id, 0, $params, $isLeaf); } } if ($num_block_icons < $num_records) { $cm_entity_pages[] = block_curr_admin_get_menu_summary_item('cluster', $cluster_css_class, $num_records - $num_block_icons); } } /***************************************** * Curricula *****************************************/ if (!empty($CURMAN->config->display_curricula_at_top_level)) { $managecurricula_css_class = block_curr_admin_get_item_css_class('managecurricula'); $curriculum_css_class = block_curr_admin_get_item_css_class('curriculum_instance'); require_once CURMAN_DIRLOCATION . '/curriculumpage.class.php'; $num_records = curriculum_count_records('', '', curriculumpage::get_contexts('block/curr_admin:curriculum:view')); if ($curricula = get_records(CURTABLE, '', '', 'priority ASC, name ASC', '*', 0, $num_block_icons)) { foreach ($curricula as $curriculum) { $params = array('id' => $curriculum->id, 'action' => 'view'); // count associated courses $course_filter = array('contexts' => coursepage::get_contexts('block/curr_admin:course:view')); $course_count = curriculumcourse_count_records($curriculum->id, '', '', $course_filter); // count associated tracks $track_contexts = trackpage::get_contexts('block/curr_admin:track:view'); $track_count = track_count_records('', '', $curriculum->id, 0, $track_contexts); // count associated clusters $cluster_filter = array('contexts' => clusterpage::get_contexts('block/curr_admin:cluster:view')); $cluster_count = clustercurriculum::count_clusters($curriculum->id, 0, $cluster_filter); $isLeaf = empty($course_count) && empty($track_count) && empty($cluster_count); $cm_entity_pages[] = block_curr_admin_get_menu_item('curriculum', $curriculum, 'root', $managecurricula_css_class, 0, $curriculum->id, $params, $isLeaf); } } if ($num_block_icons < $num_records) { $cm_entity_pages[] = block_curr_admin_get_menu_summary_item('curriculum', $curriculum_css_class, $num_records - $num_block_icons); } } global $SITE; //general cm pages $pages = array(new menuitem('dashboard', new menuitempage('dashboardpage'), 'root', '', block_curr_admin_get_item_css_class('dashboard')), new menuitem('admn', null, 'root', get_string('admin'), block_curr_admin_get_item_css_class('admn', true)), new menuitem('bulkuser', new menuitempage('bulkuserpage'), null, get_string('userbulk', 'admin'), block_curr_admin_get_item_css_class('bulkuser'))); //show the Jasper report server link if applicable if (cm_jasper_link_enabled()) { //page action $jasper_link_params = array('action' => 'reportslist'); //page instance $jasper_link_page = new menuitempage('jasperreportpage', '', $jasper_link_params); //styling for the link $jasper_link_css = block_curr_admin_get_item_css_class('reportslist'); $pages[] = new menuitem('reportslist', $jasper_link_page, null, '', $jasper_link_css); } $pages = array_merge($pages, array(new menuitem('customfields', new menuitempage('customfieldpage', '', array('level' => 'user')), null, '', block_curr_admin_get_item_css_class('customfields')), new menuitem('clusterclassification', new menuitempage('clusterclassificationpage', 'plugins/cluster_classification/clusterclassificationpage.class.php'), null, get_string('cluster_classification', 'crlm_cluster_classification'), block_curr_admin_get_item_css_class('clusterclassification')), new menuitem('info', null, 'root', get_string('informationalelements', 'block_curr_admin'), block_curr_admin_get_item_css_class('info', true)), new menuitem('managetags', new menuitempage('tagpage'), null, '', block_curr_admin_get_item_css_class('managetags')), new menuitem('manageenvironments', new menuitempage('envpage'), null, '', block_curr_admin_get_item_css_class('manageenvironments')), new menuitem('users', null, 'root', '', block_curr_admin_get_item_css_class('users', true)), new menuitem('manageusers', new menuitempage('usermanagementpage'), null, '', block_curr_admin_get_item_css_class('manageusers')), new menuitem('manageclusters', new menuitempage('clusterpage'), null, '', block_curr_admin_get_item_css_class('manageclusters')), new menuitem('curr', null, 'root', get_string('curriculum', 'block_curr_admin'), block_curr_admin_get_item_css_class('curr', true)), new menuitem('certificatelist', new menuitempage('certificatelistpage'), null, '', block_curr_admin_get_item_css_class('certificatelist')), new menuitem('managecurricula', new menuitempage('curriculumpage'), null, '', block_curr_admin_get_item_css_class('managecurricula')), new menuitem('managecourses', new menuitempage('coursepage'), null, '', block_curr_admin_get_item_css_class('managecourses')), new menuitem('manageclasses', new menuitempage('cmclasspage'), null, '', block_curr_admin_get_item_css_class('manageclasses')), new menuitem('crscat', null, 'root', get_string('learningplan', 'block_curr_admin'), block_curr_admin_get_item_css_class('crscat', true)), new menuitem('currentcourses', new menuitempage('coursecatalogpage', '', array('action' => 'current')), null, '', block_curr_admin_get_item_css_class('currentcourses')), new menuitem('availablecourses', new menuitempage('coursecatalogpage', '', array('action' => 'available')), null, '', block_curr_admin_get_item_css_class('availablecourses')), new menuitem('waitlist', new menuitempage('coursecatalogpage', '', array('action' => 'waitlist')), null, get_string('waitlistcourses', 'block_curr_admin'), block_curr_admin_get_item_css_class('waitlist')), new menuitem('rept', null, 'root', get_string('reports', 'block_curr_admin'), block_curr_admin_get_item_css_class('rept', true)))); if (has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $SITE->id))) { if ($CURMAN->config->site_course_cluster_groups) { $pages[] = new menuitem('frontpagegroups', new menuitempage('url_page', 'lib/menuitem.class.php', "{$CFG->wwwroot}/group/index.php?id={$SITE->id}"), 'admn', get_string('frontpagegroups', 'crlm_cluster_groups'), block_curr_admin_get_item_css_class('manageclusters')); } if ($CURMAN->config->cluster_groupings) { $pages[] = new menuitem('frontpagegroupings', new menuitempage('url_page', 'lib/menuitem.class.php', "{$CFG->wwwroot}/group/groupings.php?id={$SITE->id}"), 'admn', get_string('frontpagegroupings', 'crlm_cluster_groups'), block_curr_admin_get_item_css_class('manageclusters')); } } /** * This section adds all the necessary PHP reports to the menu */ //get all report pages, including categories but not including the //topmost report element $report_pages = block_curr_admin_get_report_tree_items(); //merge in the reporting page links $pages = array_merge($pages, $report_pages); if (empty($CURMAN->config->userdefinedtrack)) { $pages[] = new menuitem('managetracks', new menuitempage('trackpage'), null, '', block_curr_admin_get_item_css_class('managetracks')); } $access = cm_determine_access($USER->id); switch ($access) { case 'admin': case 'developer': $pages[] = new menuitem('configmanager', new menuitempage('configpage', '', array('section' => 'admn')), null, get_string('configuration'), block_curr_admin_get_item_css_class('configuration')); $pages[] = new menuitem('notifications', new menuitempage('notifications', 'notificationspage.class.php', array('section' => 'admn')), null, '', block_curr_admin_get_item_css_class('notifications')); $pages[] = new menuitem('dataimport', new menuitempage('dataimportpage', 'elis_ip/elis_ip_page.php', array('section' => 'admn')), null, '', block_curr_admin_get_item_css_class('integrationpoint')); $pages[] = new menuitem('defaultcls', new menuitempage('configclsdefaultpage', '', array('section' => 'admn')), null, '', block_curr_admin_get_item_css_class('defaultcls')); $pages[] = new menuitem('defaultcrs', new menuitempage('configcrsdefaultpage', '', array('section' => 'admn')), null, '', block_curr_admin_get_item_css_class('defaultcrs')); break; default: break; } //turn all pages that have no children into leaf nodes menuitemlisting::flag_leaf_nodes($pages); //combine the specific entity page listing with the general CM listing $menuitemlisting = new menuitemlisting(array_merge($cm_entity_pages, $pages)); $tree = new treerepresentation($menuitemlisting); $this->content = new stdClass(); $this->content->text = $tree->convert_to_markup(); $this->content->footer = ''; return $this->content; }
function action_default() { $id = $this->required_param('id', PARAM_INT); $parent_clusterid = $this->optional_param('parent_clusterid', 0, PARAM_INT); $sort = $this->optional_param('sort', 'name', PARAM_CLEAN); $dir = $this->optional_param('dir', 'ASC', PARAM_CLEAN); $columns = array('name' => get_string('cluster_name', 'block_curr_admin'), 'display' => get_string('description', 'block_curr_admin'), 'autoenrol' => get_string('auto_enrol', 'block_curr_admin'), 'buttons' => ''); $items = clustertrack::get_clusters($id, $parent_clusterid, $sort, $dir); $formatters = $this->create_link_formatters(array('name'), 'clusterpage', 'clusterid'); $this->print_list_view($items, $columns, $formatters, 'clusters'); // find the tracks that the user can associate with this cluster $contexts = clusterpage::get_contexts('block/curr_admin:associate'); $clusters = cluster_get_listing('name', 'ASC', 0, 0, '', '', array('contexts' => $contexts)); if (empty($clusters)) { $num_clusters = cluster_count_records(); if (!empty($num_clusters)) { // some clusters exist, but don't have associate capability on // any of them echo '<div align="center"><br />'; print_string('no_associate_caps_cluster', 'block_curr_admin'); echo '</div>'; } else { // no clusters at all echo '<div align="center"><br />'; print_string('all_items_assigned', 'block_curr_admin'); echo '</div>'; } } else { $this->print_dropdown($clusters, $items, 'trackid', 'clusterid'); } }
/** * Tests contexts in userset data object. * * Covers: * local/elisprogram/lib/data/userset.class.php:334 * local/elisprogram/lib/data/userset.class.php:453 * local/elisprogram/lib/data/userset.class.php:561 * local/elisprogram/lib/data/userset.class.php:595 * local/elisprogram/lib/data/userset.class.php:616 * local/elisprogram/lib/data/userset.class.php:721 * local/elisprogram/lib/data/userset.class.php:755 * local/elisprogram/lib/data/userset.class.php:847 * local/elisprogram/lib/data/userset.class.php:901 */ public function test_usersetcontexts() { global $USER, $DB; require_once elispm::file('plugins/usetclassify/usersetclassification.class.php'); require_once elispm::file('plugins/usetclassify/lib.php'); $this->setup_users(); $this->setup_usersets(); // TEST local/elisprogram/lib/data/userset.class.php:334. $res = userset::get_allowed_clusters(1); // TEST local/elisprogram/lib/data/userset.class.php:453. $ussfilter = new usersubset_filter('id', new field_filter('id', 1)); $res = $ussfilter->get_sql(); // TEST // local/elisprogram/lib/data/userset.class.php:561 // local/elisprogram/lib/data/userset.class.php:595 // local/elisprogram/lib/data/userset.class.php:616 // local/elisprogram/lib/data/userset.class.php:721 // local/elisprogram/lib/data/userset.class.php:755. $field = new field(array('shortname' => USERSET_CLASSIFICATION_FIELD)); $field->load(); $userset = $this->create_userset($field); // Get a role to assign. $rolesctx = $DB->get_records('role_context_levels', array('contextlevel' => CONTEXT_ELIS_USERSET)); foreach ($rolesctx as $i => $rolectx) { $roleid = $rolectx->roleid; } // Add userset_view capability to our role. $usersetcontext = \local_elisprogram\context\userset::instance($userset->id); $rc = new stdClass(); $rc->contextid = $usersetcontext->id; $rc->roleid = $roleid; $rc->capability = 'local/elisprogram:userset_view'; $rc->permission = 1; $rc->timemodified = time(); $rc->modifierid = 0; $DB->insert_record('role_capabilities', $rc); $rc = new stdClass(); $rc->contextid = $usersetcontext->id; $rc->roleid = $roleid; $rc->capability = 'local/elisprogram:userset_enrol_userset_user'; $rc->permission = 1; $rc->timemodified = time(); $rc->modifierid = 0; $DB->insert_record('role_capabilities', $rc); // Assign role. $user = new user(103); $muser = $user->get_moodleuser(); $raid = role_assign($roleid, $muser->id, $usersetcontext->id); $this->setUser(100); // Assign other user to userset. $clst = new clusterassignment(); $clst->clusterid = $userset->id; $clst->userid = 104; $clst->plugin = 'manual'; $clst->save(); // Get cluster listing. $capability = 'local/elisprogram:userset_view'; $contexts = get_contexts_by_capability_for_user('cluster', $capability, 100); $extrafilters = array('contexts' => $contexts, 'classification' => 'test field data'); $res = cluster_get_listing('name', 'ASC', 0, 0, '', '', $extrafilters, 104); $res = cluster_count_records('', '', $extrafilters); // TEST local/elisprogram/lib/data/userset.class.php:847. cluster_get_non_child_clusters(1); // TEST local/elisprogram/lib/data/userset.class.php:901. cluster_get_possible_sub_clusters(1); $this->setUser(null); }
function action_default() { $id = $this->required_param('id', PARAM_INT); $this->print_autoassigned_table(); $this->print_manuallyassigned_table(); $items = $this->get_manuallyassigned_items(); //get the listing specifically for this user $this->print_dropdown(cluster_get_listing('name', 'ASC', 0, 0, '', '', array(), $id), $items, 'userid', 'clusterid', 'add'); }
* */ if (!isset($_SERVER['REMOTE_ADDR'])) { define('CLI_SCRIPT', true); } require_once dirname(__FILE__) . '/../lib/setup.php'; require_once elispm::lib('data/userset.class.php'); global $DB; if (isset($_SERVER['REMOTE_ADDR'])) { die('no web access'); } if ($argc > 1) { die(print_usage()); } mtrace("Begin User Set fixes..."); $clusters = cluster_get_listing('id'); $clusters_fixed_cnt = 0; foreach ($clusters as $clusid => $clusdata) { if ($clusdata->parent > 0) { $select = "id = '{$clusdata->parent}'"; $parent_cnt = $DB->count_records_select(userset::TABLE, $select); if ($parent_cnt < 1) { mtrace('User Set ID:' . $clusid . ' Name:' . $clusdata->name . ' converted to top-level'); $newclusdata = new stdClass(); $newclusdata->id = $clusdata->id; $newclusdata->parent = 0; $newclusdata->depth = 1; // Update the records in local_elisprogram_uset table $result = $DB->update_record(userset::TABLE, $newclusdata); // Blank out the depth and path for associated records and child records in context table $cluster_context_instance = \local_elisprogram\context\userset::instance($clusid);
function display_default() { global $OUTPUT; // Get parameters $sort = optional_param('sort', 'name', PARAM_ALPHA); $dir = optional_param('dir', 'ASC', PARAM_ALPHA); $page = optional_param('page', 0, PARAM_INT); $perpage = optional_param('perpage', 30, PARAM_INT); // how many per page $namesearch = trim(optional_param('search', '', PARAM_TEXT)); $alpha = optional_param('alpha', '', PARAM_ALPHA); $parent = $this->optional_param('id', 0, PARAM_INT); $classification = $this->optional_param('classification', NULL, PARAM_SAFEDIR); if ($parent) { $this->print_tabs('subclusters', array('id' => $parent)); } // Define columns $columns = array('name' => array('header' => get_string('userset_name', 'local_elisprogram')), 'display' => array('header' => get_string('userset_description', 'local_elisprogram'))); // set sorting if ($dir !== 'DESC') { $dir = 'ASC'; } if (isset($columns[$sort])) { $columns[$sort]['sortable'] = $dir; } else { $sort = 'defaultsortcolumn'; $columns[$sort]['sortable'] = $dir; } $extrafilters = array('contexts' => self::get_contexts('local/elisprogram:userset_view'), 'parent' => $parent, 'classification' => $classification); $items = cluster_get_listing($sort, $dir, $page * $perpage, $perpage, $namesearch, $alpha, $extrafilters); $numitems = cluster_count_records($namesearch, $alpha, $extrafilters); self::get_contexts('local/elisprogram:userset_edit'); self::get_contexts('local/elisprogram:userset_delete'); $this->print_list_view($items, $numitems, $columns, $filter = null, $alphaflag = true, $searchflag = true); if ($this->optional_param('id', 0, PARAM_INT)) { //get the non-parent clusters that are accessible based on the edit capability $contexts = usersetpage::get_contexts('local/elisprogram:userset_edit'); $non_parent_clusters = cluster_get_possible_sub_clusters($this->optional_param('id', 0, PARAM_INT), $contexts); //display the dropdown if there are one or more available clusters if (count($non_parent_clusters) > 0) { echo html_writer::start_tag('div', array('align' => 'center')); echo get_string('cluster_subcluster_prompt', 'local_elisprogram') . ': '; $url = $this->get_new_page(array('action' => 'subcluster', 'id' => $this->optional_param('id', 0, PARAM_INT)))->url . '&subclusterid='; echo $OUTPUT->single_select($url, 'subclusterid', $non_parent_clusters); echo html_writer::end_tag('div'); } } }
function __construct() { global $CURMAN; $this->parentBad = array(); if ($clusters = cluster_get_listing('id', 'ASC', 0)) { foreach ($clusters as $clusid => $clusdata) { if ($clusdata->parent > 0) { $select = "id='{$clusdata->parent}'"; $parentCnt = $CURMAN->db->count_records_select(CLSTTABLE, $select); if ($parentCnt < 1) { $this->parentBad[] = $clusdata->name; } } } } }
function get_content() { global $CFG, $ADMIN, $USER, $HTTPSPAGEREQUIRED, $PAGE, $DB, $SITE; require_once $CFG->libdir . '/adminlib.php'; //dependencies on page classes require_once elispm::file('usersetpage.class.php'); require_once elispm::file('curriculumpage.class.php'); require_once elispm::file('coursepage.class.php'); require_once elispm::file('trackpage.class.php'); //require_once($CFG->dirroot . '/my/pagelib.php'); /// Determine the users CM access level. $access = cm_determine_access($USER->id); //make sure local_elisprogram / custom contexts set up correctly //to prevent error before the upgrade to ELIS 2 if (empty($access) || $this->content !== NULL || !defined('CONTEXT_ELIS_PROGRAM')) { return $this->content; } //if we are not on a PM page, disable the expansion of //entities in the curr admin tree (logic in curriculum/index.php) if (!is_a($PAGE, 'pm_page') && $PAGE->pagetype != 'admin-setting-local_elisprogram_settings') { unset($USER->currentitypath); } // Include Icon CSS. $PAGE->requires->css('/local/elisprogram/icons.css'); //CM entities for placement at the top of the menu $cm_entity_pages = array(); $cm_entity_pages[] = new menuitem('root'); $num_block_icons = isset(elis::$config->local_elisprogram->num_block_icons) ? elis::$config->local_elisprogram->num_block_icons : 5; /***************************************** * Clusters *****************************************/ if (!isset(elis::$config->local_elisprogram->display_clusters_at_top_level) || !empty(elis::$config->local_elisprogram->display_clusters_at_top_level)) { $manageclusters_css_class = block_elisadmin_get_item_css_class('manageclusters'); $cluster_css_class = block_elisadmin_get_item_css_class('cluster_instance'); require_once elispm::lib('contexts.php'); $context_result = pm_context_set::for_user_with_capability('cluster', 'local/elisprogram:userset_view', $USER->id); $extrafilters = array('contexts' => $context_result, 'parent' => 0); $num_records = cluster_count_records('', '', $extrafilters); if ($clusters = cluster_get_listing('priority, name', 'ASC', 0, $num_block_icons, '', '', $extrafilters)) { foreach ($clusters as $cluster) { $params = array('id' => $cluster->id, 'action' => 'view'); //count sub-clusters $cluster_filter = array('contexts' => usersetpage::get_contexts('local/elisprogram:userset_view')); $cluster_count = cluster_count_records('', '', array('parent' => $cluster->id), $cluster_filter); //count associated curricula $curriculum_filter = array('contexts' => curriculumpage::get_contexts('local/elisprogram:program_view')); $curriculum_count = clustercurriculum::count_curricula($cluster->id, $curriculum_filter); $isLeaf = empty($cluster_count) && empty($curriculum_count); $cm_entity_pages[] = block_elisadmin_get_menu_item('userset', $cluster, 'root', $manageclusters_css_class, $cluster->id, 0, $params, $isLeaf); } } if ($num_block_icons < $num_records) { $cm_entity_pages[] = block_elisadmin_get_menu_summary_item('userset', $cluster_css_class, $num_records - $num_block_icons); } } /***************************************** * Curricula *****************************************/ if (!empty(elis::$config->local_elisprogram->display_curricula_at_top_level)) { $managecurricula_css_class = block_elisadmin_get_item_css_class('managecurricula'); $curriculum_css_class = block_elisadmin_get_item_css_class('curriculum_instance'); require_once elispm::file('curriculumpage.class.php'); $num_records = curriculum_count_records('', '', curriculumpage::get_contexts('local/elisprogram:program_view')); $curricula = $DB->get_recordset(curriculum::TABLE, null, 'priority ASC, name ASC', '*', 0, $num_block_icons); foreach ($curricula as $curriculum) { $params = array('id' => $curriculum->id, 'action' => 'view'); //count associated courses $course_filter = array('contexts' => coursepage::get_contexts('local/elisprogram:course_view')); $course_count = curriculumcourse_count_records($curriculum->id, '', '', $course_filter); //count associated tracks $track_contexts = trackpage::get_contexts('local/elisprogram:track_view'); $track_count = track_count_records('', '', $curriculum->id, 0, $track_contexts); //count associated clusters $cluster_filter = array('contexts' => usersetpage::get_contexts('local/elisprogram:userset_view')); $cluster_count = clustercurriculum::count_clusters($curriculum->id, 0, $cluster_filter); $isLeaf = empty($course_count) && empty($track_count) && empty($cluster_count); $cm_entity_pages[] = block_elisadmin_get_menu_item('curriculum', $curriculum, 'root', $managecurricula_css_class, 0, $curriculum->id, $params, $isLeaf); } unset($curricula); if ($num_block_icons < $num_records) { $cm_entity_pages[] = block_elisadmin_get_menu_summary_item('curriculum', $curriculum_css_class, $num_records - $num_block_icons); } } //general cm pages $pages = array(new menuitem('dashboard', new menuitempage('dashboardpage'), 'root', '', block_elisadmin_get_item_css_class('dashboard')), new menuitem('admn', null, 'root', get_string('admin'), block_elisadmin_get_item_css_class('admn', true)), new menuitem('bulkuser', new menuitempage('bulkuserpage'), null, get_string('userbulk', 'admin'), block_elisadmin_get_item_css_class('bulkuser')), new menuitem('resultsconfig', new menuitempage('resultsconfigpage'), null, 'Default Results Engine Score Settings', block_elisadmin_get_item_css_class('resultsconfig'))); // ELIS-3208 - commented out this code as the Jasper reports no longer work in ELIS 2 /* //show the Jasper report server link if applicable if (cm_jasper_link_enabled()) { //page action $jasper_link_params = array('action' => 'reportslist'); //page instance $jasper_link_page = new menuitempage('jasperreportpage', '', $jasper_link_params); //styling for the link $jasper_link_css = block_elisadmin_get_item_css_class('reportslist'); $pages[] = new menuitem('reportslist', $jasper_link_page, null, '', $jasper_link_css); } */ $pages = array_merge($pages, array(new menuitem('customfields', new menuitempage('customfieldpage', '', array('level' => 'user')), null, '', block_elisadmin_get_item_css_class('customfields')), new menuitem('clusterclassification', new menuitempage('usersetclassificationpage', 'plugins/usetclassify/usersetclassificationpage.class.php'), null, get_string('userset_classification', 'elisprogram_usetclassify'), block_elisadmin_get_item_css_class('clusterclassification')), new menuitem('users', null, 'root', '', block_elisadmin_get_item_css_class('users', true)), new menuitem('manageusers', new menuitempage('userpage'), null, '', block_elisadmin_get_item_css_class('manageusers')), new menuitem('manageclusters', new menuitempage('usersetpage'), null, '', block_elisadmin_get_item_css_class('manageclusters')), new menuitem('curr', null, 'root', get_string('curriculum', 'local_elisprogram'), block_elisadmin_get_item_css_class('curr', true)), new menuitem('certificatelist', new menuitempage('certificatelistpage'), null, '', block_elisadmin_get_item_css_class('certificatelist')), new menuitem('managecurricula', new menuitempage('curriculumpage'), null, '', block_elisadmin_get_item_css_class('managecurricula')), new menuitem('managecourses', new menuitempage('coursepage'), null, '', block_elisadmin_get_item_css_class('managecourses')), new menuitem('manageclasses', new menuitempage('pmclasspage'), null, '', block_elisadmin_get_item_css_class('manageclasses')), new menuitem('crscat', null, 'root', get_string('learningplan', 'local_elisprogram'), block_elisadmin_get_item_css_class('crscat', true)), new menuitem('currentcourses', new menuitempage('coursecatalogpage', '', array('action' => 'current')), null, '', block_elisadmin_get_item_css_class('currentcourses')), new menuitem('availablecourses', new menuitempage('coursecatalogpage', '', array('action' => 'available')), null, '', block_elisadmin_get_item_css_class('availablecourses')), new menuitem('waitlist', new menuitempage('coursecatalogpage', '', array('action' => 'waitlist')), null, get_string('waitlistcourses', 'local_elisprogram'), block_elisadmin_get_item_css_class('waitlist')), new menuitem('rept', null, 'root', get_string('reports', 'local_elisprogram'), block_elisadmin_get_item_css_class('rept', true)))); if (has_capability('moodle/course:managegroups', context_course::instance($SITE->id))) { if (elis::$config->elisprogram_usetgroups->site_course_userset_groups) { $pages[] = new menuitem('frontpagegroups', new menuitempage('url_page', 'lib/menuitem.class.php', "{$CFG->wwwroot}/group/index.php?id={$SITE->id}"), 'admn', get_string('frontpagegroups', 'elisprogram_usetgroups'), block_elisadmin_get_item_css_class('manageclusters')); } if (elis::$config->elisprogram_usetgroups->userset_groupings) { $pages[] = new menuitem('frontpagegroupings', new menuitempage('url_page', 'lib/menuitem.class.php', "{$CFG->wwwroot}/group/groupings.php?id={$SITE->id}"), 'admn', get_string('frontpagegroupings', 'elisprogram_usetgroups'), block_elisadmin_get_item_css_class('manageclusters')); } } /** * This section adds all the necessary PHP reports to the menu */ //get all report pages, including categories but not including the //topmost report element $report_pages = block_elisadmin_get_report_tree_items(); //merge in the reporting page links $pages = array_merge($pages, $report_pages); if (empty(elis::$config->local_elisprogram->userdefinedtrack)) { $pages[] = new menuitem('managetracks', new menuitempage('trackpage'), null, '', block_elisadmin_get_item_css_class('managetracks')); } $syscontext = context_system::instance(); if (has_capability('local/elisprogram:config', $syscontext)) { $pages[] = new menuitem('configmanager', new menuitempage('url_page', 'lib/menuitem.class.php', "{$CFG->wwwroot}/admin/settings.php?section=local_elisprogram_settings"), 'admn', get_string('configuration'), block_elisadmin_get_item_css_class('configuration')); } $pages[] = new menuitem('notifications', new menuitempage('notifications', 'notificationspage.class.php', array('section' => 'admn')), null, '', block_elisadmin_get_item_css_class('notifications')); //$pages[] = new menuitem('dataimport', new menuitempage('dataimportpage', 'elis_ip/elis_ip_page.php', array('section' => 'admn')), null, '', block_elisadmin_get_item_css_class('integrationpoint')); $pages[] = new menuitem('defaultcls', new menuitempage('configclsdefaultpage', '', array('section' => 'admn')), null, '', block_elisadmin_get_item_css_class('defaultcls')); $pages[] = new menuitem('defaultcrs', new menuitempage('configcrsdefaultpage', '', array('section' => 'admn')), null, '', block_elisadmin_get_item_css_class('defaultcrs')); //turn all pages that have no children into leaf nodes menuitemlisting::flag_leaf_nodes($pages); //combine the specific entity page listing with the general CM listing $menuitemlisting = new menuitemlisting(array_merge($cm_entity_pages, $pages)); $tree = new treerepresentation($menuitemlisting); $this->content = new stdClass(); $this->content->text = $tree->convert_to_markup(); $this->content->footer = ''; $PAGE->requires->yui_module('moodle-local_elisprogram-menuitem', 'M.local_elisprogram.init_menuitem', array($tree->get_js_object(), $CFG->httpswwwroot), null, true); return $this->content; }
/** * Adds controls specific to this filter in the form. * @param object $mform a MoodleForm object to setup */ function setupForm(&$mform) { global $USER, $CFG; /** * CSS includes */ $mform->addElement('html', '<style>@import url("' . $CFG->wwwroot . '/lib/yui/treeview/assets/skins/sam/treeview-skin.css");</style>'); /**(use "git add" and/or "git commit -a") * JavaScript includes */ //include the necessary javascript libraries for the YUI TreeView require_js(array('yui_yahoo', 'yui_dom', 'yui_event', 'yui_treeview')); //for converting tree representation require_js('yui_json'); //for asynch request dynamic loading require_js('yui_connection'); //include our custom code that handles the YUI Treeview menu require_js($CFG->wwwroot . '/curriculum/js/clustertree.js'); /** * Get set up necessary CSS classes */ $manageclusters_css_class = block_curr_admin_get_item_css_class('manageclusters'); $cluster_css_class = block_curr_admin_get_item_css_class('cluster_instance'); //figure out which capability to check if ($this->execution_mode == php_report::EXECUTION_MODE_SCHEDULED) { $capability = 'block/php_report:schedule'; } else { $capability = 'block/php_report:view'; } $context_result = cm_context_set::for_user_with_capability('cluster', $capability, $USER->id); $extrafilters = array('contexts' => $context_result, 'parent' => 0); $num_records = cluster_count_records('', '', $extrafilters); /** * TreeView-related work */ //CM entities for placement at the top of the menu $cm_entity_pages = array(); $cm_entity_pages[] = new menuitem('root'); if ($clusters = cluster_get_listing('priority, name', 'ASC', 0, 0, '', '', array('parent' => 0))) { foreach ($clusters as $cluster) { $params = array('id' => $cluster->id, 'action' => 'viewreport', 'execution_mode' => $this->execution_mode); $cluster_count = cluster_count_records('', '', array('parent' => $cluster->id)); $isLeaf = empty($cluster_count); $cm_entity_pages[] = test_cluster_tree_get_menu_item('cluster', $cluster, 'root', $manageclusters_css_class, $cluster->id, 0, $params, $isLeaf); } } $menuitemlisting = new menuitemlisting($cm_entity_pages); $tree = new checkbox_treerepresentation($menuitemlisting, $this->options['report_id']); $tree_html = $tree->convert_to_markup($this->_uniqueid, $this->execution_mode); $params = array($this->options['report_id'], $this->_uniqueid, $this->options['dropdown_button_text'], $this->options['tree_button_text']); $param_string = implode('", "', $params); /** * UI element setup */ require_once $CFG->dirroot . '/curriculum/lib/filtering/equalityselect.php'; $choices_array = array(0 => get_string('anyvalue', 'filters')); //set up cluster listing if ($records = cluster_get_listing('name', 'ASC', 0, 0, '', '', array('contexts' => $context_result))) { foreach ($records as $record) { if ($record->parent == 0) { //merge in child clusters $choices_array[$record->id] = $record->name; $child_array = $this->find_child_clusters($records, $record->id); $choices_array = $this->merge_array_keep_keys($choices_array, $child_array); } } } //get help text if (isset($this->options['help'])) { $this->_filterhelp = $this->options['help']; } else { $this->_filterhelp = null; } //add filterhelp and label to this filter //import required css for the fieldset $style = '<style>@import url("' . $CFG->wwwroot . '/curriculum/styles.css");</style>'; //hack the nested fieldset into an html element $helptext = get_string('helpprefix2', $this->_filterhelp['1']) . ' (' . get_string('newwindow') . ')'; $helpurl = '/help.php?module=' . $this->_filterhelp['2'] . '&file=' . $this->_filterhelp['0'] . '.html&forcelang='; $helplink = '<span class="helplink"><a title="' . $this->_filterhelp['1'] . '" href="' . $CFG->wwwroot . $helpurl . '"' . ' onclick="this.target=\'popup\'; return openpopup(\'' . $helpurl . '\', \'popup\', \'menubar=0,location=0,scrollbars,resizable,width=500,height=400\', 0);">' . ' <img class="iconhelp" alt="' . $helptext . '" src="' . $CFG->pixpath . '/help.gif"></a></span>'; $nested_fieldset = false; $title = ''; if ($this->options['fieldset']) { $nested_fieldset = '<fieldset class="nested clearfix" id="' . $this->_uniqueid . '_label' . '">' . "\n" . '<legend class="ftoggler">' . $this->_label . $helplink . '</legend>' . "\n"; } else { $title = $this->_label . $helplink . ' '; } $mform->addElement('html', $style . $nested_fieldset); //cluster select dropdown $mform->addElement('select', $this->_uniqueid . '_dropdown', $title, $choices_array); //dropdown / cluster tree state storage $mform->addElement('hidden', $this->_uniqueid . '_usingdropdown'); //default to showing dropdown if nothing has been persisted $report_shortname = $this->options['report_shortname']; $preferences = php_report_filtering_get_user_preferences($report_shortname); if (!isset($preferences["php_report_{$report_shortname}/{$this->_uniqueid}_usingdropdown"])) { $mform->setDefault($this->_uniqueid . '_usingdropdown', 1); } // dress it up like an mform element $tree_html = '<div class="fitem"><div class="fitemtitle"></div>' . $tree_html . '</div>'; //cluster tree $mform->addElement('html', $tree_html); //list of explicitly selected elements $mform->addElement('hidden', $this->_uniqueid . '_listing'); //list of selected and unexpanded elements $mform->addElement('hidden', $this->_uniqueid . '_unexpanded'); //list of explicitly unselected elements $mform->addElement('hidden', $this->_uniqueid . '_clrunexpanded'); /** * Work needed to initialize the state of necessary components */ //parameters needed $params = array($this->options['report_id'], $this->_uniqueid, $this->options['dropdown_button_text'], $this->options['tree_button_text']); $param_string = implode('", "', $params); $mform->addElement('button', $this->_uniqueid . '_toggle', $this->options['dropdown_button_text'], array('onclick' => 'clustertree_toggle_tree("' . $param_string . '")')); //script to do the work $initialize_state_script = '<script type="text/javascript"> clustertree_set_toggle_state("' . $param_string . '"); </script>'; $mform->addElement('html', $initialize_state_script); // close hacked nested fieldset if ($this->options['fieldset']) { $mform->addElement('html', '</fieldset>'); } }
/** * Verify that getting the cluster listing works. */ public function test_clustergetlisting() { $this->load_csv_data(); $clusters = cluster_get_listing('priority, name', 'ASC', 0, 5, '', '', array('parent' => 0)); $this->assertNotEmpty($clusters); }
/** * Dynamically loads child menu items for a cluster entity * * @param int $id The entity id * @param int $parent_cluster_id The last cluster passed going down the curr_admin tree, or 0 if none * @param int $parent_curriculum_id The last curriculum passed going down the curr_admin 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_curr_admin_load_menu_children_cluster($id, $parent_cluster_id, $parent_curriculum_id, $num_block_icons, $parent_path = '') { global $CFG, $USER; // page dependencies require_once $CFG->dirroot . '/curriculum/coursepage.class.php'; //error_log("block_curr_admin_load_menu_children_cluster($id, $parent_cluster_id, $parent_curriculum_id, $num_block_icons, $parent_path)"); $result_items = array(); /***************************************** * Cluster - Child Cluster Associations *****************************************/ // TBD: no permission check 'cause currently there is no prevents/prohibits in ELIS $cluster_css_class = block_curr_admin_get_item_css_class('cluster_instance'); $parent_clst_filter = array('contexts' => clusterpage::get_contexts('block/curr_admin:cluster:view'), 'parent' => $id); $listing = cluster_get_listing('priority, name', 'ASC', 0, $num_block_icons, '', '', $parent_clst_filter); $curriculum_filter = array('contexts' => curriculumpage::get_contexts('block/curr_admin:curriculum:view')); if (!empty($listing)) { foreach ($listing as $item) { $params = array('id' => $item->id, 'action' => 'view'); $cluster_filter = array('contexts' => clusterpage::get_contexts('block/curr_admin:cluster:view'), 'parent' => $item->id); $cluster_count = cluster_count_records('', '', $cluster_filter); $curriculum_count = clustercurriculum::count_curricula($item->id, $curriculum_filter); $isLeaf = empty($cluster_count) && empty($curriculum_count); $result_items[] = block_curr_admin_get_menu_item('cluster', $item, 'root', $cluster_css_class, $item->id, $parent_curriculum_id, $params, $isLeaf, $parent_path); //error_log("block_curr_admin_load_menu_children_cluster(); parent of cluster child = {$result_items[count($result_items) - 1]->parent}"); } } //summary item $num_records = cluster_count_records('', '', $parent_clst_filter); if ($num_block_icons < $num_records) { $params = array('id' => $parent_cluster_id); $result_items[] = block_curr_admin_get_menu_summary_item('cluster', $cluster_css_class, $num_records - $num_block_icons, $params, '', $parent_path); } /***************************************** * Cluster - Curriculum *****************************************/ $curriculum_css_class = block_curr_admin_get_item_css_class('curriculum_instance'); // permissions filter $curricula = clustercurriculum::get_curricula($id, 0, $num_block_icons, 'cur.priority ASC, cur.name ASC', $curriculum_filter); if (!empty($curricula)) { foreach ($curricula as $curriculum) { $curriculum->id = $curriculum->curriculumid; $params = array('id' => $curriculum->id, 'action' => 'view'); // count associated courses $course_filter = array('contexts' => coursepage::get_contexts('block/curr_admin:course:view')); $course_count = curriculumcourse_count_records($curriculum->id, '', '', $course_filter); // count associated tracks $track_contexts = trackpage::get_contexts('block/curr_admin:track:view'); $track_count = track_count_records('', '', $curriculum->id, $parent_cluster_id, $track_contexts); // count associated clusters $cluster_filter = array('contexts' => clusterpage::get_contexts('block/curr_admin:cluster:view')); $cluster_count = clustercurriculum::count_clusters($curriculum->id, $parent_cluster_id, $cluster_filter); $isLeaf = empty($course_count) && empty($track_count) && empty($cluster_count); $result_items[] = block_curr_admin_get_menu_item('curriculum', $curriculum, 'root', $curriculum_css_class, $parent_cluster_id, $curriculum->id, $params, $isLeaf, $parent_path); } } //summary item $num_records = clustercurriculum::count_curricula($id, $curriculum_filter); if ($num_block_icons < $num_records) { $params = array('id' => $id); $result_items[] = block_curr_admin_get_menu_summary_item('clustercurriculum', $curriculum_css_class, $num_records - $num_block_icons, $params, '', $parent_path); } //error_log("block_curr_admin_load_menu_children_cluster => " . count($result_items) . " child meuitems."); return $result_items; }
* @subpackage curriculummanagement * @author Remote-Learner.net Inc * @license http://www.gnu.org/copyleft/gpl.html GNU GPL * @copyright (C) 2008-2012 Remote Learner.net Inc http://www.remote-learner.net * */ require_once '../config.php'; require_once '../lib/cluster.class.php'; if (isset($_SERVER['REMOTE_ADDR'])) { die('no web access'); } if ($argc > 1) { die(print_usage()); } mtrace("Begin cluster fixes..."); $clusters = cluster_get_listing('id', 'ASC', 0); $clusters_fixed_cnt = 0; foreach ($clusters as $clusid => $clusdata) { if ($clusdata->parent > 0) { $select = "id='{$clusdata->parent}'"; $parent_cnt = $CURMAN->db->count_records_select(CLSTTABLE, $select); if ($parent_cnt < 1) { mtrace('Cluster ID:' . $clusid . ' Name:' . $clusdata->name . ' converted to top-level'); $newclusdata = new stdClass(); $newclusdata->id = $clusdata->id; $newclusdata->parent = 0; $newclusdata->depth = 1; // Update the records in crlm_cluster table $result = update_record(CLSTTABLE, $newclusdata); // Blank out the depth and path for associated records and child records in context table $cluster_context_level = context_level_base::get_custom_context_level('cluster', 'block_curr_admin');
/** * Adds controls specific to this filter in the form. * @param object $mform a MoodleForm object to setup * @uses $CFG * @uses $OUTPUT * @uses $PAGE * @uses $USER */ function setupForm(&$mform) { global $CFG, $OUTPUT, $PAGE, $USER; // Javascript for cluster dropdown onchange event $cluster_group_separator = '------------------------------'; $js = ' <script type="text/javascript"> //<![CDATA[ function dropdown_separator(selectelem) { /* alert("dropdown_separator(" + selectelem.selectedIndex + ")"); */ if (selectelem.options[selectelem.selectedIndex].value < 0) { return 0; } return selectelem.selectedIndex; } //]]> </script> '; /** * CSS includes */ $mform->addElement('html', '<style>@import url("' . $CFG->wwwroot . '/lib/yui/2.9.0/build/treeview/assets/skins/sam/treeview-skin.css");</style>' . $js); /** * Get set up necessary CSS classes */ $manageclusters_css_class = block_elisadmin_get_item_css_class('manageclusters'); $cluster_css_class = block_elisadmin_get_item_css_class('cluster_instance'); //figure out which capability to check if ($this->execution_mode == php_report::EXECUTION_MODE_SCHEDULED) { $capability = 'local/elisreports:schedule'; } else { $capability = 'local/elisreports:view'; } $context_result = pm_context_set::for_user_with_capability('cluster', $capability, $USER->id); /** * TreeView-related work */ //CM entities for placement at the top of the menu $cm_entity_pages = array(); $cm_entity_pages[] = new menuitem('root'); if ($clusters = cluster_get_listing('priority, name', 'ASC', 0, 0, '', '', array('parent' => 0))) { foreach ($clusters as $cluster) { $params = array('id' => $cluster->id, 'action' => 'viewreport', 'execution_mode' => $this->execution_mode); $cluster_count = cluster_count_records('', '', array('parent' => $cluster->id)); $isLeaf = empty($cluster_count); $cm_entity_pages[] = test_cluster_tree_get_menu_item('cluster', $cluster, 'root', $manageclusters_css_class, $cluster->id, 0, $params, $isLeaf); } } $menuitemlisting = new menuitemlisting($cm_entity_pages); $tree = new checkbox_treerepresentation($menuitemlisting, $this->options['report_id']); /** * UI element setup */ require_once $CFG->dirroot . '/local/eliscore/lib/filtering/equalityselect.php'; $choices_array = array(0 => get_string('anyvalue', 'filters')); //set up cluster listing if ($records = $this->cluster_dropdown_get_listing($context_result)) { foreach ($records as $record) { if (empty($choices_array[$record->id])) { if (count($choices_array) > 1) { $choices_array[-$record->id] = $cluster_group_separator; } $ancestors = $record->depth - 1; // shorten really long cluster names $name = strlen($record->name) > 100 ? substr($record->name, 0, 100) . '...' : $record->name; $choices_array[$record->id] = $ancestors ? str_repeat('- ', $ancestors) . $name : $name; //merge in child clusters $child_array = $this->find_child_clusters($records, $record->id, $ancestors); $choices_array = $this->merge_array_keep_keys($choices_array, $child_array); } } } //get help text if (isset($this->options['help'])) { $this->_filterhelp = $this->options['help']; } else { $this->_filterhelp = null; } //add filterhelp and label to this filter //import required css for the fieldset $style = '<style>@import url("' . $CFG->wwwroot . '/local/elisprogram/styles.css");</style>'; $helplink = ''; $nested_fieldset = ''; $title = ''; if ($this->options['fieldset']) { $nested_fieldset = '<fieldset class="nested clearfix" id="' . $this->_uniqueid . "_label\">\n"; } else { $title = $this->_label . $helplink . ' '; } $legend = '<legend class="ftoggler">' . $this->_label . "</legend>\n"; $mform->addElement('html', $style . $nested_fieldset . $legend); $mform->addElement('static', $this->_uniqueid . '_help', ''); // cluster select dropdown $selectparams = array('onchange' => 'this.selectedIndex = dropdown_separator(this);'); $mform->addElement('select', $this->_uniqueid . '_dropdown', $title, $choices_array, $selectparams); //dropdown / cluster tree state storage $mform->addElement('hidden', $this->_uniqueid . '_usingdropdown'); $mform->setType($this->_uniqueid . '_usingdropdown', PARAM_BOOL); // Must use addHelpButton() to NOT open help link on page, but in popup! $mform->addHelpButton($this->_uniqueid . '_dropdown', $this->_filterhelp[0], $this->_filterhelp[2]); // TBV //default to showing dropdown if nothing has been persisted $report_shortname = $this->options['report_shortname']; $preferences = php_report_filtering_get_user_preferences($report_shortname); if (!isset($preferences["php_report_{$report_shortname}/{$this->_uniqueid}_usingdropdown"])) { $mform->setDefault($this->_uniqueid . '_usingdropdown', 1); } $initclustertreeopts = array($CFG->httpswwwroot, $tree->instanceid, $this->_uniqueid, $tree->get_js_object(), $this->execution_mode, $this->options['report_id'], $this->options['dropdown_button_text'], $this->options['tree_button_text']); $PAGE->requires->yui_module('moodle-local_elisprogram-clustertree', 'M.local_elisprogram.init_clustertree', $initclustertreeopts, null, true); // cluster tree $clustertreehtml = '<div class="fitem"><div class="fitemtitle"></div>' . '<style>@import url("' . $CFG->wwwroot . '/lib/yui/2.9.0/build/treeview/assets/skins/sam/treeview.css");</style>' . '<div id="cluster_param_tree_' . $tree->instanceid . '_' . $this->_uniqueid . '" class="ygtv-checkbox felement"></div>' . '</div>'; $mform->addElement('html', $clustertreehtml); //list of explicitly selected elements $mform->addElement('hidden', $this->_uniqueid . '_listing'); $mform->setType($this->_uniqueid . '_listing', PARAM_TEXT); //list of selected and unexpanded elements $mform->addElement('hidden', $this->_uniqueid . '_unexpanded'); $mform->setType($this->_uniqueid . '_unexpanded', PARAM_TEXT); //list of explicitly unselected elements $mform->addElement('hidden', $this->_uniqueid . '_clrunexpanded'); $mform->setType($this->_uniqueid . '_clrunexpanded', PARAM_TEXT); $mform->addElement('button', $this->_uniqueid . '_toggle', ''); // close hacked nested fieldset if ($this->options['fieldset']) { $mform->addElement('html', '</fieldset>'); } }
function action_default() { // Get parameters $sort = optional_param('sort', 'name', PARAM_ALPHA); $dir = optional_param('dir', 'ASC', PARAM_ALPHA); $page = optional_param('page', 0, PARAM_INT); $perpage = optional_param('perpage', 30, PARAM_INT); // how many per page $namesearch = trim(optional_param('search', '', PARAM_TEXT)); $alpha = optional_param('alpha', '', PARAM_ALPHA); $parent = $this->optional_param('id', 0, PARAM_INT); $classification = $this->optional_param('classification', NULL, PARAM_SAFEDIR); if ($parent) { $this->print_tabs('subclusters', array('id' => $parent)); } // Define columns $columns = array('name' => get_string('cluster_name', 'block_curr_admin'), 'display' => get_string('cluster_description', 'block_curr_admin')); $extrafilters = array('contexts' => clusterpage::get_contexts('block/curr_admin:cluster:view'), 'parent' => $parent, 'classification' => $classification); $items = cluster_get_listing($sort, $dir, $page * $perpage, $perpage, $namesearch, $alpha, $extrafilters); $numitems = cluster_count_records($namesearch, $alpha, $extrafilters); clusterpage::get_contexts('block/curr_admin:cluster:edit'); clusterpage::get_contexts('block/curr_admin:cluster:delete'); $this->print_list_view($items, $numitems, $columns, $filter = null, $alphaflag = true, $searchflag = true); if ($this->optional_param('id', 0, PARAM_INT)) { //get the non-parent clusters that are accessible based on the edit capability $contexts = clusterpage::get_contexts('block/curr_admin:cluster:edit'); $non_parent_clusters = cluster_get_possible_sub_clusters($this->optional_param('id', 0, PARAM_INT), $contexts); //display the dropdown if there are one or more available clusters if (count($non_parent_clusters) > 0) { echo '<div align="center">'; echo get_string('cluster_subcluster_prompt', 'block_curr_admin') . ': '; $url = $this->get_new_page(array('action' => 'subcluster', 'id' => $this->optional_param('id', 0, PARAM_INT)))->get_url() . '&subclusterid='; popup_form($url, $non_parent_clusters, 'assignsubcluster', '', 'Choose...'); echo '</div>'; } } }
/** * Display copy curriculum action. */ public function display_copycurredit() { global $CFG, $USER, $PAGE, $DB, $OUTPUT; $PAGE->requires->js('/local/elisprogram/js/clustercurriculumpage.js'); $id = $this->required_param('id', PARAM_INT); // Create a list of curricula to be excluded. $curriculumshown = array(); $table = new html_table(); $table->head = array(get_string('userset_cpyclustname', 'local_elisprogram'), get_string('userset_cpycurname', 'local_elisprogram'), get_string('userset_cpyadd', 'local_elisprogram'), get_string('userset_cpytrkcpy', 'local_elisprogram'), get_string('userset_cpycrscpy', 'local_elisprogram'), get_string('userset_cpyclscpy', 'local_elisprogram'), get_string('userset_cpymdlclscpy', 'local_elisprogram')); $table->class = 'cluster_copy_curriculum'; // Get all clusters. $sort = 'name'; $dir = 'ASC'; $clusters = cluster_get_listing($sort, $dir, 0); $clusterlist = array(); $sql = 'SELECT * from {' . userset::TABLE . '}'; // Exclude clusters the user does not have the capability to manage/see. $context = get_contexts_by_capability_for_user('cluster', 'local/elisprogram:userset_view', $USER->id); echo '<form action="index.php" method="post">'; $mdlcrsoptions = array('copyalways' => get_string('program_copy_mdlcrs_copyalways', 'local_elisprogram'), 'copyautocreated' => get_string('program_copy_mdlcrs_copyautocreated', 'local_elisprogram'), 'autocreatenew' => get_string('program_copy_mdlcrs_autocreatenew', 'local_elisprogram'), 'link' => get_string('program_copy_mdlcrs_link', 'local_elisprogram')); $contexts = curriculumpage::get_contexts('local/elisprogram:associate'); foreach ($clusters as $clusid => $clusdata) { if (!$context->context_allowed($clusid, 'cluster')) { continue; } $assocurr = clustercurriculum::get_curricula($clusid); if (!empty($assocurr)) { $first = true; foreach ($assocurr as $assocurrrec) { // Add to list of curricula to exclude. $curriculumshown[] = $assocurrrec->curriculumid; // Skip over this clusters associated curricula. if ($clusid == $id) { continue; } // Skip over curricula that user cannot associate. if (!$contexts->context_allowed($assocurrrec->curriculumid, 'curriculum')) { continue; } if ($first) { $curname = format_string($clusdata->name); $first = false; } else { $curname = ''; } // Disable the last 3 options unless the first is checked. $checkboxids = "'" . self::CPY_CURR_PREFIX . $assocurrrec->curriculumid . "',\n '" . self::CPY_CURR_TRK_PREFIX . $assocurrrec->curriculumid . "',\n '" . self::CPY_CURR_CRS_PREFIX . $assocurrrec->curriculumid . "',\n '" . self::CPY_CURR_CLS_PREFIX . $assocurrrec->curriculumid . "'"; $togglecheckboxes = "cluster_copy_checkbox_changed(" . $checkboxids . ");"; $table->data[] = array($curname, format_string($assocurrrec->name), html_writer::checkbox(self::CPY_CURR_PREFIX . $assocurrrec->curriculumid, 1, false, '', array('id' => self::CPY_CURR_PREFIX . $assocurrrec->curriculumid, 'onclick' => $togglecheckboxes)), html_writer::checkbox(self::CPY_CURR_TRK_PREFIX . $assocurrrec->curriculumid, 1, false, '', array('disabled' => true, 'id' => self::CPY_CURR_TRK_PREFIX . $assocurrrec->curriculumid)), html_writer::checkbox(self::CPY_CURR_CRS_PREFIX . $assocurrrec->curriculumid, 1, false, '', array('disabled' => true, 'id' => self::CPY_CURR_CRS_PREFIX . $assocurrrec->curriculumid)), html_writer::checkbox(self::CPY_CURR_CLS_PREFIX . $assocurrrec->curriculumid, 1, false, '', array('disabled' => true, 'id' => self::CPY_CURR_CLS_PREFIX . $assocurrrec->curriculumid)), html_writer::select($mdlcrsoptions, self::CPY_CURR_MDLCRS_PREFIX . $assocurrrec->curriculumid)); $table->rowclass[] = 'clus_cpy_row'; } } } // Add unassociated row to table. $table->data[] = array(get_string('usersetprogram_unassociated', 'local_elisprogram'), '', '', '', '', '', ''); $table->rowclass[] = 'clus_cpy_row unassigned'; // Get all curriculums, removing curricula that have already been listed. $curriculums = curriculum_get_listing($sort, $dir, 0, 0, '', '', $contexts); foreach ($curriculums as $curriculumid => $curriculumdata) { if (false === array_search($curriculumid, $curriculumshown)) { $checkboxids = "'" . self::CPY_CURR_PREFIX . $curriculumid . "',\n '" . self::CPY_CURR_TRK_PREFIX . $curriculumid . "',\n '" . self::CPY_CURR_CRS_PREFIX . $curriculumid . "',\n '" . self::CPY_CURR_CLS_PREFIX . $curriculumid . "'"; $togglecheckboxes = "cluster_copy_checkbox_changed(" . $checkboxids . ");"; $table->data[] = array('', format_string($curriculumdata->name), html_writer::checkbox(self::CPY_CURR_PREFIX . $curriculumid, 1, false, '', array('id' => self::CPY_CURR_PREFIX . $curriculumid, 'onclick' => $togglecheckboxes)), html_writer::checkbox(self::CPY_CURR_TRK_PREFIX . $curriculumid, 1, false, '', array('disabled' => true, 'id' => self::CPY_CURR_TRK_PREFIX . $curriculumid)), html_writer::checkbox(self::CPY_CURR_CRS_PREFIX . $curriculumid, 1, false, '', array('disabled' => true, 'id' => self::CPY_CURR_CRS_PREFIX . $curriculumid)), html_writer::checkbox(self::CPY_CURR_CLS_PREFIX . $curriculumid, 1, false, '', array('disabled' => true, 'id' => self::CPY_CURR_CLS_PREFIX . $curriculumid)), html_writer::select($mdlcrsoptions, self::CPY_CURR_MDLCRS_PREFIX . $curriculumid)); $table->rowclass[] = 'clus_cpy_row'; } } $currselectall = '<div class="currselectall">'; $currselectall .= '<a id="clus_currcpy_select_all" onclick="cluster_copycurriculum_set_all_selected()">'; $currselectall .= get_string('selectall') . '</a></div>'; $trkselectall = '<div class="trkselectall"><a id="clus_trkcpy_select_all" onclick="cluster_copytrack_set_all_selected()">'; $trkselectall .= get_string('selectall') . '</a></div>'; $crsselectall = '<div class="crsselectall"><a id="clus_crscpy_select_all" onclick="cluster_copycourse_set_all_selected()">'; $crsselectall .= get_string('selectall') . '</a></div>'; $clsselectall = '<div class="clsselectall"><a id="clus_crscpy_select_all" onclick="cluster_copyclass_set_all_selected()">'; $clsselectall .= get_string('selectall') . '</a></div>'; $table->data[] = array('', '', $currselectall, $trkselectall, $crsselectall, $clsselectall); $table->rowclass[] = 'clus_cpy_row select_all_row'; echo html_writer::table($table); echo '<div class="clus_curr_cpy_save_exit">'; echo '<input type="submit" name="save" value="' . get_string('userset_saveexit', 'local_elisprogram') . '">'; echo '<div class="hidden">'; echo '<input type="hidden" name="id" value="' . $id . '">'; echo '<input type="hidden" name="s" value="clstcur">'; echo '<input type="hidden" name="action" value="copycurr">'; echo '<input type="hidden" name="sesskey" value="' . $USER->sesskey . '">'; echo '</div>'; echo '</div>'; echo '</form>'; }