Skip to content
Snippets Groups Projects
Discipline.php 1.33 KiB
Newer Older
xamgore's avatar
xamgore committed
<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Api_Discipline extends Controller_Handler {

    public $data;

    public function before() {
        // todo: var $user should be defined here
        //    either by GET param (token),
        //    or on the session variables.
        $this->setAccessLevel(self::ACCESS_USER);
        parent::before();
    }

    public function after() {
        $this->response->body(json_encode($this->data));
    }

    public function action_create() {
        try {
            $discipline = Model_Discipline::make()
                ->author  ($this->user['TeacherID'])
                ->faculty ($this->post['facultyID'])
                ->subject ($this->post['subjectID'])
                ->grade   ($this->post['gradeID'])
                ->lectures($this->post['lectures'])
                ->practice($this->post['practice'])
                ->labs    ($this->post['labs'])
                ->type    ($this->post['type'])
                ->create();

            if ($this->post['bonus'] == "true")
                Model_Map::AddModuleBonus($this->user['TeacherID'], $discipline->ID);

            $this->data = ['success' => true, 'ID' => $discipline->ID];
        } catch (Exception $e) {
            $this->data = ['success' => false, 'message' => $e->getMessage()];
        }
    }
}