Commit 66a3e32b authored by Georgios Tsakalos's avatar Georgios Tsakalos

add some services with interfaces

parent 03aa0d64
<?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\School\Service;
use RedBeanPHP\R;
class LabService implements LabServiceInterface
{
protected $schoolService;
protected $staffService;
public function __construct(
SchoolServiceInterface $schoolService,
StaffServiceInterface $staffService
) {
$this->schoolService = $schoolService;
$this->staffService = $staffService;
}
public function createLab(array $data)
{
$lab = R::dispense('lab');
$required = ['name', 'school', 'area'];
foreach ($required as $value){
if (array_key_exists($value, $data)){
if ($value == 'school')
{
$school_id = $data[$value];
}
else
{
$lab[$value] = $data[$value];
}
}
else
{
return -1;
}
}
if (array_key_exists('teacher', $data)) {
$teacher_id = $data['teacher'];
}
$school = $this->schoolService->getSchool($school_id);
$teacher = $this->staffService->getTeacherById($teacher_id);
$lab->school = $school;
$lab->teacher = $teacher;
$id = R::store($lab);
return $id;
}
public function getLabById($id)
{
$lab = R::load('lab', $id);
return $lab;
}
public function getLabsBySchoolId($id)
{
$school = $this->schoolService->getSchool($id);
$labs = $school->ownLab;
return $labs;
}
}
<?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\DBService;
interface LabServiceInterface
{
public function createLab(array $data);
public function getLabById($id);
public function getLabsBySchoolId($id);
}
<?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 SchoolService implements SchoolServiceInterface
{
public function createSchool(array $data)
{
$school = R::dispense('school');
$required = ['registryNo', 'educationLevel', 'unitType', 'category', 'eduAdmin', 'regionEduAdmin'];
$optional = ['streetAddress', 'phoneNumber', 'faxNumber', 'email'];
foreach ($required as $value) {
if (array_key_exists($value, $data)) {
$school[$value] = $data[$value];
} else {
return -1;
}
}
foreach ($optional as $value) {
if (array_key_exists($value, $data)) {
$school[$value] = $data[$value];
} else {
$school[$value] = '';
}
}
$id = R::store($school);
return $id;
}
public function getSchool($id)
{
$school = R::load('school', $id);
return $school;
}
}
<?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;
interface SchoolServiceInterface
{
public function createSchool(array $data);
public function getSchool($id);
}
<?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)
{
$teacher = R::dispense('teacher');
$required = ['school_id', 'name', 'surname', 'phoneNumber', 'labSupervisor', 'schoolPrincipal'];
$optional = ['speciality', 'email'];
foreach ($required as $value) {
if (array_key_exists($value, $data)) {
$teacher[$value] = $data[$value];
} else {
return -1;
}
}
foreach ($optional as $value) {
if (array_key_exists($value, $data)) {
$teacher[$value] = $data[$value];
} else {
$$value = '';
}
}
$school = $this->schoolService->getSchool($teacher['school_id']);
$teacher->school = $school;
$id = R::store($teacher);
return $id;
}
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;
}
}
<?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;
interface StaffServiceInterface
{
public function createTeacher(array $data);
public function getTeacherById($id);
public function getTeachersBySchoolId($id);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment