Last active
August 29, 2015 14:02
-
-
Save oshanz/97782c79ac186c5f6e59 to your computer and use it in GitHub Desktop.
Multisearch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @author Waruna Oshan Wisumperuma | |
* @contact warunaoshan@gmail.com | |
* | |
* https://gist.github.com/oshanz/97782c79ac186c5f6e59 | |
* Semantic version = 1.0.0 | |
* | |
* This program is free software: you can redistribute it and/or modify | |
* it under the terms of the GNU General Public License as published by | |
* the Free Software Foundation, either version 3 of the License, or | |
* (at your option) any later version. | |
* | |
*/ | |
class Multisearch { | |
private $query; | |
private $date_between; | |
function __construct() { | |
$this->query = array(); | |
} | |
/** | |
* For = Query | |
* @param String $column - column name | |
* @param Any $value - search argument | |
*/ | |
public function set_equel($column, $value) { | |
if (isset($value) && is_numeric($value) || !empty($value)) { | |
$this->query[] = "$column = '$value'"; | |
} | |
} | |
/** | |
* For like Query %% | |
* @param String $column - column name | |
* @param Any $value - search argument | |
*/ | |
public function set_like($column, $value) { | |
if (isset($value) && is_numeric($value) || !empty($value)) { | |
$this->query[] = "$column LIKE '%$value%'"; | |
} | |
} | |
/** | |
* For Begin like Query %xxx | |
* @param String $column - column name | |
* @param Any $value - search argument | |
*/ | |
public function set_like_L($column, $value) { | |
if (isset($value) && is_numeric($value) || !empty($value)) { | |
$this->query[] = "$column LIKE '%$value'"; | |
} | |
} | |
/** | |
* For End like Query xxx% | |
* @param String $column - column name | |
* @param Any $value - search argument | |
*/ | |
public function set_like_R($column, $value) { | |
if (isset($value) && is_numeric($value) || !empty($value)) { | |
$this->query[] = "$column LIKE '$value%'"; | |
} | |
} | |
/** | |
* | |
* @param String $column | |
* @param String $from | |
* @param String $to | |
*/ | |
public function set_date_between($column, $from, $to) { | |
if (isset($from) && isset($to) && !empty($from) && !empty($to)) { | |
$this->date_between = " $column BETWEEN '$from' AND '$to' "; | |
} | |
} | |
/** | |
* get Query | |
* @return string | |
*/ | |
public function __toString() { | |
$query = ' '; | |
if (!empty($this->query) && !is_null($this->date_between)) { | |
$query = ' AND ' . implode(' AND ', $this->query) . ' AND ' . $this->date_between . ' '; | |
} elseif (!empty($this->query)) { | |
$query = ' AND ' . implode(' AND ', $this->query) . ' '; | |
} elseif (!is_null($this->date_between)) { | |
$query = ' AND ' . $this->date_between . ' '; | |
} | |
return $query; | |
} | |
} |
@supunxfinity, its not a bug. adding that functionality mean its not date_between function anymore. but nice idea. i'll impliment it. may be api get changed.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've found an error.
to use this function we had to pass two dates.
with this replacement we can use this function with one or two dates