Ejemplo n.º 1
0
 /**
  *
  */
 function action_updatemultiple()
 {
     global $CURMAN;
     $clsid = $this->required_param('id', PARAM_INT);
     $users = $this->optional_param('users', array());
     foreach ($users as $uid => $user) {
         $sturecord = array();
         $sturecord['id'] = $user['association_id'];
         $sturecord['classid'] = $clsid;
         $sturecord['userid'] = $uid;
         $startyear = $user['startyear'];
         $startmonth = $user['startmonth'];
         $startday = $user['startday'];
         $sturecord['enrolmenttime'] = mktime(0, 0, 0, $startmonth, $startday, $startyear);
         $endyear = $user['endyear'];
         $endmonth = $user['endmonth'];
         $endday = $user['endday'];
         $sturecord['completetime'] = mktime(0, 0, 0, $endmonth, $endday, $endyear);
         $sturecord['completestatusid'] = $user['completestatusid'];
         $sturecord['grade'] = $user['grade'];
         $sturecord['credits'] = $user['credits'];
         $sturecord['locked'] = !empty($user['locked']) ? 1 : 0;
         $stu = new student($sturecord);
         if ($stu->completestatusid == STUSTATUS_PASSED && $CURMAN->db->get_field(STUTABLE, 'completestatusid', 'id', $stu->id) != STUSTATUS_PASSED) {
             $stu->complete();
         } else {
             if (($status = $stu->update()) !== true) {
                 echo cm_error('Record not updated.  Reason: ' . $status->message);
             }
         }
         // Now once we've done all this, delete the student if we've been asked to
         if (isset($user['unenrol']) && cmclasspage::can_enrol_into_class($clsid)) {
             $stu_delete = new student($user['association_id']);
             if (!$stu_delete->delete()) {
                 echo cm_error('Student "name: ' . cm_fullname($stu->user) . '" not unenrolled.');
             }
         }
     }
     $this->action_default();
 }
Ejemplo n.º 2
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
  *
  * @return   boolean             True if the current user has the required permissions, otherwise false
  */
 public static function can_manage_assoc($userid, $classid)
 {
     global $USER;
     if (!cmclasspage::can_enrol_into_class($classid)) {
         //the users who satisfty this condition are a superset of those who can manage associations
         return false;
     } else {
         if (cmclasspage::_has_capability('block/curr_admin:track:enrol', $classid)) {
             //current user has the direct capability
             return true;
         }
     }
     //get the context for the "indirect" capability
     $context = cm_context_set::for_user_with_capability('cluster', 'block/curr_admin:class:enrol_cluster_user', $USER->id);
     $allowed_clusters = array();
     $allowed_clusters = cmclass::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 = {$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;
 }