Пример #1
0
 public function get_by_teacher($user_id)
 {
     $user = Model_User::find($user_id);
     $success = false;
     if (!$user) {
         return $this->error(['Cannot find user.']);
     }
     $data = null;
     if ($user->isRoleTeacher()) {
         $data = Model_Syllabus::find('all', ['related' => ['subject' => ['where' => ['user_id' => $user->id]]]]);
     } else {
         if ($user->isRoleStudent()) {
             $data = [];
         }
     }
     if ($data) {
         $success = true;
     }
     return $this->response(['data' => $data, 'success' => $success]);
 }
Пример #2
0
 public function action_delete($id = null)
 {
     $where = ['id' => $id];
     if (Model_User::is_current_user('teacher')) {
         $where['subject.user_id'] = Auth::get('id');
     }
     if ($syllabus = Model_Syllabus::find('first', ['where' => $where, 'related' => ['subject']])) {
         $syllabus->delete();
         Session::set_flash('success', e('Deleted syllabus #' . $id));
     } else {
         Session::set_flash('error', e('Could not delete syllabus #' . $id));
     }
     Response::redirect('site/syllabuses');
 }