| 1 |
<?php |
| 2 |
/** |
| 3 |
* @version $ Id; ?FILE_NAME ?DATE ?TIME ?AUTHOR $ |
| 4 |
*/ |
| 5 |
|
| 6 |
/** |
| 7 |
* No direct access. |
| 8 |
*/ |
| 9 |
// No Direct Accesss code |
| 10 |
|
| 11 |
/** |
| 12 |
* |
| 13 |
* DESCRIPTION |
| 14 |
* |
| 15 |
* @author ?? |
| 16 |
* @version ?? |
| 17 |
*/ |
| 18 |
abstract class CJTSQLView { |
| 19 |
|
| 20 |
/** |
| 21 |
* put your comment there... |
| 22 |
* |
| 23 |
* @var mixed |
| 24 |
*/ |
| 25 |
protected $driver = null; |
| 26 |
|
| 27 |
/** |
| 28 |
* put your comment there... |
| 29 |
* |
| 30 |
* @var mixed |
| 31 |
*/ |
| 32 |
protected $query = array( |
| 33 |
'columns' => array('*'), |
| 34 |
'filter' => array(), |
| 35 |
'orderBy' => array(), |
| 36 |
'limits' => array(), |
| 37 |
); |
| 38 |
|
| 39 |
/** |
| 40 |
* put your comment there... |
| 41 |
* |
| 42 |
* @param mixed $dbDriver |
| 43 |
* @return CJTPinsBlockView |
| 44 |
*/ |
| 45 |
public function __construct($driver) { |
| 46 |
$this->driver = $driver; |
| 47 |
// Initialize locals. |
| 48 |
$this->query = (object) $this->query; |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* put your comment there... |
| 53 |
* |
| 54 |
*/ |
| 55 |
abstract public function __toString(); |
| 56 |
|
| 57 |
|
| 58 |
/** |
| 59 |
* put your comment there... |
| 60 |
* |
| 61 |
* @param mixed $from |
| 62 |
* @param mixed $filter |
| 63 |
*/ |
| 64 |
protected function buildQuery($from, $filter) |
| 65 |
{ |
| 66 |
|
| 67 |
$query = $this->query; |
| 68 |
|
| 69 |
$sql = array |
| 70 |
( |
| 71 |
'columns' => null, |
| 72 |
'from' => null, |
| 73 |
'filter' => null, |
| 74 |
'orderBy' => null, |
| 75 |
'limits' => null |
| 76 |
); |
| 77 |
|
| 78 |
$sql[ 'columns' ] = implode( ', ', $query->columns ); |
| 79 |
|
| 80 |
// From. |
| 81 |
$sql[ 'from' ] = " FROM {$from}"; |
| 82 |
|
| 83 |
// Where clause. |
| 84 |
if ( ! empty( $filter ) ) |
| 85 |
{ |
| 86 |
$sql[ 'filter' ] = " WHERE {$filter}"; |
| 87 |
} |
| 88 |
|
| 89 |
// Order By. |
| 90 |
if ( ! empty( $query->orderBy ) ) |
| 91 |
{ |
| 92 |
$sql[ 'orderBy' ] = ' ORDER BY ' . implode( ',', $order ); |
| 93 |
} |
| 94 |
|
| 95 |
// Limits. |
| 96 |
if ( ! empty( $query->limits ) ) |
| 97 |
{ |
| 98 |
$sql[ 'limits' ] = " LIMIT {$limits[0]}" . ( isset( $limits[ 1 ] ) ? ",{$limits}" : '' ); |
| 99 |
} |
| 100 |
|
| 101 |
// Buile query |
| 102 |
$sql = "SELECT {$sql['columns']}\n\n{$sql['from']}\n\n{$sql['filter']}{$sql['orderBy']}{$sql['limits']};"; |
| 103 |
|
| 104 |
return $sql; |
| 105 |
} |
| 106 |
|
| 107 |
/** |
| 108 |
* put your comment there... |
| 109 |
* |
| 110 |
*/ |
| 111 |
abstract public function exec(); |
| 112 |
|
| 113 |
/** |
| 114 |
* put your comment there... |
| 115 |
* |
| 116 |
*/ |
| 117 |
public function &getQueryObject() { |
| 118 |
return $this->query; |
| 119 |
} |
| 120 |
|
| 121 |
} // End class. |