예제 #1
0
 /**
  * Determine whether the current can manage the association between a given user and userset.
  * @param int $userid The ID of a user.
  * @param int $clustid The ID of a userset.
  * @return bool Success status.
  */
 public static function can_manage_assoc($userid, $usersetid)
 {
     global $USER;
     $allowedusersets = array();
     // TODO: Ugly, this needs to be overhauled.
     $upage = new usersetpage();
     if (!usersetpage::can_enrol_into_cluster($usersetid)) {
         // The users who satisfty this condition are a superset of those who can manage associations.
         return false;
     } else {
         if ($upage->_has_capability('local/elisprogram:userset_enrol', $usersetid)) {
             // Current user has the direct capability.
             return true;
         }
     }
     $allowedusersets = userset::get_allowed_clusters($usersetid);
     $filter = array(new field_filter('userid', $userid));
     // Query to get users associated to at least one enabling userset.
     if (empty($allowedusersets)) {
         $filter[] = new select_filter('FALSE');
     } else {
         $filter[] = new in_list_filter('clusterid', $allowedusersets);
     }
     // User just needs to be in one of the possible usersets.
     if (clusterassignment::exists($filter)) {
         return true;
     }
     return false;
 }
예제 #2
0
파일: lib.php 프로젝트: jamesmcq/elis
function cluster_manual_assign_user($clusterid, $userid, $autoenrol = true, $leader = false)
{
    global $CFG;
    if (!is_numeric($clusterid) || !is_numeric($userid) || $clusterid <= 0 || $userid <= 0) {
        return false;
    }
    if (clusterassignment::exists(array(new field_filter('userid', $userid), new field_filter('clusterid', $clusterid), new field_filter('plugin', 'manual')))) {
        return true;
    }
    $record = new clusterassignment();
    $record->clusterid = $clusterid;
    $record->userid = $userid;
    $record->plugin = 'manual';
    $record->autoenrol = $autoenrol;
    $record->leader = $leader;
    $record->save();
    return true;
}
예제 #3
0
파일: contexts.php 프로젝트: jamesmcq/elis
 function _user_allowed($id)
 {
     global $DB;
     if (isset($this->contexts['cluster']) && clusterassignment::exists(array(new field_filter('userid', $id), new in_list_filter('clusterid', $this->contexts['cluster'])))) {
         return true;
     }
     if (isset($this->contexts['cluster'])) {
         $filter = $this->get_filter('clusterid', 'cluster');
         return clusterassignment::count(array(new field_filter('userid', $id), $filter));
     }
     return false;
 }
예제 #4
0
function cluster_assign_to_user($clusterid, $userid, $autoenrol = true, $leader = false)
{
    if (!is_numeric($clusterid) || !is_numeric($userid) || $clusterid <= 0 || $userid <= 0) {
        // invalid data
        return false;
    }
    if (clusterassignment::exists(array(new field_filter('userid', $userid), new field_filter('clusterid', $clusterid)))) {
        // user already assigned
        return true;
    }
    $usass = new clusterassignment();
    $usass->userid = $userid;
    $usass->clusterid = $clusterid;
    $usass->save();
    events_trigger('cluster_assigned', $usass);
    return true;
}