Ejemplo n.º 1
0
 /**
  * Determines whether the current user is allowed to create, edit, and delete associations
  * between a user and a cluster
  * 
  * @param    int      $userid    The id of the user being associated to the cluster
  * @param    int      $clustid   The id of the cluster we are associating the user to
  * 
  * @return   boolean             True if the current user has the required permissions, otherwise false
  */
 public static function can_manage_assoc($userid, $clustid)
 {
     global $USER;
     $allowed_clusters = array();
     if (!clusterpage::can_enrol_into_cluster($clustid)) {
         //the users who satisfty this condition are a superset of those who can manage associations
         return false;
     } else {
         if (clusterpage::_has_capability('block/curr_admin:cluster:enrol', $clustid)) {
             //current user has the direct capability
             return true;
         }
     }
     $allowed_clusters = cluster::get_allowed_clusters($clustid);
     //query to get users associated to at least one enabling cluster
     $cluster_select = '';
     if (empty($allowed_clusters)) {
         $cluster_select = '0=1';
     } else {
         $cluster_select = 'clusterid IN (' . implode(',', $allowed_clusters) . ')';
     }
     $select = "userid = {$userid} AND {$cluster_select}";
     //user just needs to be in one of the possible clusters
     if (record_exists_select(CLSTUSERTABLE, $select)) {
         return true;
     }
     return false;
 }
Ejemplo n.º 2
0
 function can_do_default()
 {
     $id = $this->required_param('id', PARAM_INT);
     return clusterpage::can_enrol_into_cluster($id);
 }