Esempio n. 1
0
 /**
  * Unassign the user from the program.
  * @param array $elements An array of elements to perform the action on.
  * @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;
     $pgmid = required_param('id', PARAM_INT);
     // Permissions.
     $cpage = new curriculumpage();
     if ($cpage->_has_capability('local/elisprogram:program_view', $pgmid) !== true) {
         return array('result' => 'fail', 'msg' => get_string('not_permitted', 'local_elisprogram'));
     }
     foreach ($elements as $userid => $label) {
         if ($this->can_unassign($pgmid, $userid) === true) {
             $assignrec = $DB->get_record(curriculumstudent::TABLE, array('userid' => $userid, 'curriculumid' => $pgmid));
             if (!empty($assignrec)) {
                 $curstu = new curriculumstudent($assignrec);
                 $curstu->delete();
             }
         }
     }
     return array('result' => 'success', 'msg' => 'Success');
 }
Esempio n. 2
0
 function curriculum_enrolment_delete($record, $filename, $idnumber)
 {
     global $DB, $CFG;
     if (!($curid = $DB->get_field(curriculum::TABLE, 'id', array('idnumber' => $idnumber)))) {
         $this->fslogger->log_failure("instance value of \"{$idnumber}\" does not refer to a valid instance of a program context.", 0, $filename, $this->linenumber, $record, "enrolment");
         return false;
     }
     if (!$this->validate_program_enrolment_data('delete', $record, $filename)) {
         return false;
     }
     $userid = $this->get_userid_from_record($record, $filename);
     $associd = $DB->get_field(curriculumstudent::TABLE, 'id', array('userid' => $userid, 'curriculumid' => $curid));
     $stucur = new curriculumstudent(array('id' => $associd));
     $stucur->delete();
     //string to describe the user
     $user_descriptor = $this->get_user_descriptor($record, false, 'user_');
     //log success
     $success_message = "User with {$user_descriptor} successfully unenrolled from program \"{$idnumber}\".";
     $this->fslogger->log_success($success_message, 0, $filename, $this->linenumber);
     return true;
 }
 /**
  * Performs program_enrolment deletion
  * @throws moodle_exception If there was an error in passed parameters.
  * @throws data_object_exception If there was an error deleting the association.
  * @param array $data The incoming data parameter.
  * @return array An array of parameters, if successful.
  */
 public static function program_enrolment_delete(array $data)
 {
     global $DB, $USER;
     if (static::require_elis_dependencies() !== true) {
         throw new moodle_exception('ws_function_requires_elis', 'local_datahub');
     }
     // Parameter validation.
     $params = self::validate_parameters(self::program_enrolment_delete_parameters(), array('data' => $data));
     // Context validation.
     $context = context_user::instance($USER->id);
     self::validate_context($context);
     $data = (object) $data;
     // Parse program
     if (empty($data->program_idnumber) || !($curid = $DB->get_field(curriculum::TABLE, 'id', array('idnumber' => $data->program_idnumber)))) {
         throw new data_object_exception('ws_program_enrolment_delete_fail_invalid_program', 'local_datahub', '', $data);
     }
     // Capability checking.
     require_capability('local/elisprogram:program_enrol', \local_elisprogram\context\program::instance($curid));
     // Initialize version1elis importplugin for utility functions.
     $importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis');
     $userparams = array();
     $userid = $importplugin->get_userid_from_record($data, '', $userparams);
     if ($userid == false) {
         $a = new stdClass();
         if (empty($userparams)) {
             $a->userparams = '{empty}';
         } else {
             $a->userparams = '';
             foreach ($userparams as $userfield => $uservalue) {
                 $subfield = strpos($userfield, '_');
                 $userfield = substr($userfield, $subfield === false ? 0 : $subfield + 1);
                 if (!empty($a->userparams)) {
                     $a->userparams .= ', ';
                 }
                 $a->userparams .= "{$userfield}: '{$uservalue}'";
             }
         }
         throw new data_object_exception('ws_program_enrolment_delete_fail_invalid_user', 'local_datahub', '', $a);
     }
     $id = $DB->get_field(curriculumstudent::TABLE, 'id', array('curriculumid' => $curid, 'userid' => $userid));
     // Respond.
     if (!empty($id) && ($stucur = new curriculumstudent($id))) {
         $stucur->delete();
         return array('messagecode' => get_string('ws_program_enrolment_delete_success_code', 'local_datahub'), 'message' => get_string('ws_program_enrolment_delete_success_msg', 'local_datahub'));
     } else {
         throw new data_object_exception('ws_program_enrolment_delete_fail', 'local_datahub');
     }
 }
 protected function process_unassignment($data)
 {
     global $CURMAN;
     $curid = $data->id;
     foreach ($data->_selection as $associd) {
         $curstu = new curriculumstudent($associd);
         if ($curstu->curriculumid == $curid) {
             // sanity check
             $curstu->delete();
         }
     }
     $tmppage = $this->get_basepage();
     redirect($tmppage->get_url(), get_string('num_users_unassigned', 'block_curr_admin', count($data->_selection)));
 }