Example #1
0
 /**
  * Determines whether the current user is allowed to create, edit, and delete associations
  * between a user and a class
  *
  * @param    int      $userid    The id of the user being associated to the class
  * @param    int      $classid   The id of the class we are associating the user to
  * @uses     $DB
  * @uses     $USER;
  * @return   boolean             True if the current user has the required permissions, otherwise false
  */
 public static function can_manage_assoc($userid, $classid)
 {
     global $DB, $USER;
     // TODO: Ugly, this needs to be overhauled
     $cpage = new pmclasspage();
     if (!pmclasspage::can_enrol_into_class($classid)) {
         //the users who satisfty this condition are a superset of those who can manage associations
         return false;
     } else {
         if ($cpage->_has_capability('local/elisprogram:class_enrol', $classid)) {
             //current user has the direct capability
             return true;
         }
     }
     //get the context for the "indirect" capability
     $context = pm_context_set::for_user_with_capability('cluster', 'local/elisprogram:class_enrol_userset_user', $USER->id);
     $allowed_clusters = array();
     $allowed_clusters = pmclass::get_allowed_clusters($classid);
     //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 = ? AND {$cluster_select}";
     //user just needs to be in one of the possible clusters
     if ($DB->record_exists_select(clusterassignment::TABLE, $select, array($userid))) {
         return true;
     }
     return false;
 }
Example #2
0
 /**
  * Determine whether the current user can enrol students into the class.
  *
  * @return bool Whether the user can enrol users into the class or not.
  */
 public function can_do_add()
 {
     $id = $this->required_param('id');
     return pmclasspage::can_enrol_into_class($id);
 }