예제 #1
0
 public function addMembershipFormSucceeded($form, $values)
 {
     $data = $this->model->get($values->id);
     if ($data && ($this->user->isInRole("administrator") || $this->user->id == $data->user_id)) {
         try {
             $this->membershipModel->in($values->selection, $values->id);
         } catch (Exception $e) {
             $this->flashMessage("Přidání do skupiny se nepodařilo.", "danger");
         }
     } else {
         $this->flashMessage("Nemáte oprávnění tímto způsobem přidávat někoho do skupiny.", "danger");
     }
     $this->redirect('id', $values->id);
 }
예제 #2
0
 public function actionImportStudents()
 {
     $result = $this->model->importStudents();
     $messages = $result->messages;
     $data = $result->data;
     $reports = array();
     $this->studentsModel->invalidate();
     $classConversionTable = array();
     $classData = $this->classesModel->query("SELECT id, bakalari_code FROM sch_class")->fetchAll();
     foreach ($classData as $classRecord) {
         $classConversionTable[$classRecord["bakalari_code"]] = $classRecord["id"];
     }
     foreach ($data as $record) {
         $id = $this->studentsModel->existsBakalari($record->bakalari_code);
         if (!$id) {
             $newid = $this->usersModel->insert(array("firstname" => $record->firstname, "lastname" => $record->lastname, "title" => $record->title, "title_after" => $record->title_after, "gender" => $record->gender, "birthdate" => $record->birthdate, "phone" => $record->mobile_phone, "personal_identification_number" => $record->personal_identification_number, "email" => $record->email, "enabled" => 1, "active" => 1));
             $this->studentsModel->dumbInsert(array("user_id" => $newid, "catalog_number" => $record->catalog_number, "class_id" => $classConversionTable[$record->class_code], "network_login" => $record->login, "bakalari_code" => $record->bakalari_code));
             $this->studentsModel->query("INSERT INTO login_imap VALUES (\"{$newid}\",\"{$record->login}\")");
             $reports[] = "ADD: Student " . $record->firstname . " " . $record->lastname . " byl přidán. ({$newid})";
         } else {
             $recid = $id->user_id;
             $this->usersModel->update($recid, array("firstname" => $record->firstname, "lastname" => $record->lastname, "title" => $record->title, "title_after" => $record->title_after, "gender" => $record->gender, "birthdate" => $record->birthdate, "phone" => $record->mobile_phone, "personal_identification_number" => $record->personal_identification_number, "email" => $record->email, "enabled" => 1, "active" => 1));
             $this->studentsModel->update($recid, array("catalog_number" => $record->catalog_number, "class_id" => $classConversionTable[$record->class_code], "network_login" => $record->login, "bakalari_code" => $record->bakalari_code, "invalidated" => 0));
             $this->studentsModel->query("INSERT INTO login_imap (user_id,username) VALUES (\"{$recid}\",\"{$record->login}\") ON DUPLICATE KEY UPDATE username = \"{$record->login}\"");
             $reports[] = "UPDATE: Student " . $record->firstname . " " . $record->lastname . " byl aktualizován. ({$recid})";
         }
     }
     $this->studentsModel->query("DELETE FROM login_local WHERE user_id IN(SELECT user_id FROM sch_student WHERE invalidated = 1)");
     $studentsGroupId = $this->membershipModel->getIdfromRole("student");
     if ($studentsGroupId) {
         $this->membershipModel->emptyGroup($studentsGroupId);
         $reports[] = "Skupina {$studentsGroupId} byla vyprázdněna.";
         $this->membershipModel->query("INSERT INTO membership (`user_id`,`group_id`) SELECT user_id,{$studentsGroupId} FROM `sch_student`");
         $reports[] = "Skupina {$studentsGroupId} byla naplněna aktuálními studenty.";
     }
     $this->studentsModel->removeUnused();
     $this->template->reports = $reports;
     $this->template->messages = $messages;
     $this->setView("result");
 }
예제 #3
0
 public function addMembershipFormSucceeded($form, $values)
 {
     $data = $this->model->get($values->id);
     if ($data && $this->user->isInRole("administrator")) {
         try {
             $this->membershipModel->in($values->id, $values->selection);
         } catch (Exception $e) {
             $this->flashMessage("Přidání do skupiny se nepodařilo.", "danger");
         }
     } else {
         $this->flashMessage("Nemáte oprávnění tímto způsobem přidávat někoho do skupiny.", "danger");
     }
     if (!$this->isAjax()) {
         $this->redirect('this');
     } else {
         $this->template->membership = $this->membershipModel->userIsMember($values->id);
         $this->invalidateControl('membershipList');
         $this->invalidateControl('flashMessages');
         $form["selection"]->setItems($this->membershipModel->userIsNotMemberOfGroupsAsArray($values->id));
         $form["selection"]->setValue(null);
         $this->invalidateControl('addMembershipForm');
     }
 }