コード例 #1
0
ファイル: UserController.php プロジェクト: DogFox/yalms
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $phone = trim(Request::get('phone'));
     if (empty($phone)) {
         return ['result' => false, 'message' => 'Data has not been entered'];
     }
     $countPhones = User::wherePhone($phone)->count();
     if ($countPhones > 0) {
         return ['result' => false, 'message' => 'This user already exists'];
     }
     $user = new User();
     $user->first_name = Input::get('first_name');
     $user->middle_name = Input::get('middle_name');
     $user->last_name = Input::get('last_name');
     $user->email = Input::get('email');
     $user->phone = Input::get('phone');
     $user->password = Input::get('password');
     $user->save();
     $admin = new UserAdmin();
     $admin->user_id = $user->id;
     $admin->save();
     $teacher = new UserTeacher();
     $teacher->user_id = $user->id;
     $teacher->save();
     $student = new UserStudent();
     $student->user_id = $user->id;
     $student->save();
     return ['result' => true, 'message' => 'This user is saved'];
 }
コード例 #2
0
ファイル: UserTest.php プロジェクト: DogFox/yalms
 public function setUp()
 {
     parent::setUp();
     DB::statement('SET FOREIGN_KEY_CHECKS=0;');
     UserAdmin::truncate();
     UserStudent::truncate();
     UserTeacher::truncate();
     User::truncate();
     DB::statement('SET FOREIGN_KEY_CHECKS=1;');
 }
コード例 #3
0
ファイル: UserDeleteTest.php プロジェクト: fintech-fab/yalms
 /**
  * Удаление пользователя и очистка его профилей, по REST запросу
  */
 public function testUserDelete()
 {
     $this->assertEquals(1, UserAdmin::find($this->userId)->enabled);
     $this->assertEquals(1, UserStudent::find($this->userId)->enabled);
     $this->assertEquals(1, UserTeacher::find($this->userId)->enabled);
     $this->call('DELETE', "api/v1/user/{$this->userId}");
     $this->assertTrue(empty(User::find($this->userId)));
     $this->assertEquals(0, UserAdmin::find($this->userId)->enabled);
     $this->assertEquals(0, UserStudent::find($this->userId)->enabled);
     $this->assertEquals(0, UserTeacher::find($this->userId)->enabled);
 }
コード例 #4
0
 /**
  * Изменение профиля "учитель" по REST запросу
  */
 public function testUserTeacherUpdate()
 {
     $this->assertEquals(0, UserTeacher::find($this->userId)->enabled);
     $this->call('PUT', "api/v1/teacher/{$this->userId}", ['enabled' => 1]);
     $this->assertEquals(1, UserTeacher::find($this->userId)->enabled);
 }
コード例 #5
0
ファイル: UserComponent.php プロジェクト: fintech-fab/yalms
 /**
  *  Обновление данных профиля пользователя "учитель", с указанным id
  *
  * @param  int $id
  *
  * @return bool
  * @throws \ErrorException
  */
 public function updateTeacher($id)
 {
     $teacher = UserTeacher::findOrFail($id);
     if (!$this->validateProfile()) {
         return self::FAILED_VALIDATION;
     }
     $teacher->enabled = $this->input['enabled'];
     if (!$teacher->save()) {
         throw new \ErrorException('Failed to save data');
     }
     $this->message = 'Данные успешно сохранены';
     return self::RESULT_OK;
 }
コード例 #6
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int $id
  *
  * @return Response
  */
 public function edit($id)
 {
     $user = User::whereEnabled(true)->findOrFail($id, array('id', 'first_name', 'middle_name', 'last_name'));
     return Response::json(array('teacher' => array('id' => $id, 'enabled' => UserTeacher::find($id)->enabled, 'user' => $user), 'edit_fields' => array('enabled' => 'Назначить учителем'), 'required_fields' => array('enabled')));
 }