Skip to content
Snippets Groups Projects
Subject.php 1.83 KiB
Newer Older
<?php

class Controller_Api_V0_Subject extends Controller_Handler_Api
{
    /**
     * @api {get} api/v0/subject/listForStudentID?token=:token&studentID=:studentID&semesterID=:semesterID Get list of student's subjects
Artem Konenko's avatar
Artem Konenko committed
     * @apiName Get student's subjects
     * @apiGroup Subject
     * @apiVersion 0.1.0
     * @apiParam {String} token Api key
     * @apiParam {Int} studentID Student identifier
     * @apiParam {Int} semesterID Semester identifier
     */
    public function action_get_listForStudentID() {
        if ( !$this->user->isAdmin() ) // ToDo: we should use apikey mask for checking rights
            $this->fail();
        $id = $this->request->query('studentID');
        $semester = $this->request->query('semesterID');
        $this->get->rule('studentID', 'numeric');
        $this->get->rule('semesterID', 'numeric');
        if ( !$this->get->check() )
            $this->badRequestError('Incorrect request parameters');

        $student = Model_Student::load($id);
        $disciplines = $student->getDisciplines($semester);
        $teachers = $student->getTeachers(true, $semester);

        $res = [];
        foreach ($disciplines as $discipline) {
            $subj = new StdClass(); // ToDo: Replace by specialized class
            $subj->ID = $discipline->SubjectID;
            $subj->DisciplineName = $discipline->SubjectName;
            $subj->Teachers = [];
            foreach ($teachers[$discipline->ID] as $teacher) {
                $t = new StdClass(); // ToDo: Replace by specialized class
                $t->ID = $teacher['TeacherID'];
                $t->LastName = $teacher['LastName'];
                $t->FirstName = $teacher['FirstName'];
                $t->SecondName = $teacher['SecondName'];

                $subj->Teachers[] = $t;
            }
            $res[] = $subj;
        }
        return $res;