| 1: | <?php
|
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: |
|
| 7: | namespace {
|
| 8: |
|
| 9: |
|
| 10: | class SearchQuery extends \Sphp\tools\Component{
|
| 11: | public $sql = '';
|
| 12: | public $strFormat = '';
|
| 13: | public $result = array();
|
| 14: | public $row = array();
|
| 15: | public $cacheTime = 0;
|
| 16: | private $cachesave = false;
|
| 17: | private $cachefile = '';
|
| 18: | private $cachekey = 'id';
|
| 19: |
|
| 20: | protected function oninit() {
|
| 21: | $this->unsetrenderTag();
|
| 22: | }
|
| 23: |
|
| 24: | protected function genhelpPropList() {
|
| 25: | $this->addHelpPropFunList('setSQL','Set SQL Database Query','','$sql');
|
| 26: | $this->addHelpPropFunList('setCacheKey','Set Key for Cache default is id','','$val');
|
| 27: | $this->addHelpPropFunList('setCacheTime','Set Cache Expiry Time 0 mean no cache and -1 mean always data from cache','','$val');
|
| 28: | }
|
| 29: |
|
| 30: | public function fu_setSQL($val){
|
| 31: | $this->sql = $val;
|
| 32: | }
|
| 33: | public function fu_setCacheTime($val){
|
| 34: | $this->cacheTime = intval($val);
|
| 35: | }
|
| 36: | public function fu_setCacheFile($val){
|
| 37: | $this->cachefile = $val;
|
| 38: | }
|
| 39: | public function fu_setCacheSave(){
|
| 40: | $this->cachesave = true;
|
| 41: | }
|
| 42: | public function fu_setCacheKey($val){
|
| 43: | $this->cachekey = $val;
|
| 44: | }
|
| 45: | public function getRow($dfield){
|
| 46: | if(isset($this->row[$dfield])){
|
| 47: | return $this->row[$dfield];
|
| 48: | }else{
|
| 49: |
|
| 50: |
|
| 51: | return "";
|
| 52: | }
|
| 53: | }
|
| 54: |
|
| 55: | private function genrender(){
|
| 56: | $stro = "";
|
| 57: |
|
| 58: | foreach($this->result as $key1=>$keyar){
|
| 59: | foreach($keyar as $index=>$this->row){
|
| 60: | $tmpf = new \Sphp\tools\FrontFileChild($this->strFormat,true,null,$this->frontobj);
|
| 61: | $tmpf->run();
|
| 62: | $stro .= $tmpf->data;
|
| 63: |
|
| 64: | } }
|
| 65: |
|
| 66: | return $stro;
|
| 67: |
|
| 68: | }
|
| 69: |
|
| 70: |
|
| 71: | protected function oncreate($element){
|
| 72: | $this->strFormat = $this->element->innertext;
|
| 73: | $this->element->innertext = '';
|
| 74: | }
|
| 75: |
|
| 76: |
|
| 77: | protected function onprerender(){
|
| 78: | $mysql = \SphpBase::dbEngine();
|
| 79: | $this->result = $mysql->fetchQuery($this->sql,$this->cacheTime,$this->cachefile,$this->cachekey,$this->cachesave);
|
| 80: | }
|
| 81: |
|
| 82: | protected function onrender(){
|
| 83: | $this->innerHTML = $this->genrender();
|
| 84: | }
|
| 85: |
|
| 86: |
|
| 87: | }
|
| 88: | }
|
| 89: | |