Newer
Older
Andrew Rudenets
committed
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Handler_AdmTeachers extends Controller_Handler {
public function before() {
Andrew Rudenets
committed
$this->setAccessLevel(self::ACCESS_USER);
parent::before();
}
Andrew Rudenets
committed
protected function action_createTeacher()
{
$response['success'] = false;
$this->post
->rule('firstName', 'not_empty')
// ->rule('firstName', 'alpha_dash', array(':value', TRUE))
// ->rule('secondName', 'alpha_dash', array(':value', TRUE))
Andrew Rudenets
committed
->rule('lastName', 'not_empty')
// ->rule('lastName', 'alpha_dash', array(':value', TRUE))
Andrew Rudenets
committed
->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())
{
Andrew Rudenets
committed
$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');
if($departmentID != 0)
$teachers = Model_Teachers::create()->byDepartment($departmentID)->asArray();
elseif($facultyID != 0)
$teachers = Model_Teachers::create()->byFaculty($facultyID)->asArray();
$twig = Twig::factory('admin/teachers/handler/listOutput');
$this->response->body($twig);
}
public function action_getDepartmentsList()
{
$facultyID = $this->post->offsetGet('facultyID');
$this->response->body(Model_Departments::create()->byFaculty($facultyID)->asJSON());
}