Re: Compare 2 date in cake3
exactly. glad that it workd Le 2 sept. 2015 16:22, "lorenzoshake" a écrit : > > > Il giorno mercoledì 2 settembre 2015 12:17:42 UTC+2, Anthony GRASSIOT ha > scritto: >> >> And that's normal and make sense because $calendar->start_date and >> $calendar->end_date are the only fields for which you use setters... >> >>> >>> > ok, solved ;) > just format date in array data first to process it in patchEntity : > > if(isset($this->request->data['start_date']) && > trim($this->request->data['start_date']) != '') > { > $calendar_data['start_date'] = implode("-",array_reverse(explode("/", > $this->request->data['start_date']))); > } > if(isset($this->request->data['end_date']) && > trim($this->request->data['end_date']) != '') > { > $calendar_data['end_date'] = implode("-",array_reverse(explode("/", > $this->request->data['end_date']))); > } > > $calendar = $this->Calendars->patchEntity($calendar, $calendar_data); > > -- > Like Us on FaceBook https://www.facebook.com/CakePHP > Find us on Twitter http://twitter.com/CakePHP > > --- > You received this message because you are subscribed to the Google Groups > "CakePHP" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to cake-php+unsubscr...@googlegroups.com. > To post to this group, send email to cake-php@googlegroups.com. > Visit this group at http://groups.google.com/group/cake-php. > For more options, visit https://groups.google.com/d/optout. > -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/d/optout.
Re: Compare 2 date in cake3
Il giorno mercoledì 2 settembre 2015 12:17:42 UTC+2, Anthony GRASSIOT ha scritto: > > And that's normal and make sense because $calendar->start_date and > $calendar->end_date are the only fields for which you use setters... > >> >> ok, solved ;) just format date in array data first to process it in patchEntity : if(isset($this->request->data['start_date']) && trim($this->request->data['start_date']) != '') { $calendar_data['start_date'] = implode("-",array_reverse(explode("/", $this->request->data['start_date']))); } if(isset($this->request->data['end_date']) && trim($this->request->data['end_date']) != '') { $calendar_data['end_date'] = implode("-",array_reverse(explode("/", $this->request->data['end_date']))); } $calendar = $this->Calendars->patchEntity($calendar, $calendar_data); -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/d/optout.
Re: Compare 2 date in cake3
And that's normal and make sense because $calendar->start_date and $calendar->end_date are the only fields for which you use setters... Le 2 sept. 2015 12:07, "lorenzoshake" a écrit : > > > Il giorno mercoledì 2 settembre 2015 11:24:15 UTC+2, Anthony GRASSIOT ha > scritto: >> >> That what I thought. Validation is not applied if you set the value >> directly with a setter like you does. You need to use patchEntity(). >> >> >> i think so, but the other validation rules works fine! > > -- > Like Us on FaceBook https://www.facebook.com/CakePHP > Find us on Twitter http://twitter.com/CakePHP > > --- > You received this message because you are subscribed to the Google Groups > "CakePHP" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to cake-php+unsubscr...@googlegroups.com. > To post to this group, send email to cake-php@googlegroups.com. > Visit this group at http://groups.google.com/group/cake-php. > For more options, visit https://groups.google.com/d/optout. > -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/d/optout.
Re: Compare 2 date in cake3
Il giorno mercoledì 2 settembre 2015 11:24:15 UTC+2, Anthony GRASSIOT ha scritto: > > That what I thought. Validation is not applied if you set the value > directly with a setter like you does. You need to use patchEntity(). > > > i think so, but the other validation rules works fine! -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/d/optout.
Re: Compare 2 date in cake3
That what I thought. Validation is not applied if you set the value directly with a setter like you does. You need to use patchEntity(). Le 2 sept. 2015 10:29, "lorenzoshake" a écrit : > > > > Il giorno mercoledì 2 settembre 2015 10:20:53 UTC+2, Anthony GRASSIOT ha scritto: >> >> Could you show your controller finction ? >> these validation are used when using newEntity() or patchEntities'), not save(). >> > > the other validation condition works fine ; here the method: > > public function validationDefault(Validator $validator) > { > $validator > ->add('id', 'valid', ['rule' => 'numeric']) > ->allowEmpty('id', 'create') > ->add('social_user_id', 'valid', ['rule' => 'numeric']) > ->allowEmpty('social_user_id') > ->allowEmpty('name') > ->allowEmpty('address') > ->allowEmpty('city') > ->add('lat', 'valid', ['rule' => 'numeric']) > ->allowEmpty('lat') > ->add('lng', 'valid', ['rule' => 'numeric']) > ->allowEmpty('lng') > ->add('start_date', 'valid', ['rule' => 'date']) > ->add('end_date', [ > 'valid'=> ['rule' => 'date'] , > 'compare' => [ > 'rule' => function ($value, $context) { > $date_end = Time::createFromFormat('d/m/Y',$value); > $date_start = Time::createFromFormat('d/m/Y',$context['data']['start_date']); > return ($date_start < $date_end); > } > ] > ] > > ); > > return $validator; > } > > In controller: > > $calendar = $this->Calendars->patchEntity($calendar, $calendar_data); > . > $calendar->start_date = implode("-",array_reverse(explode("/", $this->request->data['start_date']))); > $calendar->end_date = implode("-",array_reverse(explode("/", $this->request->data['end_date']))); > ... > if(!$this->Calendars->save($calendar)) > ... > > -- > Like Us on FaceBook https://www.facebook.com/CakePHP > Find us on Twitter http://twitter.com/CakePHP > > --- > You received this message because you are subscribed to the Google Groups "CakePHP" group. > To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. > To post to this group, send email to cake-php@googlegroups.com. > Visit this group at http://groups.google.com/group/cake-php. > For more options, visit https://groups.google.com/d/optout. -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/d/optout.
Re: Compare 2 date in cake3
Il giorno mercoledì 2 settembre 2015 10:20:53 UTC+2, Anthony GRASSIOT ha scritto: > > Could you show your controller finction ? > these validation are used when using newEntity() or patchEntities'), not > save(). > > the other validation condition works fine ; here the method: public function validationDefault(Validator $validator) { $validator ->add('id', 'valid', ['rule' => 'numeric']) ->allowEmpty('id', 'create') ->add('social_user_id', 'valid', ['rule' => 'numeric']) ->allowEmpty('social_user_id') ->allowEmpty('name') ->allowEmpty('address') ->allowEmpty('city') ->add('lat', 'valid', ['rule' => 'numeric']) ->allowEmpty('lat') ->add('lng', 'valid', ['rule' => 'numeric']) ->allowEmpty('lng') ->add('start_date', 'valid', ['rule' => 'date']) ->add('end_date', [ 'valid'=> ['rule' => 'date'] , 'compare' => [ 'rule' => function ($value, $context) { $date_end = Time::createFromFormat('d/m/Y',$value); $date_start = Time::createFromFormat('d/m/Y',$context['data']['start_date']); return ($date_start < $date_end); } ] ] ); return $validator; } In controller: $calendar = $this->Calendars->patchEntity($calendar, $calendar_data); . $calendar->start_date = implode("-",array_reverse(explode("/", $this->request->data['start_date']))); $calendar->end_date = implode("-",array_reverse(explode("/", $this->request->data['end_date']))); ... if(!$this->Calendars->save($calendar)) ... -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/d/optout.
Re: Compare 2 date in cake3
Could you show your controller finction ? these validation are used when using newEntity() or patchEntities'), not save(). 2015-09-02 10:15 GMT+02:00 Chetan Varshney : > my solution did not work for you? > > On Wed, Sep 2, 2015 at 1:43 PM, lorenzoshake > wrote: > >> >> >> Il giorno mercoledì 2 settembre 2015 02:24:34 UTC+2, Anthony GRASSIOT ha >> scritto: >>> >>> 'custom',['rule' => [$this, 'checkDate']] >>> >>> this doesn't seems to be a correct syntax... Why don't you use one of >>> the proposed solution ? >>> >>> $value->gte raise errors ( is a query method); the strange think is that: >>> >>> ->add('end_date', [ >> 'valid'=> ['rule' => 'date'] , >> 'compare' => [ >> 'rule' => function ($value, $context) { >> $date_end = Time::createFromFormat('d/m/Y',$value); >> $date_start = >> Time::createFromFormat('d/m/Y',$context['data']['start_date']); >> >>// return ($date_start < $date_end); >> let's test! >> return false; >> } >> ] >> ] >> >> ); >> >> as you can see i return always false ( just for testing) but the rule >> doesn't work :( >> >> -- >> Like Us on FaceBook https://www.facebook.com/CakePHP >> Find us on Twitter http://twitter.com/CakePHP >> >> --- >> You received this message because you are subscribed to the Google Groups >> "CakePHP" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to cake-php+unsubscr...@googlegroups.com. >> To post to this group, send email to cake-php@googlegroups.com. >> Visit this group at http://groups.google.com/group/cake-php. >> For more options, visit https://groups.google.com/d/optout. >> > > > > -- > Chetan Varshney > Ektanjali Softwares Pvt Ltd > > -- > Like Us on FaceBook https://www.facebook.com/CakePHP > Find us on Twitter http://twitter.com/CakePHP > > --- > You received this message because you are subscribed to the Google Groups > "CakePHP" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to cake-php+unsubscr...@googlegroups.com. > To post to this group, send email to cake-php@googlegroups.com. > Visit this group at http://groups.google.com/group/cake-php. > For more options, visit https://groups.google.com/d/optout. > -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/d/optout.
Re: Compare 2 date in cake3
my solution did not work for you? On Wed, Sep 2, 2015 at 1:43 PM, lorenzoshake wrote: > > > Il giorno mercoledì 2 settembre 2015 02:24:34 UTC+2, Anthony GRASSIOT ha > scritto: >> >> 'custom',['rule' => [$this, 'checkDate']] >> >> this doesn't seems to be a correct syntax... Why don't you use one of the >> proposed solution ? >> >> $value->gte raise errors ( is a query method); the strange think is that: >> >> ->add('end_date', [ > 'valid'=> ['rule' => 'date'] , > 'compare' => [ > 'rule' => function ($value, $context) { > $date_end = Time::createFromFormat('d/m/Y',$value); > $date_start = > Time::createFromFormat('d/m/Y',$context['data']['start_date']); > >// return ($date_start < $date_end); > let's test! > return false; > } > ] > ] > > ); > > as you can see i return always false ( just for testing) but the rule > doesn't work :( > > -- > Like Us on FaceBook https://www.facebook.com/CakePHP > Find us on Twitter http://twitter.com/CakePHP > > --- > You received this message because you are subscribed to the Google Groups > "CakePHP" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to cake-php+unsubscr...@googlegroups.com. > To post to this group, send email to cake-php@googlegroups.com. > Visit this group at http://groups.google.com/group/cake-php. > For more options, visit https://groups.google.com/d/optout. > -- Chetan Varshney Ektanjali Softwares Pvt Ltd -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/d/optout.
Re: Compare 2 date in cake3
Il giorno mercoledì 2 settembre 2015 02:24:34 UTC+2, Anthony GRASSIOT ha scritto: > > 'custom',['rule' => [$this, 'checkDate']] > > this doesn't seems to be a correct syntax... Why don't you use one of the > proposed solution ? > > $value->gte raise errors ( is a query method); the strange think is that: > > ->add('end_date', [ 'valid'=> ['rule' => 'date'] , 'compare' => [ 'rule' => function ($value, $context) { $date_end = Time::createFromFormat('d/m/Y',$value); $date_start = Time::createFromFormat('d/m/Y',$context['data']['start_date']); // return ($date_start < $date_end); let's test! return false; } ] ] ); as you can see i return always false ( just for testing) but the rule doesn't work :( -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/d/optout.
Re: Compare 2 date in cake3
'custom',['rule' => [$this, 'checkDate']] this doesn't seems to be a correct syntax... Why don't you use one of the proposed solution ? Le 1 sept. 2015 10:46, "lorenzoshake" a écrit : Il giorno martedì 1 settembre 2015 10:44:40 UTC+2, lorenzoshake ha scritto: > > > > Il giorno lunedì 31 agosto 2015 18:34:37 UTC+2, Anthony GRASSIOT ha > scritto: >> >> Maybe something like: >> >> 'compare' => [ >> 'rule' => function ($value, $context) { >> return >> $value->gte($context['data']['start_date']); >> } >> >>> >>> now the check was executed: > public function validationDefault(Validator $validator) > { > $validator > ->add('id', 'valid', ['rule' => 'numeric']) > ->allowEmpty('id', 'create') > ->add('social_user_id', 'valid', ['rule' => 'numeric']) > ->allowEmpty('social_user_id') > ->allowEmpty('name') > ->allowEmpty('address') > ->allowEmpty('city') > ->add('lat', 'valid', ['rule' => 'numeric']) > ->allowEmpty('lat') > ->add('lng', 'valid', ['rule' => 'numeric']) > ->allowEmpty('lng') > ->add('start_date', 'valid', ['rule' => 'date']) > ->add('end_date', > 'custom',['rule' => [$this, 'checkDate']] > ); > > return $validator; > } > but the record was always saved ( checkDate return always false for test) -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/d/optout. -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/d/optout.
Re: Compare 2 date in cake3
Il giorno martedì 1 settembre 2015 10:44:40 UTC+2, lorenzoshake ha scritto: > > > > Il giorno lunedì 31 agosto 2015 18:34:37 UTC+2, Anthony GRASSIOT ha > scritto: >> >> Maybe something like: >> >> 'compare' => [ >> 'rule' => function ($value, $context) { >> return >> $value->gte($context['data']['start_date']); >> } >> >>> >>> now the check was executed: > public function validationDefault(Validator $validator) > { > $validator > ->add('id', 'valid', ['rule' => 'numeric']) > ->allowEmpty('id', 'create') > ->add('social_user_id', 'valid', ['rule' => 'numeric']) > ->allowEmpty('social_user_id') > ->allowEmpty('name') > ->allowEmpty('address') > ->allowEmpty('city') > ->add('lat', 'valid', ['rule' => 'numeric']) > ->allowEmpty('lat') > ->add('lng', 'valid', ['rule' => 'numeric']) > ->allowEmpty('lng') > ->add('start_date', 'valid', ['rule' => 'date']) > ->add('end_date', > 'custom',['rule' => [$this, 'checkDate']] > ); > > return $validator; > } > but the record was always saved ( checkDate return always false for test) -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/d/optout.
Re: Compare 2 date in cake3
Il giorno lunedì 31 agosto 2015 18:34:37 UTC+2, Anthony GRASSIOT ha scritto: > > Maybe something like: > > 'compare' => [ > 'rule' => function ($value, $context) { > return $value->gte($context['data']['start_date']); > } > >> >> now the check was executed: public function validationDefault(Validator $validator) { $validator ->add('id', 'valid', ['rule' => 'numeric']) ->allowEmpty('id', 'create') ->add('social_user_id', 'valid', ['rule' => 'numeric']) ->allowEmpty('social_user_id') ->allowEmpty('name') ->allowEmpty('address') ->allowEmpty('city') ->add('lat', 'valid', ['rule' => 'numeric']) ->allowEmpty('lat') ->add('lng', 'valid', ['rule' => 'numeric']) ->allowEmpty('lng') ->add('start_date', 'valid', ['rule' => 'date']) ->add('end_date', 'custom',['rule' => [$this, 'checkDate']] ); return $validator; } -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/d/optout.
Re: Compare 2 date in cake3
You can do like this. ->add('end_date', [ 'mustValid'=>[ 'rule'=>'checkForEndDate', 'provider'=>'table', 'message'=>__('End date should be greater than start date') ] ]) and define following function in model table (in same class) public function checkForEndDate($value, $context) { if(!empty($value) && !empty($context['data']['start_date'])) { // may be you need to play with time object to compare dates if($value <= $context['data']['start_date']) { return false; } } return true; } On Mon, Aug 31, 2015 at 9:53 PM, lorenzoshake wrote: > I've been tried with: > > $validator ->add('end_date', [ > 'valid'=> ['rule' => 'date'] , > 'compare' =>['rule' => ['comparison', '>' ,'start_date']] > ] > ); > > but doesn't work; > > how to validate start_date and end_date ( end must be greater than > start_date) ? > > -- > Like Us on FaceBook https://www.facebook.com/CakePHP > Find us on Twitter http://twitter.com/CakePHP > > --- > You received this message because you are subscribed to the Google Groups > "CakePHP" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to cake-php+unsubscr...@googlegroups.com. > To post to this group, send email to cake-php@googlegroups.com. > Visit this group at http://groups.google.com/group/cake-php. > For more options, visit https://groups.google.com/d/optout. > -- Chetan Varshney Ektanjali Softwares Pvt Ltd -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/d/optout.
Re: Compare 2 date in cake3
Maybe something like: 'compare' => [ 'rule' => function ($value, $context) { return $value->gte($context['data']['start_date']); } Le 31 août 2015 18:24, "lorenzoshake" a écrit : > I've been tried with: > > $validator ->add('end_date', [ > 'valid'=> ['rule' => 'date'] , > 'compare' =>['rule' => ['comparison', '>' ,'start_date']] > ] > ); > > but doesn't work; > > how to validate start_date and end_date ( end must be greater than > start_date) ? > > -- > Like Us on FaceBook https://www.facebook.com/CakePHP > Find us on Twitter http://twitter.com/CakePHP > > --- > You received this message because you are subscribed to the Google Groups > "CakePHP" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to cake-php+unsubscr...@googlegroups.com. > To post to this group, send email to cake-php@googlegroups.com. > Visit this group at http://groups.google.com/group/cake-php. > For more options, visit https://groups.google.com/d/optout. > -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/d/optout.