Newer
Older
Andrew Rudenets
committed
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Handler_AdmTeachers extends Controller_Handler {
public function before() {
$this->model = new Model_Admin_Teachers;
Andrew Rudenets
committed
$this->setAccessLevel(self::ACCESS_USER);
parent::before();
}
Andrew Rudenets
committed
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
protected function action_createTeacher()
{
$response['success'] = false;
$this->post
->rule('firstName', 'not_empty')
->rule('firstName', 'alpha_dash', array(':value', TRUE))
->rule('secondName', 'not_empty')
->rule('secondName', 'alpha_dash', array(':value', TRUE))
->rule('lastName', 'not_empty')
->rule('lastName', 'alpha_dash', array(':value', TRUE))
->rule('jobPositionID', 'not_empty')
->rule('jobPositionID', 'digit')
->rule('departmentID', 'not_empty')
->rule('departmentID', 'digit');
if($this->post->offsetGet('jobPositionID') == 0)
{
$this->post->error('jobPositionID', 'not_empty');
$response['success'] = false;
}
if($this->post->offsetGet('departmentID') == 0)
{
$this->post->error('departmentID', 'not_empty');
$response['success'] = false;
}
if($this->post->check())
{
$code = $this->createTeacher(
$this->post->offsetGet('lastName'),
$this->post->offsetGet('firstName'),
$this->post->offsetGet('secondName'),
$this->post->offsetGet('jobPositionID'),
$this->post->offsetGet('departmentID'));
if($code != -1)
{
$response['success'] = true;
$response['messages'][1] = 'Всё ОК! Вот код активации: '.$code;
}
else {
$response['success'] = false;
$response['messages'][1] = 'Неверные входные данные.';
}
}
else
{
$response['success'] = false;
$response['messages'] = $this->post->errors();
}
$this->response->body(json_encode($response));
}
protected function createTeacher($firstName, $secondName, $lastName, $degreeID, $departamentID)
Andrew Rudenets
committed
{
$activationCode = Account::instance()->createTeacher($firstName, $secondName, $lastName, $degreeID, $departamentID);
return $activationCode;
}
public function action_getTeachersList()
{
$departmentID = $this->post->offsetGet('departmentID');
$facultyID = $this->post->offsetGet('facultyID');
$teachersHandled = array();
if($departmentID != 0)
{
$teachers = $this->model->getTeachersByDepartment($departmentID);
$i = 0;
foreach($teachers as $row)
{
$i++;
$teachersHandled[$i]['ID'] = $row['TeacherID'];
$teachersHandled[$i]['FirstName'] = $row['TeacherFirst'];
$teachersHandled[$i]['SecondName'] = $row['TeacherSecond'];
$teachersHandled[$i]['LastName'] = $row['TeacherLast'];
$teachersHandled[$i]['JobPositionName'] = $row['JobPositionName'];
$teachersHandled[$i]['DepartmentName'] = $row['DepName'];
}
}
elseif($facultyID != 0)
{
$teachers = $this->model->getTeachersByFaculty($facultyID);
$i = 0;
foreach($teachers as $row)
{
$i++;
$teachersHandled[$i]['ID'] = $row['TeacherID'];
$teachersHandled[$i]['FirstName'] = $row['TeacherFirst'];
$teachersHandled[$i]['SecondName'] = $row['TeacherSecond'];
$teachersHandled[$i]['LastName'] = $row['TeacherLast'];
$teachersHandled[$i]['JobPositionName'] = $row['JobPositionName'];
$teachersHandled[$i]['DepartmentID'] = $row['DepID'];
$teachersHandled[$i]['DepartmentName'] = $row['DepName'];
}
}
$twig = Twig::factory('admin/teachers/handler/listOutput');
$twig->List = $teachersHandled;
$this->response->body($twig);
}
public function action_getDepartmentsList()
{
$facultyID = $this->post->offsetGet('facultyID');
if($facultyID != 0)
{
$departaments = $this->model->getDepartmentsByFaculty($facultyID);
$departamentsHandled = array(); $i = 0;
foreach($departaments as $row)
{
$i++;
$departamentsHandled[$i]['ID'] = $row['DepID'];
$departamentsHandled[$i]['Name'] = $row['DepName'];
}
$this->response->body(json_encode($departamentsHandled));
}
}