TeacherFormService.php 2.31 KB
Newer Older
Aspasia Katsi's avatar
Aspasia Katsi committed
1 2 3 4 5 6 7 8 9 10
<?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\TeacherForm\Service;
11

Aspasia Katsi's avatar
Aspasia Katsi committed
12 13
use RedBeanPHP\OODBBean;
use RedBeanPHP\R;
14 15
use GrEduLabs\UniversityForm\Service\UniversityFormService;

Aspasia Katsi's avatar
Aspasia Katsi committed
16 17
class TeacherFormService implements TeacherFormServiceInterface
{
18

Aspasia Katsi's avatar
Aspasia Katsi committed
19 20
    public function submit(array $data)
    {
21
        $appForm = R::dispense('volunteerteachers');
Aspasia Katsi's avatar
Aspasia Katsi committed
22
//        $appForm->id                  = $data['id'];
23 24 25 26 27 28 29 30 31 32
        $appForm->name = $data['name'];
        $appForm->surname = $data['surname'];
        $appForm->eidikothta = $data['eidikothta'];
        $appForm->arithmitroou = $data['arithmitroou'];
        $appForm->email = $data['email'];
        $appForm->telef = trim($data['telef']);
        $appForm->school = $data['school'];
        $appForm->schooltelef = trim($data['schooltelef']);
        $appForm->projectdescription = $data['projectdescription'];
        $appForm->comments = $data['comments'];
Aspasia Katsi's avatar
Aspasia Katsi committed
33 34 35 36 37 38 39 40 41 42
        R::store($appForm);
        return $appForm;
    }

    public function getBranches()
    {
        return array_map(function ($branch) {
            return $branch->export();
        }, R::findAll('branch', 'ORDER BY name ASC'));
    }
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73

    /**
     * 
     * @param OODBBean $bean the form bean
     * @return array
     */
    private function exportApplicationForm(OODBBean $bean)
    {
        $form = $bean->export();

        $form['projectdescription'] = UniversityFormService::recomposeProjects($form['projectdescription']);

        return $form;
    }

    /**
     * Get all the university volunteer submissions 
     * 
     * @return array The exported bean info from retrieved data
     */
    public function findAll()
    {
        $forms = R::getAll('SELECT `volunteerteachers`.*, `branch`.`name` AS `eidikothta_name` '
                . 'FROM `volunteerteachers` JOIN `branch` ON (`volunteerteachers`.`eidikothta` = `branch`.`id`) '
                . 'ORDER BY `id` DESC');
        $beanForms = R::convertToBeans('volunteerteachers', $forms);

        return array_map(function ($form) {
            return $this->exportApplicationForm($form);
        }, $beanForms);
    }
Aspasia Katsi's avatar
Aspasia Katsi committed
74
}