/** * ELIS(TM): Enterprise Learning Intelligence Suite * Copyright (C) 2008-2012 Remote Learner.net Inc http://www.remote-learner.net * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * @package elis * @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 * */ function xmldb_crlm_cluster_classification_upgrade($oldversion = 0) { global $CFG, $THEME, $db; $result = true; if ($result && $oldversion < 2010080502) { /// Define table crlm_cluster_classification to be created $table = new XMLDBTable('crlm_cluster_classification'); /// Adding fields to table crlm_cluster_classification $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); $table->addFieldInfo('shortname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null); $table->addFieldInfo('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null); $table->addFieldInfo('params', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null); /// Adding keys to table crlm_cluster_classification $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id')); $table->addKeyInfo('shortname_idx', XMLDB_KEY_UNIQUE, array('shortname')); /// Launch create table for crlm_cluster_classification $result = $result && create_table($table); } if ($result && $oldversion < 2010080503) { require_once $CFG->dirroot . '/curriculum/lib/customfield.class.php'; require_once $CFG->dirroot . '/curriculum/plugins/cluster_classification/lib.php'; require_once $CFG->dirroot . '/curriculum/plugins/cluster_classification/clusterclassification.class.php'; $field = new field(field::get_for_context_level_with_name('cluster', CLUSTER_CLASSIFICATION_FIELD)); // make sure we're set as owner if (!isset($field->owners['cluster_classification'])) { $owner = new field_owner(); $owner->fieldid = $field->id; $owner->plugin = 'cluster_classification'; $owner->add(); } // make sure we have a default value set if (!field_data::get_for_context_and_field(NULL, $field)) { field_data::set_for_context_and_field(NULL, $field, 'regular'); } $default = new clusterclassification(); $default->shortname = 'regular'; $default->name = get_string('cluster', 'block_curr_admin'); $default->param_autoenrol_curricula = 1; $default->param_autoenrol_tracks = 1; $default->add(); } // make sure 'manual' is an owner if ($result && $oldversion < 2010080504) { require_once $CFG->dirroot . '/curriculum/lib/customfield.class.php'; require_once $CFG->dirroot . '/curriculum/plugins/cluster_classification/lib.php'; require_once $CFG->dirroot . '/curriculum/plugins/cluster_classification/clusterclassification.class.php'; $field = new field(field::get_for_context_level_with_name('cluster', CLUSTER_CLASSIFICATION_FIELD)); $owner = new field_owner(); $owner->fieldid = $field->id; $owner->plugin = 'manual'; $owner->param_view_capability = ''; $owner->param_edit_capability = 'moodle/user:update'; $owner->param_control = 'menu'; $owner->param_options_source = 'cluster_classifications'; $owner->add(); } return $result; }
function action_savenew() { $id = $this->required_param('id', PARAM_INT); $autounenrol = $this->optional_param('autounenrol', 1, PARAM_INT); $clusterid = $this->required_param('clusterid', PARAM_INT); $trackid = $this->required_param('trackid', PARAM_INT); require_once CURMAN_DIRLOCATION . '/form/' . $this->form_class . '.class.php'; require_once CURMAN_DIRLOCATION . '/plugins/cluster_classification/clusterclassification.class.php'; $target = $this->get_new_page(array('action' => 'savenew', 'id' => $id, 'clusterid' => $clusterid, 'trackid' => $trackid)); $form = new $this->form_class($target->get_moodle_url(), array('id' => $id, 'clusterid' => $clusterid, 'trackid' => $trackid)); $form->set_data(array('clusterid' => $clusterid, 'trackid' => $trackid)); if ($data = $form->get_data()) { if (!isset($data->cancel)) { clustertrack::associate($clusterid, $trackid, $autounenrol, $data->autoenrol); } $this->action_default(); } else { $cluster_classification = clusterclassification::get_for_cluster($clusterid); if (!empty($cluster_classification->param_autoenrol_tracks)) { $form->set_data(array('autoenrol' => 1)); } else { $form->set_data(array('autoenrol' => 0)); } $form->display(); } }
function cluster_classification_install() { global $CFG; require_once $CFG->dirroot . '/curriculum/config.php'; require_once CURMAN_DIRLOCATION . '/lib/customfield.class.php'; require_once CURMAN_DIRLOCATION . '/plugins/cluster_classification/clusterclassification.class.php'; $cluster_ctx_lvl = context_level_base::get_custom_context_level('cluster', 'block_curr_admin'); $field = new field(); $field->shortname = CLUSTER_CLASSIFICATION_FIELD; $field->name = get_string('classification_field_name', 'crlm_cluster_classification'); $field->datatype = 'char'; $category = new field_category(); $category->name = get_string('classification_category_name', 'crlm_cluster_classification'); $field = field::ensure_field_exists_for_context_level($field, 'cluster', $category); // make sure we're set as owner if (!isset($field->owners['cluster_classification'])) { $owner = new field_owner(); $owner->fieldid = $field->id; $owner->plugin = 'cluster_classification'; $owner->add(); } // make sure 'manual' is an owner if (!isset($field->owners['manual'])) { $owner = new field_owner(); $owner->fieldid = $field->id; $owner->plugin = 'manual'; $owner->param_view_capability = ''; $owner->param_edit_capability = 'moodle/user:update'; $owner->param_control = 'menu'; $owner->param_options_source = 'cluster_classifications'; $owner->add(); } // make sure we have a default value set if (!field_data::get_for_context_and_field(NULL, $field)) { field_data::set_for_context_and_field(NULL, $field, 'regular'); } $default = new clusterclassification(); $default->shortname = 'regular'; $default->name = get_string('cluster', 'block_curr_admin'); $default->param_autoenrol_curricula = 1; $default->param_autoenrol_tracks = 1; $default->add(); return true; }
function get_default_object_for_add() { $parent = $this->optional_param('parent', 0, PARAM_INT); if ($parent) { $obj = new stdClass(); $obj->parent = $parent; if ($parent) { require_once CURMAN_DIRLOCATION . '/plugins/cluster_classification/clusterclassification.class.php'; require_once CURMAN_DIRLOCATION . '/plugins/cluster_classification/lib.php'; if ($classification = clusterclassification::get_for_cluster($parent)) { $fieldname = 'field_' . CLUSTER_CLASSIFICATION_FIELD; if ($classification->param_child_classification) { $obj->{$fieldname} = $classification->param_child_classification; } else { $obj->{$fieldname} = $classification->shortname; } //default groups and groupings settings if ($classification->param_autoenrol_groups) { $obj->field_cluster_group = $classification->param_autoenrol_groups; } if ($classification->param_autoenrol_groupings) { $obj->field_cluster_groupings = $classification->param_autoenrol_groupings; } } } return $obj; } else { return NULL; } }
/** * Find a list of organization folders that the user has access to. * * @param $CFG * @param int $muserid The Moodle user id. * @param string $username The Moodle user name. * @param int $oid The organization id. * @return array Alfresco repository folder names. */ function find_organization_folders($muserid, $username) { global $CFG, $CURMAN, $USER; require_once $CFG->libdir . '/ddllib.php'; // Ensure that the cluster table actually exists before we query it. $table = new XMLDBTable('crlm_cluster'); if (!table_exists($table)) { return false; } if (!file_exists($CFG->dirroot . '/curriculum/plugins/cluster_classification/clusterclassification.class.php')) { return false; } require_once $CFG->dirroot . '/curriculum/plugins/cluster_classification/clusterclassification.class.php'; // Convert moodle userid to CM userid $cmuserid = cm_get_crlmuserid($muserid); $obj = new cm_context_set(); $timenow = time(); $contextlevelnum = context_level_base::get_custom_context_level('cluster', 'block_curr_admin'); $capability = "'block/repository:vieworganizationcontent'"; $like = sql_ilike(); $child_path = sql_concat('c_parent.path', "'/%'"); // Select clusters and sub-clusters for the current user // to which they have the vieworganization capability // TODO: Add this capability to the user when they are first assigned to a cluster $sql = "SELECT DISTINCT clst.id AS clusterid\n FROM {$CURMAN->db->prefix_table(CLSTTABLE)} clst\n WHERE EXISTS ( SELECT 'x'\n FROM {$CURMAN->db->prefix_table('context')} c\n JOIN {$CURMAN->db->prefix_table('context')} c_parent\n ON c.path {$like} {$child_path}\n OR c.path = c_parent.path\n JOIN {$CURMAN->db->prefix_table('role_assignments')} ra\n ON ra.contextid = c_parent.id\n AND ra.userid = {$muserid}\n AND (ra.timeend = 0 OR ra.timeend >= {$timenow})\n JOIN {$CURMAN->db->prefix_table('role_capabilities')} rc\n ON ra.roleid = rc.roleid\n WHERE c_parent.instanceid = clst.id\n AND c.contextlevel = {$contextlevelnum}\n AND c_parent.contextlevel = {$contextlevelnum}\n AND rc.capability = {$capability}\n )\n OR EXISTS ( SELECT 'x'\n FROM {$CURMAN->db->prefix_table(CLSTASSTABLE)} ca\n WHERE ca.clusterid = clst.id\n AND ca.userid = {$cmuserid})\n "; $viewable_clusters = $CURMAN->db->get_records_sql($sql); $cluster_info = array(); if ($viewable_clusters) { foreach ($viewable_clusters as $cluster) { if (!($new_cluster_info = $this->load_cluster_info($cluster->clusterid))) { continue; } else { $cluster_info[$cluster->clusterid] = $new_cluster_info; } } } else { return false; } if (empty($cluster_info)) { return false; } // There may be multiple clusters that this user is assigned to... $org_folders = array(); foreach ($cluster_info as $cluster) { // Get the extra cluster data and ensure it is present before proceeding. $clusterdata = clusterclassification::get_for_cluster($cluster); if (empty($clusterdata->params)) { continue; } $clusterparams = unserialize($clusterdata->params); // Make sure this cluster has the Alfresco shared folder property defined if (empty($clusterparams['alfresco_shared_folder'])) { continue; } // Make sure we can get the storage space from Alfresco for this organization. if (!($uuid = $this->get_organization_store($cluster->id))) { continue; } $org_folders[$cluster->name] = array('uuid' => $uuid, 'id' => $cluster->id); } return $org_folders; }
/** * Handle the event when a user is assigned to a cluster. * * @uses $CFG * @param object $clusterinfo The Moodle role_assignment record object. * @return bool True on success or failure (event handlers must always return true). */ function block_repository_cluster_assigned($clusterinfo) { global $CFG; // Only proceed here if the Alfresco plug-in is actually enabled. if (!isset($CFG->repository_plugins_enabled) || strstr($CFG->repository_plugins_enabled, 'alfresco') === false || !($repo = repository_factory::factory('alfresco'))) { return true; } // Get the Moodle user ID from the CM user ID. if (!($muserid = cm_get_moodleuserid($clusterinfo->userid))) { return true; } if (!($username = get_field('user', 'username', 'id', $muserid))) { return true; } if (!($cluster = get_record('crlm_cluster', 'id', $clusterinfo->clusterid))) { return true; } if (!file_exists($CFG->dirroot . '/curriculum/plugins/cluster_classification/clusterclassification.class.php')) { return true; } require_once $CFG->dirroot . '/curriculum/plugins/cluster_classification/clusterclassification.class.php'; // Get the extra cluster data and ensure it is present before proceeding. $clusterdata = clusterclassification::get_for_cluster($cluster); if (empty($clusterdata->params)) { return true; } $clusterparams = unserialize($clusterdata->params); // Make sure this cluster has the Alfresco shared folder property defined if (empty($clusterparams['alfresco_shared_folder'])) { return true; } // Make sure we can get the storage space from Alfresco for this organization. if (!($uuid = $repo->get_organization_store($cluster->id))) { return true; } $context = get_context_instance(context_level_base::get_custom_context_level('cluster', 'block_curr_admin'), $cluster->id); $sql = "SELECT rc.*\n FROM {$CFG->prefix}role_capabilities rc\n INNER JOIN {$CFG->prefix}role r ON r.id = rc.roleid\n INNER JOIN {$CFG->prefix}role_assignments ra ON ra.roleid = r.id\n WHERE ra.contextid = {$context->id}\n AND ra.userid = {$muserid}\n AND rc.capability = 'block/repository:createorganizationcontent'\n AND rc.permission = " . CAP_ALLOW; // Check if the user has the the editing capability for the Alfresco organization shared // storage space assigned at this cluster context level or is designated as a cluster leader in order to // enable editing permission on the Alfresco space. if (record_exists('crlm_usercluster', 'userid', $clusterinfo->userid, 'clusterid', $cluster->id, 'leader', 1) || record_exists_sql($sql)) { // Ensure that this user already has an Alfresco account. if (!$repo->alfresco_userdir($username)) { if (!$repo->migrate_user($username)) { return true; } } if (!alfresco_has_permission($uuid, $username, true)) { alfresco_set_permission($username, $uuid, ALFRESCO_ROLE_COLLABORATOR, ALFRESCO_CAPABILITY_ALLOWED); } // Double-check tjhat the user is designated as a cluster member (we should not be here otherwise) in order to // enable viewinging permission on the Alfresco space. } else { if (record_exists('crlm_usercluster', 'userid', $clusterinfo->userid, 'clusterid', $cluster->id, 'leader', 0)) { // Ensure that this user already has an Alfresco account. if (!$repo->alfresco_userdir($username)) { if (!$repo->migrate_user($username)) { return true; } } if (!alfresco_has_permission($uuid, $username, false)) { alfresco_set_permission($username, $uuid, ALFRESCO_ROLE_CONSUMER, ALFRESCO_CAPABILITY_ALLOWED); } } } return true; }
function action_default() { global $CURMAN; $sort = optional_param('sort', 'name', PARAM_ALPHA); $dir = optional_param('dir', 'ASC', PARAM_ALPHA); $namesearch = trim(optional_param('search', '', PARAM_TEXT)); $alpha = optional_param('alpha', '', PARAM_ALPHA); $page = optional_param('page', 0, PARAM_INT); $perpage = optional_param('perpage', 30, PARAM_INT); $clusterclass = new clusterclassification(); $columns = array('shortname' => get_string('shortname', 'crlm_cluster_classification'), 'name' => get_string('name', 'crlm_cluster_classification')); $records = $clusterclass->cluster_classification_listing($namesearch, $alpha, $page * $perpage, $perpage, $sort, $dir); $count = $CURMAN->db->count_records(CLUSTERCLASSTABLE); // total record count if (!empty($alpha) || !empty($namesearch)) { $count = $clusterclass->get_record_count(); // retrieve total count for search result } $this->print_list_view($records, $count, $columns, $filter = null, $alphaflag = true, $searchflag = true); }