/** * Prints a deletion confirmation form. * @param $obj record whose deletion is being confirmed */ function print_delete_form($obj) { global $DB; if ($count = userset::count(new field_filter('parent', $obj->id))) { // cluster has sub-clusters, so ask the user if they want to // promote or delete the sub-clusters $a = new stdClass(); $a->name = $obj; $a->subclusters = $count; $context = \local_elisprogram\context\userset::instance($obj->id); $like = $DB->sql_like('path', '?'); $a->descendants = $DB->count_records_select('context', $DB->sql_like('path', '?'), array("{$context->path}/%")) - $a->subclusters; print_string($a->descendants ? 'confirm_delete_with_usersubsets_and_descendants' : 'confirm_delete_with_usersubsets', 'local_elisprogram', array('name' => $obj->name, 'subclusters' => $count)); $target = $this->get_new_page(array('action' => 'delete', 'confirm' => '1')); $form = new usersetdeleteform($target->url, array('obj' => $obj, 'a' => $a)); $form->display(); } else { parent::print_delete_form($obj); } }
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); }