/** * Determines whether the current user is allowed to enrol users into the provided curriculum * * @param int $curriculumid The id of the curriculum we are checking permissions on * * @return boolean Whether the user is allowed to enrol users into the curriculum * */ static function can_enrol_into_curriculum($curriculumid) { global $USER; //check the standard capability if (curriculumpage::_has_capability('block/curr_admin:curriculum:enrol', $curriculumid)) { return true; } //get the context for the "indirect" capability $context = cm_context_set::for_user_with_capability('cluster', 'block/curr_admin:curriculum:enrol_cluster_user', $USER->id); //get the clusters and check the context against them $clusters = clustercurriculum::get_clusters($curriculumid); if (!empty($clusters)) { foreach ($clusters as $cluster) { if ($context->context_allowed($cluster->clusterid, 'cluster')) { return true; } } } return false; }
/** * Determines whether the current user is allowed to enrol users into the provided curriculum * * @param int $curriculumid The id of the curriculum we are checking permissions on * * @return boolean Whether the user is allowed to enrol users into the curriculum * */ static function can_enrol_into_curriculum($curriculumid) { global $USER; //check the standard capability // TODO: Ugly, this needs to be overhauled $cpage = new curriculumpage(); if ($cpage->_has_capability('local/elisprogram:program_enrol', $curriculumid)) { return true; } //get the context for the "indirect" capability $context = pm_context_set::for_user_with_capability('cluster', 'local/elisprogram:program_enrol_userset_user', $USER->id); //get the clusters and check the context against them $clusters = clustercurriculum::get_clusters($curriculumid); if (!empty($clusters)) { foreach ($clusters as $cluster) { if ($context->context_allowed($cluster->clusterid, 'cluster')) { return true; } } } return false; }
/** * Dynamically loads child menu items for a curriculum 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_curriculum($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(); /***************************************** * Curriculum - Course Associations *****************************************/ $course_css_class = block_elisadmin_get_item_css_class('course_instance'); //permissions filter $course_filter = array('contexts' => coursepage::get_contexts('local/elisprogram:course_view')); $listing = curriculumcourse_get_listing($id, 'position', 'ASC', 0, $num_block_icons, '', '', $course_filter); foreach ($listing as $item) { $item->id = $item->courseid; $params = array('id' => $item->id, 'action' => 'view'); //count associated classes $class_contexts = pmclasspage::get_contexts('local/elisprogram:class_view'); $class_count = pmclass_count_records('', '', $item->id, false, $class_contexts, $parent_cluster_id); $isLeaf = empty($class_count); $result_items[] = block_elisadmin_get_menu_item('course', $item, 'root', $course_css_class, $parent_cluster_id, $parent_curriculum_id, $params, $isLeaf, $parent_path); } unset($listing); //summary item $num_records = curriculumcourse_count_records($id, '', '', $course_filter); if ($num_block_icons < $num_records) { $params = array('id' => $id); $result_items[] = block_elisadmin_get_menu_summary_item('curriculumcourse', $course_css_class, $num_records - $num_block_icons, $params, '', $parent_path); } /***************************************** * Curriculum - Track Associations *****************************************/ $track_css_class = block_elisadmin_get_item_css_class('track_instance'); //permissions filter $track_contexts = trackpage::get_contexts('local/elisprogram:track_view'); if ($track_records = track_get_listing('name', 'ASC', 0, $num_block_icons, '', '', $id, $parent_cluster_id, $track_contexts)) { foreach ($track_records as $track_record) { $params = array('id' => $track_record->id, 'action' => 'view'); //count associated classes $class_contexts = array('contexts' => pmclasspage::get_contexts('local/elisprogram:class_view')); $class_count = track_assignment_count_records($track_record->id, '', '', $class_contexts); //count associated clusters $cluster_filter = array('contexts' => usersetpage::get_contexts('local/elisprogram:userset_view')); $cluster_count = clustertrack::count_clusters($track_record->id, $parent_cluster_id, $cluster_filter); $isLeaf = empty($class_count) && empty($cluster_count); $result_items[] = block_elisadmin_get_menu_item('track', $track_record, 'root', $track_css_class, $parent_cluster_id, $parent_curriculum_id, $params, $isLeaf, $parent_path); } } //summary item $num_records = track_count_records('', '', $id, $parent_cluster_id, $track_contexts); 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('track', $track_css_class, $num_records - $num_block_icons, $params, '', $parent_path); } /***************************************** * Curriculum - 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 = clustercurriculum::get_clusters($id, $parent_cluster_id, 'name', 'ASC', 0, $num_block_icons, $cluster_filter); //$clusters = clustercurriculum::get_clusters($id, $parent_cluster_id, 'priority, name', 'ASC', 0, $num_block_icons); 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('userset', $cluster, 'root', $cluster_css_class, $cluster->id, $parent_curriculum_id, $params, false, $parent_path); } } //summary item $num_records = clustercurriculum::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('curriculumcluster', $cluster_css_class, $num_records - $num_block_icons, $params, 'clustercurriculumpage.class.php', $parent_path); } return $result_items; }
function action_default() { $id = $this->required_param('id', PARAM_INT); $sort = $this->optional_param('sort', 'name', PARAM_CLEAN); $dir = $this->optional_param('dir', 'ASC', PARAM_CLEAN); //this extra parameter signals a dependency on a parent cluster $parent_clusterid = $this->optional_param('parent_clusterid', 0, PARAM_INT); $columns = array('name' => 'Name', 'display' => 'Display', 'autoenrol' => get_string('auto_enrol', 'block_curr_admin'), 'buttons' => ''); $items = clustercurriculum::get_clusters($id, $parent_clusterid, $sort, $dir); $formatters = $this->create_link_formatters(array('name'), 'clusterpage', 'clusterid'); $this->print_list_view($items, $columns, $formatters, 'clusters'); $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, 'curriculumid', 'clusterid'); } }
/** * Determines whether the current user is allowed to create, edit, and delete associations * between a user and a curriculum * * @param int $userid The id of the user being associated to the curricula * @param int $curid The id of the curricula we are associating the user to * * @return boolean True if the current user has the required permissions, otherwise false */ public static function can_manage_assoc($userid, $curid) { global $USER; if (!curriculumpage::can_enrol_into_curriculum($curid)) { //the users who satisfty this condition are a superset of those who can manage associations return false; } else { if (curriculumpage::_has_capability('block/curr_admin:curriculum:enrol', $curid)) { //current user has the direct capability return true; } } //get the context for the "indirect" capability $context = cm_context_set::for_user_with_capability('cluster', 'block/curr_admin:curriculum:enrol_cluster_user', $USER->id); $allowed_clusters = array(); //get the clusters and check the context against them $clusters = clustercurriculum::get_clusters($curid); $allowed_clusters = $context->get_allowed_instances($clusters, 'cluster', 'id'); //query to get users associated to at least one enabling cluster $cluster_select = ''; if (empty($allowed_clusters)) { $cluster_select = '0=1'; } else { $cluster_select = 'clusterid IN (' . implode(',', $allowed_clusters) . ')'; } $select = "userid = {$userid} AND {$cluster_select}"; //user just needs to be in one of the possible clusters if (record_exists_select(CLSTUSERTABLE, $select)) { return true; } return false; }
/** * Determines whether the current user is allowed to create, edit, and delete associations * between a user and a curriculum * * @param int $userid The id of the user being associated to the curricula * @param int $curid The id of the curricula we are associating the user to * * @return boolean True if the current user has the required permissions, otherwise false */ public static function can_manage_assoc($userid, $curid) { global $USER, $DB; // TODO: Ugly, this needs to be overhauled $cpage = new curriculumpage(); if (!curriculumpage::can_enrol_into_curriculum($curid)) { //the users who satisfty this condition are a superset of those who can manage associations return false; } else { if ($cpage->_has_capability('local/elisprogram:program_enrol', $curid)) { //current user has the direct capability return true; } } //get the context for the "indirect" capability $context = pm_context_set::for_user_with_capability('cluster', 'local/elisprogram:program_enrol_userset_user', $USER->id); $allowedclusters = array(); // Get the clusters and check the context against them. $clusters = clustercurriculum::get_clusters($curid); $allowedclusters = $context->get_allowed_instances($clusters, 'cluster', 'clusterid'); // Query to get users associated to at least one enabling cluster. $clusterselect = ''; if (empty($allowedclusters)) { $clusterselect = '0=1'; } else { $clusterselect = 'clusterid IN (' . implode(',', $allowedclusters) . ')'; } $select = "userid = {$userid} AND {$clusterselect}"; //user just needs to be in one of the possible clusters if ($DB->record_exists_select(clusterassignment::TABLE, $select)) { return true; } return false; }
function __construct(&$items, $columns, $pageurl, $decorators = array()) { global $CURMAN, $USER; parent::__construct($items, $columns, $pageurl, $decorators); $id = required_param('id', PARAM_INT); if (!curriculumpage::_has_capability('block/curr_admin:curriculum:enrol', $id)) { $context = cm_context_set::for_user_with_capability('cluster', 'block/curr_admin:curriculum:enrol_cluster_user', $USER->id); $allowed_clusters = array(); //get the clusters assigned to this curriculum $clusters = clustercurriculum::get_clusters($id); if (!empty($clusters)) { foreach ($clusters as $cluster) { if ($context->context_allowed($cluster->clusterid, 'cluster')) { $allowed_clusters[] = $cluster->id; } } } $this->allowed_clusters = $allowed_clusters; } }