Skip to content

Commit

Permalink
automatic shifts
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrodevog committed Oct 14, 2023
1 parent 6d76125 commit 5e11835
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public function editAction()
public function scheduleAction()
{
$form = $this->getForm('cudi_sale_session_opening-hour_schedule');
$shiftForm = $this->getForm('shift_shift_schedule');
$registrationForm = $this->getForm('shift_registration-shift_schedule');

$now = (new DateTime())->format('d/m/Y H:i');
Expand All @@ -147,6 +148,7 @@ public function scheduleAction()
$startDate = $split[2] . ' ' . $startHour;
$endDate = $split[2] . ' ' . $endHour;

// OPENING HOURS
$data = array();
$data["start_date"] = $startDate;
$data["end_date"] = $endDate;
Expand All @@ -155,6 +157,32 @@ public function scheduleAction()
$form->getHydrator()->hydrate($data)
);

// SHIFTS
$reward = $startHour == '12:30'? 2: 1;

$shift = array(
'name' => 'Boekjes verkopen',
'description' => 'Kom helpen met boeken verkopen. Leer nieuwe mensen kennen en kom de sfeer opsnuiven.
(Er is altijd begeleiding dus wees niet bang als je voor de eerste keer komt ;))',
'manager' => false,
'unit' => 1,
'event' => '',
'location' => 1,
'start_date' => $startDate,
'end_date' => $endDate,
'nb_responsibles' => 1,
'nb_volunteers' => $formData['volunteers_' . $startHour . '-' . $endHour . '_' . $split[2]],
'nb_volunteers_min' => $formData['volunteers-min_' . $startHour . '-' . $endHour . '_' . $split[2]],
'reward' => $reward,
'handled_on_event' => false,
'ticket_needed' => false,
'points' => 0,
);
$this->getEntityManager()->persist(
$shiftForm->getHydrator()->hydrate($shift)
);

// REGISTRATION SHIFTS
$count = 0;
$startHour_ = $startHour; // creating dummy variable that is updated
$signoutDate = (DateTime::createFromFormat('d/m/Y', $split[2]))->modify('+1 day')->format('d/m/Y') . ' 00:00';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,108 @@ public function init()
'type' => 'checkbox',
'name' => 'interval_12:30-14:00_' . $day->format('d/m/Y'),
'label' => $day->format('l') . ' 12:30 - 14:00',
'required' => true,
'attributes' => array(
'id' => 'interval_12:30-14:00_' . $day->format('d/m/Y'),
),
)
);

$this->add(
array(
'type' => 'text',
'name' => 'volunteers_12:30-14:00_' . $day->format('d/m/Y'),
'label' => 'Volunteers',
'attributes' => array(
'value' => '0',
),
'options' => array(
'input' => array(
'filters' => array(
array('name' => 'StringTrim'),
),
'validators' => array(
array('name' => 'Int'),
),
),
),
)
);

$this->add(
array(
'type' => 'text',
'name' => 'volunteers-min_12:30-14:00_' . $day->format('d/m/Y'),
'label' => 'Min. Volunteers',
'attributes' => array(
'value' => '0',
),
'options' => array(
'input' => array(
'filters' => array(
array('name' => 'StringTrim'),
),
'validators' => array(
array('name' => 'Int'),
),
),
),
)
);

$this->add(
array(
'type' => 'checkbox',
'name' => 'interval_18:00-19:00_' . $day->format('d/m/Y'),
'label' => $day->format('l') . ' 18:00 - 19:00',
'label' => '18:00 - 19:00',
'required' => true,
'attributes' => array(
'id' => 'interval_18:00-19:00_' . $day->format('d/m/Y'),
),
)
);

$this->add(
array(
'type' => 'text',
'name' => 'volunteers_18:00-19:00_' . $day->format('d/m/Y'),
'label' => 'Volunteers',
'attributes' => array(
'value' => '0',
),
'options' => array(
'input' => array(
'filters' => array(
array('name' => 'StringTrim'),
),
'validators' => array(
array('name' => 'Int'),
),
),
),
)
);

$this->add(
array(
'type' => 'text',
'name' => 'volunteers-min_18:00-19:00_' . $day->format('d/m/Y'),
'label' => 'Min. Volunteers',
'attributes' => array(
'value' => '0',
),
'options' => array(
'input' => array(
'filters' => array(
array('name' => 'StringTrim'),
),
'validators' => array(
array('name' => 'Int'),
),
),
),
)
);
}

$this->addSubmit('Add', 'clock_add');
Expand Down
14 changes: 14 additions & 0 deletions module/ShiftBundle/Form/Admin/Shift/Schedule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace ShiftBundle\Form\Admin\Shift;

/**
* Add multiple registrations at once; only made to get the hydrator in OpeningHourController
*
* @author Pedro Devogelaere <[email protected]>
*/
class Schedule extends \CommonBundle\Component\Form\Admin\Form
{
protected $hydrator = 'ShiftBundle\Hydrator\Shift';
}

10 changes: 7 additions & 3 deletions module/ShiftBundle/Hydrator/Shift.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,13 @@ protected function doHydrate(array $data, $object = null)
->setEndDate(self::loadDateTime($data['end_date']));
}

$manager = $this->getEntityManager()
->getRepository('CommonBundle\Entity\User\Person\Academic')
->findOneById($data['manager']['id']);
if ($data['manager']) {
$manager = $this->getEntityManager()
->getRepository('CommonBundle\Entity\User\Person\Academic')
->findOneById($data['manager']['id']);
} else {
$manager = $this->getPersonEntity();
}

$editRoles = array();
if (isset($data['edit_roles'])) {
Expand Down

0 comments on commit 5e11835

Please sign in to comment.