1: <?php
2: /**
3: * Description of SearchQuery
4: *
5: * @author SARTAJ
6: */
7: namespace {
8:
9:
10: class SearchQuery extends \Sphp\tools\Control{
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: public function __construct($name='',$fieldName='',$tableName='') {
21: $this->init($name,'','');
22: $this->unsetrenderTag();
23: }
24:
25: protected function genhelpPropList() {
26: $this->addHelpPropFunList('setSQL','Set SQL Database Query','','$sql');
27: $this->addHelpPropFunList('setCacheKey','Set Key for Cache default is id','','$val');
28: $this->addHelpPropFunList('setCacheTime','Set Cache Expiry Time 0 mean no cache and -1 mean always data from cache','','$val');
29: }
30:
31: public function setSQL($val){
32: $this->sql = $val;
33: }
34: public function setCacheTime($val){
35: $this->cacheTime = intval($val);
36: }
37: public function setCacheFile($val){
38: $this->cachefile = $val;
39: }
40: public function setCacheSave(){
41: $this->cachesave = true;
42: }
43: public function setCacheKey($val){
44: $this->cachekey = $val;
45: }
46: public function getField($dfield){
47: if(isset($this->row[$dfield])){
48: return $this->row[$dfield];
49: }else{
50: // print_r($this->result);
51: // trigger_error("Invalid Database Field in SQL:- ".$this->sql,E_USER_ERROR);
52: return "";
53: }
54: }
55:
56: private function genrender(){
57: $stro = "";
58: //$roote = $this->tempobj->getChildrenWrapper($this);
59: foreach($this->result as $key1=>$keyar){
60: foreach($keyar as $index=>$this->row){
61: $tmpf = new \Sphp\tools\TempFileChild($this->strFormat,true,null,$this->tempobj);
62: $tmpf->run();
63: $stro .= $tmpf->data;
64: //$stro .= $this->tempobj->parseComponentChildren($roote);
65: } }
66:
67: return $stro;
68:
69: }
70:
71:
72: public function oncreate($element){
73: $this->strFormat = $this->element->innertext;
74: $this->element->innertext = '';
75: }
76:
77:
78: public function onprerender(){
79: $mysql = \SphpBase::dbEngine();
80: $this->result = $mysql->fetchQuery($this->sql,$this->cacheTime,$this->cachefile,$this->cachekey,$this->cachesave);
81: }
82:
83: public function onrender(){
84: $this->innerHTML = $this->genrender();
85: }
86:
87:
88: }
89: }
90: