/** * Main action to display contacts */ function index_action($filter = null) { // Check if we need to add contacts $mps = MultiPersonSearch::load('contacts'); $imported = 0; foreach ($mps->getAddedUsers() as $userId) { $user_to_add = User::find($userId); if ($user_to_add) { $new_contact = array('owner_id' => User::findCurrent()->id, 'user_id' => $user_to_add->id); if ($filter && $this->group) { $new_contact['group_assignments'][] = array('statusgruppe_id' => $this->group->id, 'user_id' => $user_to_add->id); } $imported += (bool) Contact::import($new_contact)->store(); } } if ($imported) { PageLayout::postMessage(MessageBox::success(sprintf(_("%s Kontakte wurden hinzugefügt."), $imported))); } $mps->clearSession(); // write filter to local $this->filter = $filter; // Deal with navigation Navigation::activateItem('community/contacts'); // Edit CSS for quicknavigation PageLayout::addStyle('div.letterlist span {color: #c3c8cc;}'); if ($filter) { $selected = $this->group; $contacts = SimpleCollection::createFromArray(User::findMany($selected->members->pluck('user_id'))); } else { $contacts = User::findCurrent()->contacts; } $this->allContacts = $contacts; // Retrive first letter and store in that contactgroup $this->contacts = array(); foreach ($contacts as $contact) { $this->contacts[strtoupper(SimpleCollection::translitLatin1($contact->nachname[0]))][] = $contact; } // Humans are a lot better with sorted results ksort($this->contacts); $this->contacts = array_map(function ($g) { return SimpleCollection::createFromArray($g)->orderBy('nachname, vorname'); }, $this->contacts); // Init sidebar $this->initSidebar($filter); // Init person search $mps = MultiPersonSearch::get('contacts')->setTitle(_('Kontakte hinzufügen'))->setDefaultSelectedUser($this->allContacts->pluck('user_id'))->setExecuteURL($this->url_for('contact/index/' . $filter))->setSearchObject(new StandardSearch('user_id')); // Set default title $this->title = _('Alle Kontakte'); // If we have a group if ($selected) { // Set title of Table $this->title = $selected->name; // Set title of multipersonsearch $mps->setTitle(sprintf(_('Kontakte zu %s hinzufügen'), $selected->name)); $mps->addQuickfilter(_('Kontakte'), User::findCurrent()->contacts->pluck('user_id')); } // Render multiperson search $this->multiPerson = $mps->render(); }
public function getUsers() { if ($this->anonymous) { return $this->anonymous_users; } $result = array(); foreach ($this->answers as $answer) { foreach ($answer->users as $user) { $result[$user->user_id] = $user; } } return SimpleCollection::createFromArray(array_values($result)); }
public function testConstruct() { $data[] = array('id' => 1, 'vorname' => 'Ândré', 'nachname' => 'Noack', 'perm' => 'dozent'); $data[] = array('id' => 2, 'vorname' => 'Stefan', 'nachname' => 'Suchi', 'perm' => 'dozent'); $data[] = array('id' => 10, 'vorname' => 'Élmar', 'nachname' => 'Ludwig', 'perm' => 'admin'); $data[] = array('id' => 11, 'vorname' => 'Jan-Hendrik', 'nachname' => 'Wilms', 'perm' => 'tutor'); $data[] = array('id' => 15, 'vorname' => 'Nico', 'nachname' => 'Müller', 'perm' => 'root'); $a = new SimpleCollection(); $this->assertInstanceOf('SimpleCollection', $a); $a = SimpleCollection::createFromArray($data); $this->assertInstanceOf('SimpleCollection', $a); $this->assertInstanceOf('ArrayAccess', $a[0]); $this->assertEquals($data[0]['id'], $a[0]['id']); $this->assertEquals($a->toArray(), $data); $finder = function () use($data) { return $data; }; $a = new SimpleCollection($finder); $this->assertInstanceOf('ArrayAccess', $a[0]); $this->assertEquals($data[0]['id'], $a[0]['id']); $this->assertEquals($a->toArray(), $data); return $a; }
/** * * @param type $user_id * @return type */ public static function GetCoursesActivatedCalendar($user_id) { $courses_user = SimpleCollection::createFromArray(CourseMember::findByUser($user_id)); $modules = new Modules(); $courses = $courses_user->filter(function ($c) use($modules) { if ($modules->isBit($c->course->modules, $modules->registered_modules['calendar']['id'])) { return $c; } }); return $courses->pluck('course'); }
public function getMemberData($member) { $datafields = SimpleCollection::createFromArray(DatafieldEntryModel::findByModel($member)); foreach ($this->datafields as $field => $useless_value_pls_refactor) { // since we have no only datafields we have to filter! if ($new = $datafields->findOneBy('datafield_id', $field)) { $result[] = $new; } } return $result; }
/** * Returns the teacher for a given cours * * @param String $course_id Id of the course * @return array of user infos [user_id, username, Nachname, fullname] */ private function getTeacher($course_id) { $teachers = CourseMember::findByCourseAndStatus($course_id, 'dozent'); $collection = SimpleCollection::createFromArray($teachers); return $collection->map(function (CourseMember $teacher) { return array('user_id' => $teacher->user_id, 'username' => $teacher->username, 'Nachname' => $teacher->nachname, 'fullname' => $teacher->getUserFullname('no_title_rev')); }); }
/** * Aux input for users */ public function additional_input_action() { // Activate the autoNavi otherwise we dont find this page in navi Navigation::activateItem('/course/members/additional'); // Fetch datafields for the user $course = new Course($_SESSION['SessionSeminar']); $member = $course->members->findOneBy('user_id', $GLOBALS['user']->id); $this->datafields = $member ? $course->aux->getMemberData($member) : array(); // We need aux data in the view $this->aux = $course->aux; // Update em if they got submittet if (Request::submitted('save')) { $datafields = SimpleCollection::createFromArray($this->datafields); foreach (Request::getArray('aux') as $aux => $value) { $datafield = $datafields->findOneBy('datafield_id', $aux); if ($datafield) { $typed = $datafield->getTypedDatafield(); if ($typed->isEditable()) { $typed->setValueFromSubmit($value); $typed->store(); } } } } }
/** * List all contact groups of a user * * @get /user/:user_id/contact_groups */ public function getUserContactGroups($user_id) { if ($GLOBALS['user']->id !== $user_id) { $this->error(401); } $contact_groups = \SimpleCollection::createFromArray(\Statusgruppen::findByRange_id($GLOBALS['user']->id))->orderBy('name ASC'); $total = count($contact_groups); $contact_groups = $contact_groups->limit($this->offset, $this->limit); $contact_groups_json = $this->contactGroupsToJSON($contact_groups); $this->etag(md5(serialize($contact_groups_json))); return $this->paginated($contact_groups_json, $total, compact('user_id')); }
function assign_role_institutes_action($role_id, $user_id) { if (Request::isXhr()) { $this->set_layout(null); $this->set_content_type('text/html;charset=windows-1252'); $this->response->add_header('X-No-Buttons', 1); $this->response->add_header('X-Title', PageLayout::getTitle()); foreach (array_keys($_POST) as $param) { Request::set($param, studip_utf8decode(Request::get($param))); } } if (Request::submitted('add_institute') && ($institut_id = Request::option('institute_id'))) { $roles = RolePersistence::getAllRoles(); $role = $roles[$role_id]; $user = new StudIPUser($user_id); RolePersistence::assignRole($user, $role, Request::option('institute_id')); PageLayout::postMessage(MessageBox::success(_("Die Einrichtung wurde zugewiesen."))); } if ($remove_institut_id = Request::option('remove_institute')) { $roles = RolePersistence::getAllRoles(); $role = $roles[$role_id]; $user = new StudIPUser($user_id); RolePersistence::deleteRoleAssignment($user, $role, $remove_institut_id); PageLayout::postMessage(MessageBox::success(_("Die Einrichtung wurde entfernt."))); } $roles = RolePersistence::getAllRoles(); $this->role = $roles[$role_id]; $this->user = new User($user_id); $this->institutes = SimpleCollection::createFromArray(Institute::findMany(RolePersistence::getAssignedRoleInstitutes($user_id, $role_id))); $this->institutes->orderBy('name'); $this->qsearch = QuickSearch::get("institute_id", new StandardSearch("Institut_id")); if (Request::isXhr()) { $this->qsearch->withoutButton(); } }
public function manage_access_action($range_id = null) { $this->range_id = $range_id ?: $this->range_id; $this->calendar = new SingleCalendar($this->range_id); $all_calendar_users = CalendarUser::getUsers($this->calendar->getRangeId()); $this->filter_groups = Statusgruppen::findByRange_id($this->calendar->getRangeId()); $this->users = array(); $this->group_filter_selected = Request::option('group_filter', 'list'); if ($this->group_filter_selected != 'list') { $contact_group = Statusgruppen::find($this->group_filter_selected); $calendar_users = array(); foreach ($contact_group->members as $member) { $calendar_users[] = new CalendarUser(array($this->calendar->getRangeId(), $member->user_id)); } $this->calendar_users = SimpleORMapCollection::createFromArray($calendar_users); } else { $this->group_filter_selected = 'list'; $this->calendar_users = $all_calendar_users; } $this->own_perms = array(); foreach ($this->calendar_users as $calendar_user) { $other_user = CalendarUser::find(array($calendar_user->user_id, $this->calendar->getRangeId())); if ($other_user) { $this->own_perms[$calendar_user->user_id] = $other_user->permission; } else { $this->own_perms[$calendar_user->user_id] = Calendar::PERMISSION_FORBIDDEN; } $this->users[strtoupper(SimpleCollection::translitLatin1($calendar_user->nachname[0]))][] = $calendar_user; } ksort($this->users); $this->users = array_map(function ($g) { return SimpleCollection::createFromArray($g)->orderBy('nachname, vorname'); }, $this->users); $this->mps = MultiPersonSearch::get('calendar-manage_access')->setTitle(_('Personhinzufügen'))->setLinkText(_('Person hinzufügen'))->setDefaultSelectedUser($all_calendar_users->pluck('user_id'))->setJSFunctionOnSubmit('STUDIP.CalendarDialog.closeMps')->setExecuteURL($this->url_for('calendar/single/add_users/' . $this->calendar->getRangeId()))->setSearchObject(new StandardSearch('user_id')); PageLayout::setTitle($this->getTitle($this->calendar, _('Kalender freigeben'))); $this->createSidebar('manage_access', $this->calendar); $this->createSidebarFilter(); }
/** * Validates the semester for required valies, properness of values * and possible overlaps with other semesters. * * The validation is also divided into these three steps, so the next * validation step only occurs when the previous one succeeded. * * @param Semester $semester Semester (data) to validate * @return Array filled with errors */ protected function validateSemester(Semester $semester) { // Validation, step 1: Check required values $errors = array(); if (!$this->semester->name) { $errors['name'] = _('Sie müssen den Namen des Semesters angeben.'); } if (!$this->semester->beginn) { $errors['beginn'] = _('Sie müssen den Beginn des Semesters angeben.'); } if (!$this->semester->ende) { $errors['ende'] = _('Sie müssen das Ende des Semesters angeben.'); } if (!$this->semester->vorles_beginn) { $errors['vorles_beginn'] = _('Sie müssen den Beginn der Vorlesungzeit angeben.'); } if (!$this->semester->vorles_ende) { $errors['vorles_ende'] = _('Sie müssen das Ende der Vorlesungzeit angeben.'); } // Validation, step 2: Check properness of values if (empty($errors)) { if ($this->semester->beginn > $this->semester->vorles_beginn) { $errors['beginn'] = _('Der Beginn des Semester muss vor dem Beginn der Vorlesungszeit liegen.'); } if ($this->semester->vorles_beginn > $this->semester->vorles_ende) { $errors['vorles_beginn'] = _('Der Beginn der Vorlesungszeit muss vor ihrem Ende liegen.'); } if ($this->semester->vorles_ende > $this->semester->ende) { $errors['vorles_ende'] = _('Das Ende der Vorlesungszeit muss vor dem Semesterende liegen.'); } } // Validation, step 3: Check overlapping with other semesters if (empty($errors)) { $all_semester = SimpleCollection::createFromArray(Semester::getAll())->findBy('id', $this->semester->id, '<>'); $collisions = $all_semester->findBy('beginn', array($this->semester->beginn, $this->semester->ende), '>=<='); $collisions->merge($all_semester->findBy('ende', array($this->semester->beginn, $this->semester->ende), '>=<=')); if ($collisions->count()) { $errors[] = sprintf(_('Der angegebene Zeitraum des Semester überschneidet sich mit einem anderen Semester (%s)'), join(', ', $collisions->pluck('name'))); } } return $errors; }
/** * Gets the list of applicants for the courses belonging to this course set. * * @param String $set_id course set ID * @param String $csv export users to file */ public function applications_list_action($set_id, $csv = null) { if (Request::isXhr()) { $this->response->add_header('X-Title', _('Liste der Anmeldungen')); } $courseset = new CourseSet($set_id); $applicants = AdmissionPriority::getPriorities($set_id); $users = User::findMany(array_keys($applicants), 'ORDER BY Nachname'); $courses = SimpleCollection::createFromArray(Course::findMany($courseset->getCourses())); $captions = array(_("Nachname"), _("Vorname"), _("Nutzername"), _("Veranstaltung"), _("Nummer"), _("Priorität")); $data = array(); foreach ($users as $user) { $row = array(); $app_courses = $applicants[$user->id]; asort($app_courses); foreach ($app_courses as $course_id => $prio) { $row = array(); $row[] = $user->nachname; $row[] = $user->vorname; $row[] = $user->username; $row[] = $courses->findOneBy('id', $course_id)->name; $row[] = $courses->findOneBy('id', $course_id)->veranstaltungsnummer; $row[] = $prio; if ($csv) { $row[] = $user->email; } $data[] = $row; } } if ($csv) { $tmpname = md5(uniqid('tmp')); $captions[] = _("Email"); if (array_to_csv($data, $GLOBALS['TMP_PATH'] . '/' . $tmpname, $captions)) { $this->redirect(GetDownloadLink($tmpname, 'Anmeldungen_' . $courseset->getName() . '.csv', 4, 'force')); return; } } $this->captions = $captions; $this->data = $data; $this->set_id = $courseset->getId(); }
/** * Dateien/Ordner einer Veranstaltung * * @get /course/:course_id/files */ public function getCourseFiles($course_id) { $folders = \SimpleCollection::createFromArray(\DocumentFolder::findBySeminar_id($course_id))->orderBy('name asc'); // slice according to demanded pagination $total = count($folders); $json = array(); foreach ($folders->limit($this->offset, $this->limit) as $folder) { $url = $this->urlf('/file/%s', array($folder->id)); $json[$url] = $this->folderToJSON($folder, true); } return $this->paginated($json, $total, compact('course_id')); }
/** * @param string $sort_status * @param string $order_by * @return SimpleCollection */ function getAdmissionMembers($sort_status = 'autor', $order_by = 'nachname asc') { $cs = CourseSet::getSetForCourse($this->course_id); $claiming = array(); if (is_object($cs) && !$cs->hasAlgorithmRun()) { foreach (AdmissionPriority::getPrioritiesByCourse($cs->getId(), $this->course_id) as $user_id => $p) { $user = User::find($user_id); $data = $user->toArray('user_id username vorname nachname email'); $data['fullname'] = $user->getFullname('full_rev'); $data['position'] = $p; $data['visible'] = 'unknown'; $data['status'] = 'claiming'; $claiming[] = $data; } } $query = "SELECT asu.user_id,username,vorname,nachname,email,status,position,asu.mkdate,asu.visible, asu.comment,\n " . $GLOBALS['_fullname_sql']['full_rev'] . " as fullname\n FROM admission_seminar_user asu INNER JOIN auth_user_md5 USING(user_id)\n INNER JOIN user_info USING(user_id)\n WHERE seminar_id = ? ORDER BY position, nachname ASC"; $st = DBManager::get()->prepare($query); $st->execute(array($this->course_id)); $application_members = SimpleCollection::createFromArray(array_merge($claiming, $st->fetchAll(PDO::FETCH_ASSOC))); $filtered_members = array(); foreach (words('awaiting accepted claiming') as $status) { $filtered_members[$status] = $application_members->findBy('status', $status); if ($status == $sort_status) { $filtered_members[$status]->orderBy($order_by, strpos($order_by, 'nachname') === false ? SORT_NUMERIC : SORT_LOCALE_STRING); } } return $filtered_members; }
public function execute($last_result, $parameters = array()) { $verbose = $parameters['verbose']; $sets = DbManager::get()->fetchFirst("SELECT DISTINCT cr.set_id FROM courseset_rule cr INNER JOIN coursesets USING(set_id)\n WHERE type = 'ParticipantRestrictedAdmission' AND algorithm_run = 0"); if (count($sets)) { if ($verbose) { echo date('r') . ' - Starting seat distribution ' . chr(10); $old_logger = Log::get()->getHandler(); $old_log_level = Log::get()->getLogLevel(); @mkdir($GLOBALS['TMP_PATH'] . '/seat_distribution_logs'); $logfile = $GLOBALS['TMP_PATH'] . '/seat_distribution_logs/' . date('Y-m-d-H-i') . '_seat_distribution.log'; if (is_dir($GLOBALS['TMP_PATH'] . '/seat_distribution_logs')) { Log::get()->setHandler($logfile); Log::get()->setLogLevel(Log::DEBUG); echo 'logging to ' . $logfile . chr(10); } else { echo 'could not create directory ' . $GLOBALS['TMP_PATH'] . '/seat_distribution_logs' . chr(10); } } foreach ($sets as $set_id) { $courseset = new CourseSet($set_id); if ($courseset->isSeatDistributionEnabled() && !$courseset->hasAlgorithmRun() && $courseset->getSeatDistributionTime() < time()) { if ($verbose) { echo ++$i . ' ' . $courseset->getId() . ' : ' . $courseset->getName() . chr(10); $applicants = AdmissionPriority::getPriorities($set_id); $courses = SimpleCollection::createFromArray(Course::findMany($courseset->getCourses()))->toGroupedArray('seminar_id', words('name veranstaltungsnummer')); $captions = array(_("Nachname"), _("Vorname"), _("Nutzername"), _('Nutzer-ID'), _('Veranstaltung-ID'), _("Veranstaltung"), _("Nummer"), _("Priorität")); $data = array(); $users = User::findEachMany(function ($user) use($courses, $applicants, &$data) { $app_courses = $applicants[$user->id]; asort($app_courses); foreach ($app_courses as $course_id => $prio) { $row = array(); $row[] = $user->nachname; $row[] = $user->vorname; $row[] = $user->username; $row[] = $user->id; $row[] = $course_id; $row[] = $courses[$course_id]['name']; $row[] = $courses[$course_id]['veranstaltungsnummer']; $row[] = $prio; $data[] = $row; } }, array_keys($applicants), 'ORDER BY Nachname'); $applicants_file = $GLOBALS['TMP_PATH'] . '/seat_distribution_logs/applicants_' . $set_id . '.csv'; if (array_to_csv($data, $applicants_file, $captions)) { echo 'applicants written to ' . $applicants_file . chr(10); } } $courseset->distributeSeats(); } } if ($verbose) { Log::get()->setHandler($old_logger); Log::get()->setLogLevel($old_log_level); } } else { if ($verbose) { echo date('r') . ' - Nothing to do' . chr(10); } } }