| 1 |
<?php |
| 2 |
/** |
| 3 |
* |
| 4 |
*/ |
| 5 |
|
| 6 |
/** |
| 7 |
* |
| 8 |
*/ |
| 9 |
abstract class CJTServicesTable |
| 10 |
{ |
| 11 |
|
| 12 |
/** |
| 13 |
* put your comment there... |
| 14 |
* |
| 15 |
* @var wpdb |
| 16 |
*/ |
| 17 |
protected $gateway; |
| 18 |
|
| 19 |
/** |
| 20 |
* put your comment there... |
| 21 |
* |
| 22 |
* @var mixed |
| 23 |
*/ |
| 24 |
protected $tableName; |
| 25 |
|
| 26 |
/** |
| 27 |
* put your comment there... |
| 28 |
* |
| 29 |
*/ |
| 30 |
public function __construct() |
| 31 |
{ |
| 32 |
$this->gateway =& $GLOBALS['wpdb']; |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* put your comment there... |
| 37 |
* |
| 38 |
*/ |
| 39 |
public function getInsertedId() |
| 40 |
{ |
| 41 |
return $this->gateway->insert_id; |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* put your comment there... |
| 46 |
* |
| 47 |
*/ |
| 48 |
public static function getInstance() |
| 49 |
{ |
| 50 |
|
| 51 |
$tableClass = get_called_class(); |
| 52 |
|
| 53 |
$table = new $tableClass(); |
| 54 |
|
| 55 |
return $table; |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* put your comment there... |
| 60 |
* |
| 61 |
*/ |
| 62 |
public function getTableName() |
| 63 |
{ |
| 64 |
return "{$this->gateway->prefix}{$this->tableName}"; |
| 65 |
} |
| 66 |
|
| 67 |
/** |
| 68 |
* put your comment there... |
| 69 |
* |
| 70 |
* @param mixed $query |
| 71 |
* @param mixed $params |
| 72 |
*/ |
| 73 |
protected function prepare($query, $params = array()) |
| 74 |
{ |
| 75 |
|
| 76 |
# Resolve Table name |
| 77 |
$query = str_replace('#table#', $this->getTableName(), $query); |
| 78 |
|
| 79 |
if (!empty($params)) |
| 80 |
{ |
| 81 |
|
| 82 |
# Prepare Query parameters |
| 83 |
array_unshift($params, $query); |
| 84 |
|
| 85 |
$query = call_user_func_array( |
| 86 |
|
| 87 |
array($this->gateway, 'prepare'), |
| 88 |
$params |
| 89 |
); |
| 90 |
} |
| 91 |
|
| 92 |
return $query; |
| 93 |
} |
| 94 |
} |