Skip to content
Snippets Groups Projects
Commit 0b645dc7 authored by xamgore's avatar xamgore
Browse files

Renamed listOutput to listStudent

+ Code refactoring in the AdmStudent controller
parent cfd3f3bd
Branches
Tags
No related merge requests found
<?php defined('SYSPATH') or die('No direct script access.'); <?php defined('SYSPATH') or die('No direct script access.');
abstract class SortingOptions { //extends SplEnum { // todo: think about usage & file system abstract class SortingOptions
{ //extends SplEnum { // todo: think about usage & file system
//const __default = self::Name; //const __default = self::Name;
const Name = 0; const Name = 0;
const Grade = 1; const Grade = 1;
const Group = 2; const Group = 2;
} }
class Controller_Handler_AdmStudents extends Controller_Handler class Controller_Handler_AdmStudents extends Controller_Handler
{ {
const STUDENTS_LIST = '/handler/listOutput'; const STUDENTS_LIST = '/handler/listStudents';
public function before() { public function before() {
$this->setAccessLevel(self::ACCESS_USER); $this->setAccessLevel(self::ACCESS_USER);
parent::before(); parent::before();
}
public function action_createStudent() {
$response['success'] = false;
$this->post->rule('firstName', 'not_empty')
->rule('lastName', 'not_empty')
->rule('gradeNum', 'not_empty')
->rule('gradeNum', 'digit')
->rule('groupNum', 'not_empty')
->rule('groupNum', 'digit')
->rule('facultyID', 'not_empty')
->rule('facultyID', 'digit');
if ($this->post['gradeNum'] == 0) {
$this->post->error('gradeNum', 'not_empty');
$response['success'] = false;
} }
public function action_createStudent() if ($this->post['groupNum'] == 0) {
{ $this->post->error('groupNum', 'not_empty');
$response['success'] = false; $response['success'] = false;
$this->post }
->rule('firstName', 'not_empty')
// ->rule('firstName', 'alpha_dash', array(':value', TRUE)) if ($this->post['facultyID'] == 0) {
// ->rule('secondName', 'not_empty') $this->post->error('facultyID', 'not_empty');
// ->rule('secondName', 'alpha_dash', array(':value', TRUE)) $response['success'] = false;
->rule('lastName', 'not_empty') }
// ->rule('lastName', 'alpha_dash', array(':value', TRUE))
->rule('gradeNum', 'not_empty') if ($this->post->check()) {
->rule('gradeNum', 'digit') $code = Account::instance()
->rule('groupNum', 'not_empty') ->createStudent(
->rule('groupNum', 'digit') $this->post['lastName'], $this->post['firstName'], $this->post['secondName'],
->rule('facultyID', 'not_empty') $this->post['gradeNum'], $this->post['groupNum'], $this->post['facultyID']
->rule('facultyID', 'digit'); );
if($this->post['gradeNum'] == 0)
{ if ($code != -1) {
$this->post->error('gradeNum', 'not_empty'); $response['success'] = true;
$response['success'] = false; $response['code'] = $code;
} } else {
if($this->post['groupNum'] == 0)
{
$this->post->error('groupNum', 'not_empty');
$response['success'] = false;
}
if($this->post['facultyID'] == 0)
{
$this->post->error('facultyID', 'not_empty');
$response['success'] = false;
}
if($this->post->check())
{
$code = Account::instance()
->createStudent(
$this->post['lastName'],
$this->post['firstName'],
$this->post['secondName'],
$this->post['gradeNum'],
$this->post['groupNum'],
$this->post['facultyID']
);
if($code != -1)
{
$response['success'] = true;
$response['code'] = $code;
}
else {
$response['success'] = false;
}
}
else
{
$response['success'] = false; $response['success'] = false;
$response['messages'] = $this->post->errors();
} }
$this->response->body(json_encode($response)); } else {
$response['success'] = false;
$response['messages'] = $this->post->errors();
} }
$this->response->body(json_encode($response));
public function action_getGroups() }
{
$facultyID = $this->post['facultyID']; public function action_getGroups() {
$gradeID = $this->post['gradeNum']; $facultyID = $this->post['facultyID'];
if(($facultyID && $gradeID) != 0) $gradeID = $this->post['gradeNum'];
{ if (($facultyID && $gradeID) != 0) {
$groups = Model_Faculty::with($facultyID)->getGroups($gradeID); $groups = Model_Faculty::with($facultyID)->getGroups($gradeID);
$groupsHandled = array(); $i = $j = $id = 0; $groupsHandled = array();
foreach($groups as $row) $i = $j = $id = 0;
{ foreach ($groups as $row) {
if($id != $row['SpecID']) if ($id != $row['SpecID']) {
{ $i++;
$i++; $j = 0; $j = 0;
$id = $row['SpecID']; $id = $row['SpecID'];
}
$j++;
if (is_null($row['SpecName']))
$groupsHandled[$i]['SpecName'] = "<без специализации>";
else
$groupsHandled[$i]['SpecName'] = $row['SpecName'];
$groupsHandled[$i]['Groups'][$j]['ID'] = $row['ID'];
$groupsHandled[$i]['Groups'][$j]['Num'] = $row['GroupNum'];
} }
$this->response->body(json_encode($groupsHandled)); $j++;
if (is_null($row['SpecName'])) {
$groupsHandled[$i]['SpecName'] = "<без специализации>";
} else {
$groupsHandled[$i]['SpecName'] = $row['SpecName'];
}
$groupsHandled[$i]['Groups'][$j]['ID'] = $row['ID'];
$groupsHandled[$i]['Groups'][$j]['Num'] = $row['GroupNum'];
} }
$this->response->body(json_encode($groupsHandled));
} }
}
public function action_getStudentsList($option = SortingOptions::Name) { public function action_getStudentsList($option = SortingOptions::Name) {
$twig = Twig::factory(self::STUDENTS_LIST); $twig = Twig::factory(self::STUDENTS_LIST);
$facultyID = (int) $this->post['facultyID']; $facultyID = (int) $this->post['facultyID'];
$gradeID = (int) $this->post['gradeID']; $gradeID = (int) $this->post['gradeID'];
$groupID = (int) $this->post['groupID']; $groupID = (int) $this->post['groupID'];
if ($this->post->check()) { if ($this->post->check()) {
$result = Model_Students::byFaculty($facultyID , $gradeID, $groupID); $result = Model_Students::byFaculty($facultyID, $gradeID, $groupID);
$twig->List = $result; $twig->List = $result;
} }
$this->response->body($twig);
}
public function action_getStudentsByStudyGroup() {
$groupID = $this->post['studyGroupID'];
if ($groupID != 0) {
$twig = Twig::factory(self::STUDENTS_LIST);
$twig->List = Model_Students::byStudyGroup($groupID);
$this->response->body($twig); $this->response->body($twig);
} }
}
public function action_getStudentsByStudyGroup() public function action_getStudentsByFaculty() {
{ $facultyID = $this->post['facultyID'];
$groupID = $this->post['studyGroupID'];
if($groupID != 0)
{
$twig = Twig::factory(self::STUDENTS_LIST);
$twig->List = Model_Students::byStudyGroup($groupID);
$this->response->body($twig);
}
}
/** @deprecated */ if ($facultyID != 0) {
public function action_getStudentsByFaculty() $twig = Twig::factory(self::STUDENTS_LIST);
{ // (Grade, Group) = (0,0), to ignore (search all students)
$facultyID = $this->post['facultyID']; $twig->List = Model_Students::byFaculty($facultyID);
if($facultyID != 0) $this->response->body($twig);
{
$twig = Twig::factory(self::STUDENTS_LIST);
// (Grade, Group) = (0,0), to ignore (search all students)
$twig->List = Model_Students::byFaculty($facultyID, 0, 0);
$this->response->body($twig);
}
} }
}
public function action_getStudentsByName() { public function action_getStudentsByName() {
$twig = Twig::factory(self::STUDENTS_LIST); $twig = Twig::factory(self::STUDENTS_LIST);
...@@ -161,8 +144,7 @@ class Controller_Handler_AdmStudents extends Controller_Handler ...@@ -161,8 +144,7 @@ class Controller_Handler_AdmStudents extends Controller_Handler
public function action_giveLeave() { public function action_giveLeave() {
// fixme // fixme
$id = (int) $this->get['id']; $id = (int) $this->get['id'];
Model_Student::load($id) Model_Student::load($id)->toAcademicLeave();
->toAcademicLeave();
} }
public function action_stopLeave() { public function action_stopLeave() {
......
...@@ -27,10 +27,17 @@ class Model_Students extends Model ...@@ -27,10 +27,17 @@ class Model_Students extends Model
return self::collect(self::ofGroup($groupID)); return self::collect(self::ofGroup($groupID));
} }
public static function byFaculty($facultyID, $gradeID, $groupID, $semesterID = null) { public static function byFaculty($facultyID, $gradeID = null, $groupID = null, $semesterID = null) {
$semesterID = $semesterID ? $semesterID : User::instance()->SemesterID;; $semesterID = $semesterID ? $semesterID : User::instance()->SemesterID;
$sql = "CALL `GetStudentsByFaculty`('$facultyID', '$gradeID', $groupID, $semesterID); "; $sql = "CALL `GetStudentsByFaculty`(:faculty, :grade, :group, :semester); ";
$students = DB::query(Database::SELECT, $sql)->execute(); $students = DB::query(Database::SELECT, $sql)
->parameters([
':faculty' => (int) $facultyID,
':grade' => (int) $gradeID,
':group' => (int) $groupID,
':semester' => (int) $semesterID,
])
->execute();
return self::collect($students); return self::collect($students);
} }
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
<div class="search_item_info"> <div class="search_item_info">
<div class="search_item_firstLine"> <div class="search_item_firstLine">
{% set name = row.LastName ~ ' ' ~ row.FirstName ~ ' ' ~ row.SecondName %} {% set name = row.LastName ~ ' ' ~ row.FirstName ~ ' ' ~ row.SecondName %}
{{ HTML.anchor('dean_office/students/' ~ row.AccountID, name|e)|raw }} {{ HTML.anchor('students/' ~ row.AccountID, name|e)|raw }}
</div> </div>
</div> </div>
<div class="search_item_actions"> <div class="search_item_actions">
......
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