Skip to content

Commit c1de055

Browse files
committed
added some missing features and fix some bugs
1 parent 8a4e077 commit c1de055

File tree

1 file changed

+102
-2
lines changed

1 file changed

+102
-2
lines changed

src/JsonQueriable.php

Lines changed: 102 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ trait JsonQueriable
3434
protected $_conditions = [];
3535

3636
/**
37-
* @var bool
37+
* @var bool
3838
*/
3939
protected $_isProcessed = false;
4040

@@ -67,6 +67,9 @@ trait JsonQueriable
6767
'endswith' => 'endsWith',
6868
'match' => 'match',
6969
'contains' => 'contains',
70+
'dates' => 'dates',
71+
'month' => 'month',
72+
'year' => 'year',
7073
];
7174

7275

@@ -169,7 +172,7 @@ public function isJson($value, $return_map = false)
169172

170173
return (json_last_error() == JSON_ERROR_NONE) ? ($return_map ? $data : true) : json_last_error_msg();
171174
}
172-
175+
173176
/**
174177
* prepare data for result
175178
*
@@ -473,6 +476,48 @@ public function whereContains($key, $value)
473476
return $this;
474477
}
475478

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+
476521
/**
477522
* make macro for custom where clause
478523
*
@@ -652,6 +697,22 @@ protected function condStartsWith($val, $payable)
652697
return false;
653698
}
654699

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+
655716
/**
656717
* make Match condition
657718
*
@@ -683,4 +744,43 @@ protected function condContains($val, $payable)
683744
{
684745
return (strpos($val, $payable) !== false);
685746
}
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+
}
686786
}

0 commit comments

Comments
 (0)