@@ -34,7 +34,7 @@ trait JsonQueriable
34
34
protected $ _conditions = [];
35
35
36
36
/**
37
- * @var bool
37
+ * @var bool
38
38
*/
39
39
protected $ _isProcessed = false ;
40
40
@@ -67,6 +67,9 @@ trait JsonQueriable
67
67
'endswith ' => 'endsWith ' ,
68
68
'match ' => 'match ' ,
69
69
'contains ' => 'contains ' ,
70
+ 'dates ' => 'dates ' ,
71
+ 'month ' => 'month ' ,
72
+ 'year ' => 'year ' ,
70
73
];
71
74
72
75
@@ -169,7 +172,7 @@ public function isJson($value, $return_map = false)
169
172
170
173
return (json_last_error () == JSON_ERROR_NONE ) ? ($ return_map ? $ data : true ) : json_last_error_msg ();
171
174
}
172
-
175
+
173
176
/**
174
177
* prepare data for result
175
178
*
@@ -473,6 +476,48 @@ public function whereContains($key, $value)
473
476
return $ this ;
474
477
}
475
478
479
+ /**
480
+ * make WHERE DATE clause
481
+ *
482
+ * @param $key string
483
+ * @param $value string
484
+ * @return $this
485
+ */
486
+ public function whereDate ($ key , $ value )
487
+ {
488
+ $ this ->where ($ key , 'dates ' , $ value );
489
+
490
+ return $ this ;
491
+ }
492
+
493
+ /**
494
+ * make WHERE month clause
495
+ *
496
+ * @param $key string
497
+ * @param $value string
498
+ * @return $this
499
+ */
500
+ public function whereMonth ($ key , $ value )
501
+ {
502
+ $ this ->where ($ key , 'month ' , $ value );
503
+
504
+ return $ this ;
505
+ }
506
+
507
+ /**
508
+ * make WHERE Year clause
509
+ *
510
+ * @param $key string
511
+ * @param $value string
512
+ * @return $this
513
+ */
514
+ public function whereYear ($ key , $ value )
515
+ {
516
+ $ this ->where ($ key , 'year ' , $ value );
517
+
518
+ return $ this ;
519
+ }
520
+
476
521
/**
477
522
* make macro for custom where clause
478
523
*
@@ -652,6 +697,22 @@ protected function condStartsWith($val, $payable)
652
697
return false ;
653
698
}
654
699
700
+ /**
701
+ * make Ends With condition
702
+ *
703
+ * @param $val string
704
+ * @param $payable mixed
705
+ * @return bool
706
+ */
707
+ protected function condEndsWith ($ val , $ payable )
708
+ {
709
+ if (preg_match ("/ $ payable$/ " , $ val )) {
710
+ return true ;
711
+ }
712
+
713
+ return false ;
714
+ }
715
+
655
716
/**
656
717
* make Match condition
657
718
*
@@ -683,4 +744,43 @@ protected function condContains($val, $payable)
683
744
{
684
745
return (strpos ($ val , $ payable ) !== false );
685
746
}
747
+
748
+ /**
749
+ * make date condition
750
+ *
751
+ * @param $val string
752
+ * @param $payable mixed
753
+ * @return bool
754
+ */
755
+ protected function condDates ($ val , $ payable )
756
+ {
757
+ $ date = date ('Y-m-d ' , strtotime ($ val ));
758
+ return $ date == $ payable ;
759
+ }
760
+
761
+ /**
762
+ * make month condition
763
+ *
764
+ * @param $val string
765
+ * @param $payable mixed
766
+ * @return bool
767
+ */
768
+ protected function condMonth ($ val , $ payable )
769
+ {
770
+ $ month = date ('m ' , strtotime ($ val ));
771
+ return $ month == $ payable ;
772
+ }
773
+
774
+ /**
775
+ * make year condition
776
+ *
777
+ * @param $val string
778
+ * @param $payable mixed
779
+ * @return bool
780
+ */
781
+ protected function condYear ($ val , $ payable )
782
+ {
783
+ $ year = date ('Y ' , strtotime ($ val ));
784
+ return $ year == $ payable ;
785
+ }
686
786
}
0 commit comments