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 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; }