Skip to content
Snippets Groups Projects
Commit fb39098d authored by Andrew Rudenets's avatar Andrew Rudenets
Browse files

Added methods for the form service

parent 77f657cc
No related merge requests found
<?php defined('SYSPATH') or die('No direct script access.');
/*
* Т.к. нынешнее состояние Handler'ов не позволяет работать с кроссдоменными запросами,
* (например, проблема #1 - повсеместное использование метода POST)
* пришлось написать данный класс, в котором перечислены все необходимые методы для работы
* с сервисом анкетирования. В связи с чем...
*/
// TODO: Выбросить содержимое папки Handler и разработать API
class Controller_Handler_Form extends Controller_Handler
{
public function before() {
parent::before();
}
public function action_authorize() {
$user = User::instance();
$isEmail = Validation::factory($_GET)
->rule('login', 'not_empty')
->rule('login', 'email')
->check();
$isCorrectLogin = Validation::factory($_GET)
->rule('login', 'not_empty')
->rule('login', 'alpha_dash')
->check();
$res['success'] = ($isEmail or $isCorrectLogin)
? $user->signIn($_GET['login'], $_GET['password'])
: false;
if($res['success'])
{
$res['ID'] = $user->ID;
$res['Type'] = $user->Type;
$res['Name'] = $user->FirstName.' '.$user->SecondName.' '.$user->LastName;
$res['Group'] = ($user->Type == 'student') ?
$user->GroupID : -1;
}
$this->response->body(json_encode($res));
}
public function action_getSubjects()
{
$facultyID = $this->get['faculty_id'];
$res = Model_Faculty::with($facultyID)->getSubjects();
$this->response->body(json_encode($res));
}
public function action_getTeachers()
{
$facultyID = $this->get['faculty_id'];
$res = Model_Teachers::ofFaculty($facultyID);
$this->response->body(json_encode($res));
}
public function action_getGroups()
{
$facultyID = $this->get['faculty_id'];
$gradeID = $this->get['grade_id'];
$res = Model_Faculty::with($facultyID)->getGroups($gradeID);
$this->response->body(json_encode($res));
}
public function action_getGrades()
{
$res = Model_Grades::loadAll();
$this->response->body(json_encode($res));
}
public function action_getSubjectByID()
{
$facultyID = $this->get['faculty_id'];
$subjectID = $this->get['subject_id'];
$res = Model_Faculty::with($facultyID)->getSubjects();
$this->response->body(json_encode(array($res[$subjectID])));
}
public function action_getTeacherByID()
{
$teacherID = $this->get['teacher_id'];
$teacher = Model_Teacher::with($teacherID);
$data = [
'Name' => $teacher->LastName . ' ' . $teacher->FirstName . ' ' . $teacher->SecondName,
'JobPosition' => $teacher->JobPositionName,
];
$this->response->body(json_encode($data));
}
public function after()
{
parent::after();
$data = $this->response->body();
$callback = $this->get['callback'];
$this->response->body($callback.'('.$data.');');
}
}
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment