/** * @param string $field: name of the field of target table (not the imported table!) * @param array $line : all other data from that line. * @return mixed: if no mapping should apply map to false. null maps * to database NULL. Any other value will map to a string value. */ public function mapField($field, $line) { if ($field === "fleximport_studyarea") { $studienbereiche = array("0" => "Webinare / eLearning", "1" => "Studiengebiet 1", "2" => "Studiengebiet 2", "3" => "Studiengebiet 3", "4" => "Studiengebiet 4", "5" => "Studiengebiet 5", "6" => "Trainingszentrum", "8" => "BKA / DHPOL / externe Fobi", "9" => "Sonstiges"); $studyareas = array(); foreach (StudipStudyArea::findBySQL("name = ?", array($studienbereiche[$line['studienbereich']])) as $study_area) { $studyareas[] = $study_area->getId(); } return $studyareas; } return false; }
public function check($data, $virtualobject, $relevantfields) { $errors = ""; if (!$data['fleximport_dozenten'] || !count($data['fleximport_dozenten'])) { $errors .= "Dozent kann nicht gemapped werden. "; } else { $exist = false; foreach ((array) $data['fleximport_dozenten'] as $dozent_id) { if (User::find($dozent_id)) { $exist = true; break; } } if (!$exist) { $errors .= "Angegebene Dozenten sind nicht im System vorhanden. "; } else { if ($GLOBALS['SEM_CLASS'][$GLOBALS['SEM_TYPE'][$virtualobject['status']]['class']]['only_inst_user']) { $statement = DBManager::get()->prepare("\n SELECT 1\n FROM user_inst\n WHERE user_id IN (:dozent_ids)\n AND Institut_id IN (:institut_ids)\n AND inst_perms IN ('autor','tutor','dozent')\n "); $statement->execute(array('dozent_ids' => (array) $data['fleximport_dozenten'], 'institut_ids' => $data['fleximport_related_institutes'] ?: array($virtualobject['institut_id']))); if (!$statement->fetch(PDO::FETCH_COLUMN, 0)) { $errors .= "Keiner der Dozenten ist in einer beteiligten Einrichtung angestellt. "; } } } } if (!$data['institut_id'] || !Institute::find($data['institut_id'])) { $errors .= "Keine gültige Heimateinrichtung. "; } if (!Semester::findByTimestamp($data['start_time'])) { $errors .= "Semester wurde nicht gefunden. "; } if ($data['status']) { if ($GLOBALS['SEM_CLASS'][$GLOBALS['SEM_TYPE'][$data['status']]['class']]['bereiche']) { $found = false; foreach ((array) $data['fleximport_studyarea'] as $sem_tree_id) { if (StudipStudyArea::find($sem_tree_id)) { $found = true; break; } } if (!$found) { $errors .= "Keine (korrekten) Studienbereiche definiert. "; } } } else { $errors .= "Kein Veranstaltungstyp definiert. "; } return $errors; }
public function index_action() { $this->prelim_discussion = vorbesprechung($this->course->id); $this->title = $this->course->getFullname(); $this->course_domains = UserDomain::getUserDomainsForSeminar($this->course->id); $this->sem = new Seminar($this->course); if ($studienmodulmanagement = PluginEngine::getPlugin('StudienmodulManagement')) { foreach ($this->course->study_areas->filter(function ($m) { return $m->isModule(); }) as $module) { $this->studymodules[] = array('nav' => $studienmodulmanagement->getModuleInfoNavigation($module->id, $this->course->start_semester->id), 'title' => $studienmodulmanagement->getModuleTitle($module->id, $this->course->start_semester->id)); } } // Retrive display of sem_tree if (Config::get()->COURSE_SEM_TREE_DISPLAY) { $this->studyAreaTree = StudipStudyArea::backwards($this->course->study_areas); } else { $this->study_areas = $this->course->study_areas->filter(function ($m) { return !$m->isModule(); }); } if (Request::isXhr()) { $this->set_layout(null); $this->response->add_header('Content-Type', 'text/html;charset=Windows-1252'); header('X-Title: ' . $this->title); } else { PageLayout::setHelpKeyword("Basis.InVeranstaltungDetails"); PageLayout::setTitle($this->title . " - " . _("Details")); PageLayout::addSqueezePackage('admission'); PageLayout::addSqueezePackage('enrolment'); if ($GLOBALS['SessionSeminar'] == $this->course->id) { Navigation::activateItem('/course/main/details'); SkipLinks::addIndex(Navigation::getItem('/course/main/details')->getTitle(), 'main_content', 100); } else { $sidebarlink = true; $enrolment_info = $this->sem->getEnrolmentInfo($GLOBALS['user']->id); } $sidebar = Sidebar::Get(); if ($sidebarlink) { $sidebar->setContextAvatar(CourseAvatar::getAvatar($this->course->id)); } $sidebar->setTitle(_('Details')); $links = new ActionsWidget(); $links->addLink(_("Drucken"), URLHelper::getScriptLink("dispatch.php/course/details/index/" . $this->course->id), Icon::create('print', 'clickable'), array('class' => 'print_action', 'target' => '_blank')); if ($enrolment_info['enrolment_allowed'] && $sidebarlink) { if (in_array($enrolment_info['cause'], words('member root courseadmin'))) { $abo_msg = _("direkt zur Veranstaltung"); } else { $abo_msg = _("Zugang zur Veranstaltung"); } $links->addLink($abo_msg, URLHelper::getScriptLink("dispatch.php/course/enrolment/apply/" . $this->course->id), Icon::create('door-enter', 'clickable'), array('data-dialog' => '')); } if (Config::get()->SCHEDULE_ENABLE && !$GLOBALS['perm']->have_studip_perm("user", $this->course->id) && !$GLOBALS['perm']->have_perm('admin') && $this->sem->getMetaDateCount()) { $query = "SELECT COUNT(*) FROM schedule_seminare WHERE seminar_id = ? AND user_id = ?"; if (!DBManager::Get()->fetchColumn($query, array($this->course->id, $GLOBALS['user']->id))) { $links->addLink(_("Nur im Stundenplan vormerken"), URLHelper::getLink("dispatch.php/calendar/schedule/addvirtual/" . $this->course->id), Icon::create('info', 'clickable')); } } if ($this->send_from_search_page) { $links->addLink(_("Zurück zur letzten Auswahl"), URLHelper::getLink($this->send_from_search_page), Icon::create('link-intern', 'clickable')); } if ($links->hasElements()) { $sidebar->addWidget($links); } $sidebar->setImage('sidebar/seminar-sidebar.png'); $sidebar->setContextAvatar(CourseAvatar::getAvatar($this->course->id)); $sidebar = Sidebar::Get(); $sidebar->setImage('sidebar/seminar-sidebar.png'); $sidebar->setContextAvatar(CourseAvatar::getAvatar($this->course->id)); if ($enrolment_info['description']) { PageLayout::postMessage(MessageBox::info($enrolment_info['description'])); } } }
/** * Returns the name of the study area for the id found in the given * field or the id if the study area is unknown. * * @param string $field The name of the table field. * @return string The name of seminar or the id. */ protected function formatStudyarea($field) { $study_area = StudipStudyArea::find($this->{$field}); if (!$study_area) { return $this->{$field}; } return '<em>' . $study_area->getPath(' > ') . '</em>'; }
/** * Returns the trail -- the path from the root of the tree of study areas down * to the currently selected area. * * # TODO (mlunzena) this has to be refactored as well * * @return array an array of study areas; currently each item is an * hashmap containing the ID of each area using the key * 'id' and the name of the study area using the key 'name' */ function getTrail() { $area = $this->selected; $trail = array($area->getID() => $area); while ($parent = $area->getParent()) { $trail[$parent->getID()] = $parent; $area = $parent; } $trail[StudipStudyArea::ROOT] = StudipStudyArea::getRootArea(); return array_reverse($trail, TRUE); }
public function getMappedData($line) { $plugin = $this->getPlugin(); $fields = $this->getTargetFields(); //dynamic additional fields: switch ($this['import_type']) { case "Course": foreach (Datafield::findBySQL("object_type = 'sem'") as $datafield) { $fields[] = $datafield['name']; } $fields[] = "fleximport_dozenten"; $fields[] = "fleximport_related_institutes"; $fields[] = "fleximport_studyarea"; $fields[] = "fleximport_locked"; $fields[] = "fleximport_course_userdomains"; break; case "User": foreach (Datafield::findBySQL("object_type = 'user'") as $datafield) { $fields[] = $datafield['name']; } $fields[] = "fleximport_username_prefix"; $fields[] = "fleximport_userdomains"; $fields[] = "fleximport_user_inst"; $fields[] = "fleximport_expiration_date"; $fields[] = "fleximport_welcome_message"; break; } $data = array(); foreach ($fields as $field) { $mapping = false; //important: false means no mapping, null means mapping to database null if ($plugin && in_array($field, $plugin->fieldsToBeMapped())) { $mapping = $plugin->mapField($field, $line); } if ($mapping !== false) { $data[$field] = $mapping; } else { if ($this['tabledata']['simplematching'][$field]['column']) { if ($this['tabledata']['simplematching'][$field]['column'] === "static value") { //use a static value $data[$field] = $this['tabledata']['simplematching'][$field]['static']; } else { if (strpos($this['tabledata']['simplematching'][$field]['column'], "fleximportconfig_") === 0) { $config = substr($this['tabledata']['simplematching'][$field]['column'], strlen("fleximportconfig_")); $template = FleximportConfig::get($config); foreach ($data as $index => $value) { $template = str_replace("{{" . $index . "}}", $value, $template); } foreach ($line as $index => $value) { if (!in_array($index, $data)) { $template = str_replace("{{" . $index . "}}", $value, $template); } } $data[$field] = $template; } else { //use a matched column $data[$field] = $line[$this['tabledata']['simplematching'][$field]['column']]; } } } else { //else no mapping, don't even overwrite old value. } } } foreach ($fields as $field) { //mapper: if (strpos($this['tabledata']['simplematching'][$field]['column'], "fleximport_mapper__") === 0) { list($prefix, $mapperclass, $format) = explode("__", $this['tabledata']['simplematching'][$field]['column']); if (class_exists($mapperclass)) { $mapper = new $mapperclass(); if (is_a($mapper, "FleximportMapper")) { $mapfrom = $this['tabledata']['simplematching'][$field]['mapfrom']; $data[$field] = $mapper->map($format, $data[$mapfrom] ?: $line[$mapfrom]); } } } } //special mapping if ($this['import_type'] === "Course") { //Map seminar_id : if (!$data['seminar_id'] && $this['tabledata']['simplematching']["seminar_id"]['column'] === "fleximport_map_from_veranstaltungsnummer_and_semester") { $course = Course::findOneBySQL("name = ? AND start_time = ?", array($data['name'], $data['start_time'])); if ($course) { $data['seminar_id'] = $course->getId(); } } //Map dozenten: if ($this['tabledata']['simplematching']["fleximport_dozenten"]['column'] && !in_array("fleximport_dozenten", $this->fieldsToBeDynamicallyMapped())) { $data['fleximport_dozenten'] = (array) preg_split($this['tabledata']['simplematching']["fleximport_dozenten"]['format'] === "fullname" ? "/\\s*,\\s*/" : "/\\s+/", $data['fleximport_dozenten'], null, PREG_SPLIT_NO_EMPTY); switch ($this['tabledata']['simplematching']["fleximport_dozenten"]['format']) { case "user_id": $data['fleximport_dozenten'] = array_map(function ($user_id) { $user = User::find($user_id); if ($user) { return $user->getId(); } else { return null; } }, $data['fleximport_dozenten']); break; case "username": $data['fleximport_dozenten'] = array_map("get_userid", $data['fleximport_dozenten']); break; case "email": $data['fleximport_dozenten'] = array_map(function ($email) { $user = User::findOneByEmail($email); if ($user) { return $user->getId(); } else { return null; } }, $data['fleximport_dozenten']); break; case "fullname": $data['fleximport_dozenten'] = array_map(function ($fullname) { list($vorname, $nachname) = (array) preg_split("/\\s+/", $fullname, null, PREG_SPLIT_NO_EMPTY); $user = User::findOneBySQL("Vorname = ? AND Nachname = ? AND perms = 'dozent'", array($vorname, $nachname)); if ($user) { return $user->getId(); } else { return null; } }, $data['fleximport_dozenten']); break; default: //map by datafield $datafield_id = $this['tabledata']['simplematching']["fleximport_dozenten"]['format']; foreach ($data['fleximport_dozenten'] as $key => $value) { $entry = DatafieldEntryModel::findOneBySQL("datafield_id = ? AND content = ?", array($datafield_id, $value)); if ($entry) { $data['fleximport_dozenten'][$key] = $entry['range_id']; } else { unset($data['fleximport_dozenten'][$key]); } } break; } } //Map sem_type: if ($this['tabledata']['simplematching']["status"]['column'] && $this['tabledata']['simplematching']["status"]['format']) { if ($this['tabledata']['simplematching']["status"]['format'] === "name") { $sem_type_id = null; foreach ($GLOBALS['SEM_TYPE'] as $id => $sem_type) { if ($sem_type['name'] === $data['status']) { $sem_type_id = $id; } } $data['status'] = $sem_type_id; } } //Map Studienbereiche if ($this['tabledata']['simplematching']["fleximport_studyarea"]['column'] && !in_array("fleximport_studyarea", $this->fieldsToBeDynamicallyMapped())) { if ($this['tabledata']['simplematching']["fleximport_studyarea"]['column'] === "static value") { $data['fleximport_studyarea'] = (array) explode(";", $this['tabledata']['simplematching']["fleximport_studyarea"]['static']); } else { $data['fleximport_studyarea'] = (array) explode(";", $data['fleximport_studyarea']); $study_areas = array(); foreach ($data['fleximport_studyarea'] as $key => $name) { foreach (StudipStudyArea::findBySQL("name = ?", array($name)) as $study_area) { $study_areas[] = $study_area->getId(); } } $data['fleximport_studyarea'] = $study_areas; } } if ($this['tabledata']['simplematching']["fleximport_course_userdomains"]['column'] && !in_array("fleximport_course_userdomains", $this->fieldsToBeDynamicallyMapped())) { $data['fleximport_course_userdomains'] = (array) preg_split("/\\s*,\\s*/", $data['fleximport_course_userdomains'], null, PREG_SPLIT_NO_EMPTY); $statement = DBManager::get()->prepare("SELECT userdomain_id FROM userdomains WHERE name IN (:domains) OR userdomain_id IN (:domains)"); $statement->execute(array('domains' => $data['fleximport_course_userdomains'])); $data['fleximport_course_userdomains'] = $statement->fetchAll(PDO::FETCH_COLUMN, 0); } } if ($this['import_type'] === "User") { if ($this['tabledata']['simplematching']["username"]['column']) { if ($this['tabledata']['simplematching']["username"]['format'] === "email_first_part") { list($data['username']) = explode("@", $data['username']); } if ($this['tabledata']['simplematching']["fleximport_username_prefix"]['column']) { $data['username'] = $data['fleximport_username_prefix'] . $data['username']; } } if ($this['tabledata']['simplematching']["fleximport_user_inst"]['column']) { $data['fleximport_user_inst'] = (array) preg_split("/\\s*,\\s*/", $data['fleximport_user_inst'], null, PREG_SPLIT_NO_EMPTY); $institut_ids = array(); foreach ($data['fleximport_user_inst'] as $inst_name) { $statement = DBManager::get()->prepare("\n SELECT Institut_id\n FROM Institute\n WHERE Name = ?\n "); $statement->execute(array($inst_name)); $institut_id = $statement->fetch(PDO::FETCH_COLUMN, 0); if ($institut_id) { $institut_ids[] = $institut_id; } } $data['fleximport_user_inst'] = $institut_ids; } if ($this['tabledata']['simplematching']["fleximport_userdomains"]['column'] && !in_array("fleximport_userdomains", $this->fieldsToBeDynamicallyMapped())) { $data['fleximport_userdomains'] = (array) preg_split("/\\s*,\\s*/", $data['fleximport_userdomains'], null, PREG_SPLIT_NO_EMPTY); $statement = DBManager::get()->prepare("SELECT userdomain_id FROM userdomains WHERE name IN (:domains) OR userdomain_id IN (:domains)"); $statement->execute(array('domains' => $data['fleximport_userdomains'])); $data['fleximport_userdomains'] = $statement->fetchAll(PDO::FETCH_COLUMN, 0); } if ($this['tabledata']['simplematching']["fleximport_expiration_date"]['column'] && !in_array("fleximport_expiration_date", $this->fieldsToBeDynamicallyMapped())) { if (!is_numeric($data['fleximport_expiration_date'])) { $data['fleximport_expiration_date'] = strtotime($data['fleximport_expiration_date']); } } } if ($this['import_type'] === "User" && !$data['user_id']) { if (!$data['user_id'] && $data['auth_plugin'] === "standard" && !$data['password']) { $usermanager = new UserManagement(); $data['password'] = $usermanager->generate_password(6); } } return $data; }
public function getAncestorTree($id) { $result = array(); $node = StudipStudyArea::find($id); $root = StudipStudyArea::backwards(array($node)); $result = $this->buildPartialSemTree($root); return json_encode($result); }
/** * Returns the not really existing root study area. * * @return object the root study area object */ static function getRootArea() { $root = new StudipStudyArea(); $root->setID(self::ROOT); $root->setName($GLOBALS['UNI_NAME_CLEAN']); return $root; }
function get_area_ids($course_id) { $selection = StudipStudyArea::getStudyAreasForCourse($course_id); return array_keys($selection->toGroupedArray('sem_tree_id')); }