. /** * Auxiliary manual user enrolment lib, the main purpose is to lower memory requirements... * * @package enrol * @subpackage manual * @copyright 2010 Petr Skoda {@link http://skodak.org} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); require_once($CFG->dirroot . '/user/selector/lib.php'); /** * Enrol candidates */ class enrol_apply_potential_participant extends user_selector_base { protected $enrolid; public function __construct($name, $options) { $this->enrolid = $options['enrolid']; parent::__construct($name, $options); } /** * Candidate users * @param $search * @return array */ public function find_users($search) { global $DB; //by default wherecondition retrieves all users except the deleted, not confirmed and guest list($wherecondition, $params) = $this->search_sql($search, 'u'); $params['enrolid'] = $this->enrolid; $fields = 'SELECT ' . $this->required_fields_sql('u'); $countfields = 'SELECT COUNT(1)'; $sql = " FROM {user} u WHERE $wherecondition AND u.id NOT IN (SELECT ue.userid FROM {user_enrolments} ue JOIN {enrol} e ON (e.id = ue.enrolid AND e.id = :enrolid))"; $order = ' ORDER BY u.lastname ASC, u.firstname ASC'; if (!$this->is_validating()) { $potentialmemberscount = $DB->count_records_sql($countfields . $sql, $params); if ($potentialmemberscount > 100) { return $this->too_many_results($search, $potentialmemberscount); } } $availableusers = $DB->get_records_sql($fields . $sql . $order, $params); if (empty($availableusers)) { return array(); } if ($search) { $groupname = get_string('enrolcandidatesmatching', 'enrol', $search); } else { $groupname = get_string('enrolcandidates', 'enrol'); } return array($groupname => $availableusers); } protected function get_options() { $options = parent::get_options(); $options['enrolid'] = $this->enrolid; $options['file'] = 'enrol/apply/selectlib.php'; return $options; } } /** * Enroled users */ class enrol_apply_current_participant extends user_selector_base { protected $courseid; protected $enrolid; public function __construct($name, $options) { $this->enrolid = $options['enrolid']; parent::__construct($name, $options); } /** * Candidate users * @param $search * @return array */ public function find_users($search) { global $DB; //by default wherecondition retrieves all users except the deleted, not confirmed and guest list($wherecondition, $params) = $this->search_sql($search, 'u'); $params['enrolid'] = $this->enrolid; $fields = 'SELECT ' . $this->required_fields_sql('u'); $countfields = 'SELECT COUNT(1)'; $sql = " FROM {user} u JOIN {user_enrolments} ue ON (ue.userid = u.id AND ue.enrolid = :enrolid) WHERE $wherecondition"; $order = ' ORDER BY u.lastname ASC, u.firstname ASC'; if (!$this->is_validating()) { $potentialmemberscount = $DB->count_records_sql($countfields . $sql, $params); if ($potentialmemberscount > 100) { return $this->too_many_results($search, $potentialmemberscount); } } $availableusers = $DB->get_records_sql($fields . $sql . $order, $params); if (empty($availableusers)) { return array(); } if ($search) { $groupname = get_string('enrolledusersmatching', 'enrol', $search); } else { $groupname = get_string('enrolledusers', 'enrol'); } return array($groupname => $availableusers); } protected function get_options() { $options = parent::get_options(); $options['enrolid'] = $this->enrolid; $options['file'] = 'enrol/apply/apply_form.php'; return $options; } }