Sunday, 15 June 2014

php - ZF2 Form validation - non-overlapping dates and times -



php - ZF2 Form validation - non-overlapping dates and times -

i'm working on meeting scheme using zf2. utilize 2 models this, called 'meeting' , 'meetingtime'. meeting has one-to-many relationship meetingtime.

meeting contains next fields related dates/times:

public $slotduration; public $meetingtimes;

slotduration time of each meeting in minutes. meetingtimes contains meetingtime objects.

meetingtime has next fields related dates/times:

public $slots; public $datetimestart;

slots amount of meetings should in 'block' of meetings. datetimestart self-explanatory. determine end time of meeting, take slot duration , multiply amount of slots in meetingtime object. since each block of meetings may end @ different time, done in meetingtime object. result converted datetime object.

in creation form, dynamically add together new fieldsets meetingtimes if user thinks necessary. our business model made flexible possible, user may have pauses between meetings or stretch out on multiple days if need be. each single fieldset contains html5 datetime element start date , time, html5 number element slots , selectbox room reserved. these fieldsets enclosed in fieldset, enclosed in form.

now, question is, concerning validation, how create sure none of these times overlap (they have consecutive)? create objects in controller before sending info database, maybe might of use. hope can utilize zf2 validation pipeline this, if isn't possible, i'm open other solution.

edit: form looks this, way. http://puu.sh/9yjri/12422b8231.png

i can't write without way more info you're going need write custom validator bit this:

locationavailabilityvalidator.php

<?php namespace meetingmodulethang\validator; utilize zend\validator\abstractvalidator; class locationavailabilityvalidator extends abstractvalidator /** * (non-phpdoc) * @see zend\validator.validatorinterface::isvalid() */ public function isvalid($value, $context=array()) { //get location object db name $location = $this->getobjectmanager()->findbyname('\application\entity\location', $context['location']); //get datetime of end ridiculous // don't know metrics , types using $endtime = $value + $slotduration; $meetingstartdatetime = datetime::createfromformat($yourformat, $value); $meetinenddatetime = datetime::createfromformat($yourformat, $endtime); homecoming $location->isavailablebetween($meetingstart, $meetingend); }

then can check in location method if slots exist object in db

php html5 validation zend-framework2

No comments:

Post a Comment