예제 #1
0
 /**
  * Unassign the users from the track.
  *
  * @param array $elements An array of user informatio to unassign from the track.
  * @param bool $bulkaction Whether this is a bulk-action or not.
  * @return array An array to format as JSON and return to the Javascript.
  */
 protected function _respond_to_js(array $elements, $bulkaction)
 {
     global $DB;
     $trackid = required_param('id', PARAM_INT);
     // Permissions.
     $tpage = new trackpage();
     if ($tpage->_has_capability('local/elisprogram:track_view', $trackid) !== true) {
         return array('result' => 'fail', 'msg' => get_string('not_permitted', 'local_elisprogram'));
     }
     foreach ($elements as $userid => $label) {
         if ($this->can_unassign($trackid, $userid) === true) {
             $assignrec = $DB->get_record(usertrack::TABLE, array('userid' => $userid, 'trackid' => $trackid));
             $usertrack = new usertrack($assignrec);
             $usertrack->delete();
         }
     }
     return array('result' => 'success', 'msg' => 'Success');
 }
예제 #2
0
 /**
  * Unassign the tracks from the user.
  * @param array $elements An array containing information on tracks to unassign from the user.
  * @param bool $bulkaction Whether this is a bulk-action or not.
  * @return array An array to format as JSON and return to the Javascript.
  */
 protected function _respond_to_js(array $elements, $bulkaction)
 {
     global $DB;
     $userid = required_param('id', PARAM_INT);
     foreach ($elements as $trackid => $label) {
         if ($this->can_unassign($userid, $trackid) === true) {
             $assignrec = $DB->get_record(usertrack::TABLE, array('userid' => $userid, 'trackid' => $trackid));
             $usertrack = new usertrack($assignrec);
             $usertrack->delete();
         }
     }
     return array('result' => 'success', 'msg' => 'Success');
 }
예제 #3
0
 /**
  * Delete a track enrolment
  *
  * @param object $record One record of import data
  * @param string $filename The import file name, used for logging
  * @param string $idnumber The idnumber of the track
  *
  * @return boolean true on success, otherwise false
  */
 function track_enrolment_delete($record, $filename, $idnumber)
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/local/elisprogram/lib/setup.php';
     require_once elispm::lib('data/track.class.php');
     require_once elispm::lib('data/usertrack.class.php');
     if (!($trackid = $DB->get_field(track::TABLE, 'id', array('idnumber' => $idnumber)))) {
         $this->fslogger->log_failure("instance value of \"{$idnumber}\" does not refer to a valid instance of a track context.", 0, $filename, $this->linenumber, $record, "enrolment");
         return false;
     }
     $userid = $this->get_userid_from_record($record, $filename);
     //string to describe the user
     $user_descriptor = $this->get_user_descriptor($record, false, 'user_');
     if (!$DB->record_exists(usertrack::TABLE, array('trackid' => $trackid, 'userid' => $userid))) {
         $this->fslogger->log_failure("User with {$user_descriptor} is not enrolled in track \"{$idnumber}\".", 0, $filename, $this->linenumber, $record, "enrolment");
         return false;
     }
     if (!$this->validate_track_enrolment_data('delete', $record, $filename)) {
         return false;
     }
     //obtain the track id
     $trackid = $DB->get_field(track::TABLE, 'id', array('idnumber' => $idnumber));
     //delete the association
     $usertrackid = $DB->get_field(usertrack::TABLE, 'id', array('userid' => $userid, 'trackid' => $trackid));
     $usertrack = new usertrack($usertrackid);
     $usertrack->delete();
     //log success
     $success_message = "User with {$user_descriptor} successfully unenrolled from track \"{$idnumber}\".";
     $this->fslogger->log_success($success_message, 0, $filename, $this->linenumber);
     return true;
 }