/** * Dummy can_do method for viewing a curriculum report (needed for the * cluster tree parameter for reports) */ function can_do_viewreport() { global $CFG, $DB; $id = $this->required_param('id', PARAM_INT); //needed for execution mode constants require_once $CFG->dirroot . '/local/elisreports/php_report_base.php'; //check if we're scheduling or viewing $execution_mode = $this->optional_param('execution_mode', php_report::EXECUTION_MODE_SCHEDULED, PARAM_INT); //check the correct capability $capability = $execution_mode == php_report::EXECUTION_MODE_SCHEDULED ? 'local/elisreports:schedule' : 'local/elisreports:view'; if ($this->_has_capability($capability)) { return true; } /* * Start of cluster hierarchy extension */ $viewable_clusters = userset::get_viewable_clusters($capability); //if the user has no additional access through parent clusters, then they can't view this cluster if (empty($viewable_clusters)) { return false; } $parentpath = $DB->sql_concat('parent_context.path', "?"); $likeclause = $DB->sql_like('child_context.path', $parentpath); list($in_clause, $params) = $DB->get_in_or_equal($viewable_clusters); //determine if this cluster is the parent of some accessible child cluster $sql = "SELECT parent_context.instanceid\n FROM {context} parent_context\n JOIN {context} child_context\n ON child_context.instanceid {$in_clause}\n AND {$likeclause}\n AND parent_context.contextlevel = " . CONTEXT_ELIS_USERSET . "\n AND child_context.contextlevel = " . CONTEXT_ELIS_USERSET . "\n AND parent_context.instanceid = {$id}"; if (!isset($params) || !is_array($params)) { $params = array('/%'); } else { $params[] = '/%'; } return $DB->record_exists_sql($sql, $params); /* * End of cluster hierarchy extension */ }
function cluster_count_records($namesearch = '', $alpha = '', $extrafilters = array()) { global $DB; $filters = array(); if (!empty($namesearch)) { $namesearch = trim($namesearch); $filters[] = new field_filter('name', "%{$namesearch}%", field_filter::LIKE); } if ($alpha) { $filters[] = new field_filter('name', "{$alpha}%", field_filter::LIKE); } if (!empty($extrafilters['contexts'])) { /* * Start of cluster hierarchy extension */ $sql_condition = new select_filter('FALSE'); if (userset::all_clusters_viewable()) { //user has capability at system level so allow access to any cluster $sql_condition = new select_filter('TRUE'); } else { //user does not have capability at system level, so filter $viewable_clusters = userset::get_viewable_clusters(); if (empty($viewable_clusters)) { //user has no access to any clusters, so do not allow additional access $sql_condition = new select_filter('FALSE'); } else { //user has additional access to some set of clusters, so "enable" this access //use the context path to find parent clusters $path = $DB->sql_concat('parent_context.path', "'/%'"); list($IN, $inparams) = $DB->get_in_or_equal($viewable_clusters, SQL_PARAMS_NAMED); $sql_condition = new select_filter("id IN (SELECT parent_context.instanceid\n FROM {context} parent_context\n JOIN {context} child_context\n ON child_context.path LIKE {$path}\n AND parent_context.contextlevel = " . CONTEXT_ELIS_USERSET . "\n AND child_context.contextlevel = " . CONTEXT_ELIS_USERSET . "\n AND child_context.instanceid {$IN}\n )", $inparams); } } /* * End of cluster hierarchy extension */ $context_filter = $extrafilters['contexts']->get_filter('id', 'cluster'); //extend the basic context filter by potentially enabling access to parent clusters $filters[] = new OR_filter(array($context_filter, $sql_condition)); } if (isset($extrafilters['parent'])) { $filters[] = new field_filter('parent', $extrafilters['parent']); } if (isset($extrafilters['classification'])) { require_once elispm::file('plugins/usetclassify/lib.php'); $field = new field(field::get_for_context_level_with_name(CONTEXT_ELIS_USERSET, USERSET_CLASSIFICATION_FIELD)); $filters[] = new elis_field_filter($field, 'id', CONTEXT_ELIS_USERSET, $extrafilters['classification']); } return userset::count($filters); }