StaffService.php 1.63 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php
/**
 * gredu_labs
 * 
 * @link https://github.com/eellak/gredu_labs for the canonical source repository
 * @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
 * @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
 */

namespace GrEduLabs\Schools\Service;

use RedBeanPHP\R;

class StaffService implements StaffServiceInterface
{
    protected $schoolService;
    public function __construct(SchoolServiceInterface $schoolService)
    {
        $this->schoolService = $schoolService;
    }

    public function createTeacher(array $data)
    {
24
        unset($data['id']);
25
        $teacher  = R::dispense('teacher');
26
27
28
        $required = ['school_id', 'name','email', 'surname', 'telephone',
                     'position', 'branch'];
        $data['school_id'] = 1;
29
30
31
32
33
34
35
        foreach ($required as $value) {
            if (array_key_exists($value, $data)) {
                $teacher[$value] = $data[$value];
            } else {
                return -1;
            }
        }
Georgios Tsakalos's avatar
Georgios Tsakalos committed
36
        $id = R::store($teacher);
37
38
39
        return $id;
    }

40
41
42
43
44
45
46
47
48
    public function updateTeacher(array $data, $id){
        $teacher = R::load('teacher', $id);
        foreach ($data as $key => $value){
            $teacher[$key] = $value;
        }
        $id = R::store($teacher);
        return $id;
    }

49
50
51
52
53
54
55
56
57
58
59
60
61
    public function getTeacherById($id)
    {
        $teacher = R::load('teacher', $id);
        return $teacher;
    }

    public function getTeachersBySchoolId($id)
    {
        $school   = $this->schoolService->getSchool($id);
        $teachers = $school->ownTeacher;
        return $teachers;
    }
}