| @@ -11,31 +11,31 @@ | ||
| 11 | 11 | // CJTTable class. |
| 12 | 12 | require_once CJTOOLBOX_FRAMEWORK . '/db/mysql/table.inc.php'; |
| 13 | 13 | |
| 14 | 14 | /** |
| 15 | -* | |
| 15 | +* | |
| 16 | 16 | * @deprecated Use CJTBlockTable instead! |
| 17 | 17 | */ |
| 18 | 18 | class CJTBlocksTable extends CJTTable { |
| 19 | - | |
| 19 | + | |
| 20 | 20 | /** */ |
| 21 | 21 | const BLOCK_META_BOX_ID_META_NAME = '__CJT-BLOCK-ID'; |
| 22 | - | |
| 22 | + | |
| 23 | 23 | /** */ |
| 24 | 24 | const BLOCK_META_BOX_STATUS_META_NAME = '__CJT-BLOCK-STATUS'; |
| 25 | - | |
| 25 | + | |
| 26 | 26 | /** |
| 27 | 27 | * put your comment there... |
| 28 | - * | |
| 28 | + * | |
| 29 | 29 | */ |
| 30 | 30 | public function __construct(&$dbDriver) { |
| 31 | 31 | // Inirialize parent class. |
| 32 | 32 | parent::__construct($dbDriver, cssJSToolbox::$config->database->tables->blocks); |
| 33 | 33 | } |
| 34 | - | |
| 34 | + | |
| 35 | 35 | /** |
| 36 | 36 | * put your comment there... |
| 37 | - * | |
| 37 | + * | |
| 38 | 38 | * @param mixed $ids |
| 39 | 39 | */ |
| 40 | 40 | public function delete($ids = array()) { |
| 41 | 41 | $where = ''; |
| @@ -44,12 +44,12 @@ | ||
| 44 | 44 | } |
| 45 | 45 | $query = "DELETE FROM {$this->table}{$where};"; |
| 46 | 46 | $this->dbDriver->delete($query); |
| 47 | 47 | } |
| 48 | - | |
| 48 | + | |
| 49 | 49 | /** |
| 50 | 50 | * put your comment there... |
| 51 | - * | |
| 51 | + * | |
| 52 | 52 | * @param mixed $ids |
| 53 | 53 | * @param mixed $fields |
| 54 | 54 | * @param mixed $filters |
| 55 | 55 | * @deprecated @param mixed $returnType |
| @@ -54,9 +54,9 @@ | ||
| 54 | 54 | * @param mixed $filters |
| 55 | 55 | * @deprecated @param mixed $returnType |
| 56 | 56 | * @param mixed $orderBy |
| 57 | 57 | */ |
| 58 | - public function get($ids = array(), $fields = array('*'), $filters = array(), $returnType = OBJECT_K, $orderBy = array()) { | |
| 58 | + public function get($ids = array(), $fields = array('*'), $filters = array(), $returnType = OBJECT_K, $orderBy = array(), $useDefaultBackupFltr = true) { | |
| 59 | 59 | // Warn if $returnTypes is used |
| 60 | 60 | if ($returnType != OBJECT_K) { |
| 61 | 61 | die('Warning! Using $returnType with value other than OBJECT_K from the caller!!!'); |
| 62 | 62 | } |
| @@ -68,18 +68,20 @@ | ||
| 68 | 68 | $ids = implode(',', $ids); |
| 69 | 69 | $where[] = " `id` IN ({$ids})"; |
| 70 | 70 | } |
| 71 | 71 | // Filter by backup name. |
| 72 | - $where[] = (($filters['backupId'] == null) ? ' `backupId` IS NULL' : " `backupId` = {$filters['backupId']}"); | |
| 73 | - unset($filters['backupId']); | |
| 72 | + if ($useDefaultBackupFltr) { | |
| 73 | + $where[] = (!isset($filters['backupId']) ? ' `backupId` IS NULL' : " `backupId` = {$filters['backupId']}"); | |
| 74 | + unset($filters['backupId']); | |
| 75 | + } | |
| 74 | 76 | // Filter by parent. |
| 75 | - if ($filters['parent'] != null) { | |
| 77 | + if (isset($filters['parent'])) { | |
| 76 | 78 | $filters['parent'] = implode(',', ((array) $filters['parent'])); |
| 77 | 79 | $where[] = " `parent` IN ({$filters['parent']})"; |
| 78 | 80 | unset($filters['parent']); |
| 79 | 81 | } |
| 80 | 82 | // Types filter. |
| 81 | - if ($filters['types']) { | |
| 83 | + if (isset($filters['types'])) { | |
| 82 | 84 | $types = '"' . implode('", "', $filters['types']) . '"'; |
| 83 | 85 | $where[] = " `type` IN ({$types})"; |
| 84 | 86 | unset($filters['types']); |
| 85 | 87 | } |
| @@ -101,9 +103,22 @@ | ||
| 101 | 103 | $blocks[$block->id] = $block; |
| 102 | 104 | } |
| 103 | 105 | return $blocks; |
| 104 | 106 | } |
| 105 | - | |
| 107 | + | |
| 108 | + public function getNextIdNEW($offset = 0) | |
| 109 | + { | |
| 110 | + // Get post meta table name. | |
| 111 | + $blocksTable = $this->dbDriver->getTableName('cjtoolbox_blocks'); | |
| 112 | + | |
| 113 | + // Get all reserved blocks/metaboxes id associated with posts. | |
| 114 | + $postMetaName = self::BLOCK_META_BOX_ID_META_NAME; | |
| 115 | + $query = "SELECT id FROM {$blocksTable} ORDER BY id DESC LIMIT 1;"; | |
| 116 | + // Get all ids. | |
| 117 | + $currentID = current( array_keys( $this->dbDriver->select($query) ) ); | |
| 118 | + | |
| 119 | + return $currentID + 1; | |
| 120 | + } | |
| 106 | 121 | /** |
| 107 | 122 | * Override Parent::getNextId(). |
| 108 | 123 | */ |
| 109 | 124 | public function getNextId($offset = 0) { |
| @@ -114,9 +129,9 @@ | ||
| 114 | 129 | $query = "SELECT meta_value as `value` |
| 115 | 130 | FROM {$postMetaTable} |
| 116 | 131 | WHERE meta_key = '{$postMetaName}';"; |
| 117 | 132 | // Get all ids. |
| 118 | - $reservedIds = array_keys($this->dbDriver->select($query, OBJECT_K)); | |
| 133 | + $reservedIds = array_keys($this->dbDriver->select($query, OBJECT_K)); | |
| 119 | 134 | // Find a unique Id for the new block. |
| 120 | 135 | do { |
| 121 | 136 | // Increase by one until finding new unique id. |
| 122 | 137 | $nextId = parent::getNextId($offset++); |
| @@ -123,12 +138,12 @@ | ||
| 123 | 138 | } while(in_array($nextId, $reservedIds)); |
| 124 | 139 | // Return new id. |
| 125 | 140 | return $nextId; |
| 126 | 141 | } |
| 127 | - | |
| 142 | + | |
| 128 | 143 | /** |
| 129 | 144 | * put your comment there... |
| 130 | - * | |
| 145 | + * | |
| 131 | 146 | */ |
| 132 | 147 | public function insert($data) { |
| 133 | 148 | // Prepare New Record data. |
| 134 | 149 | $data = $this->prepareQueryParameters($data); |
| @@ -136,12 +151,12 @@ | ||
| 136 | 151 | // Insert statement. |
| 137 | 152 | $query = "INSERT INTO {$this->table} SET {$data};"; |
| 138 | 153 | $this->dbDriver->insert($query); |
| 139 | 154 | } |
| 140 | - | |
| 155 | + | |
| 141 | 156 | /** |
| 142 | 157 | * put your comment there... |
| 143 | - * | |
| 158 | + * | |
| 144 | 159 | * @param mixed $data |
| 145 | 160 | */ |
| 146 | 161 | public function update($block) { |
| 147 | 162 | // Get block id copy. |
| @@ -157,6 +172,6 @@ | ||
| 157 | 172 | $this->dbDriver->update($query); |
| 158 | 173 | } |
| 159 | 174 | return $this; |
| 160 | 175 | } |
| 161 | - | |
| 176 | + | |
| 162 | 177 | } // End class. |