PluginProbe
CSS & JavaScript Toolbox / 11.9
CSS & JavaScript Toolbox v11.9
trunk 0.3 0.8 10 10.1 11 11.2 11.3 11.4 11.5 11.6 11.7 11.8 11.9 11.9.1 12 12.0 12.0.1 12.0.3 12.0.4 12.0.5 12.0.6 12.0.7 6.0 6.0.11 All 60 releases
css-javascript-toolbox / tables / blocks.php

blocks.php in CSS & JavaScript Toolbox 11.9, at tables/blocks.php

177 lines 4.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @deprecated
4 */
5
6 /**
7 * No direct access.
8 */
9 defined('ABSPATH') or die("Access denied");
10
11 // CJTTable class.
12 require_once CJTOOLBOX_FRAMEWORK . '/db/mysql/table.inc.php';
13
14 /**
15 *
16 * @deprecated Use CJTBlockTable instead!
17 */
18 class CJTBlocksTable extends CJTTable {
19
20 /** */
21 const BLOCK_META_BOX_ID_META_NAME = '__CJT-BLOCK-ID';
22
23 /** */
24 const BLOCK_META_BOX_STATUS_META_NAME = '__CJT-BLOCK-STATUS';
25
26 /**
27 * put your comment there...
28 *
29 */
30 public function __construct(&$dbDriver) {
31 // Inirialize parent class.
32 parent::__construct($dbDriver, cssJSToolbox::$config->database->tables->blocks);
33 }
34
35 /**
36 * put your comment there...
37 *
38 * @param mixed $ids
39 */
40 public function delete($ids = array()) {
41 $where = '';
42 if (!empty($ids)) {
43 $where = ' WHERE `id` IN (' . implode(',', ((array) $ids)) . ')';
44 }
45 $query = "DELETE FROM {$this->table}{$where};";
46 $this->dbDriver->delete($query);
47 }
48
49 /**
50 * put your comment there...
51 *
52 * @param mixed $ids
53 * @param mixed $fields
54 * @param mixed $filters
55 * @deprecated @param mixed $returnType
56 * @param mixed $orderBy
57 */
58 public function get($ids = array(), $fields = array('*'), $filters = array(), $returnType = OBJECT_K, $orderBy = array(), $useDefaultBackupFltr = true) {
59 // Warn if $returnTypes is used
60 if ($returnType != OBJECT_K) {
61 die('Warning! Using $returnType with value other than OBJECT_K from the caller!!!');
62 }
63 $blocks = array();
64 $where = array();
65 // Query block ids.
66 $ids = (array) $ids; // $ids may be single integer.
67 if (!empty($ids)) {
68 $ids = implode(',', $ids);
69 $where[] = " `id` IN ({$ids})";
70 }
71 // Filter by backup name.
72 if ($useDefaultBackupFltr) {
73 $where[] = (!isset($filters['backupId']) ? ' `backupId` IS NULL' : " `backupId` = {$filters['backupId']}");
74 unset($filters['backupId']);
75 }
76 // Filter by parent.
77 if (isset($filters['parent'])) {
78 $filters['parent'] = implode(',', ((array) $filters['parent']));
79 $where[] = " `parent` IN ({$filters['parent']})";
80 unset($filters['parent']);
81 }
82 // Types filter.
83 if (isset($filters['types'])) {
84 $types = '"' . implode('", "', $filters['types']) . '"';
85 $where[] = " `type` IN ({$types})";
86 unset($filters['types']);
87 }
88 // Do other filters as standard where opertions nothing specific here.
89 $where = array_merge($where, $this->prepareQueryParameters($filters));
90 // Build where clause if there.
91 if (!empty($where)) {
92 $where = ' WHERE ' . implode(' AND ', $where);
93 }
94 // Order by Clause.
95 $orderBy = empty($orderBy) ? '' : (" ORDER BY " . implode(',', $orderBy));
96 // Build fields list.
97 $fields = implode(',', $fields);
98 // Build full query.
99 $query = "SELECT {$fields} FROM {$this->table}{$where}{$orderBy};";
100 $resultSet = $this->dbDriver->select($query, OBJECT);
101 // Use block id as key.
102 foreach($resultSet as $block) {
103 $blocks[$block->id] = $block;
104 }
105 return $blocks;
106 }
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 }
121 /**
122 * Override Parent::getNextId().
123 */
124 public function getNextId($offset = 0) {
125 // Get post meta table name.
126 $postMetaTable = $this->dbDriver->getTableName('postmeta');
127 // Get all reserved blocks/metaboxes id associated with posts.
128 $postMetaName = self::BLOCK_META_BOX_ID_META_NAME;
129 $query = "SELECT meta_value as `value`
130 FROM {$postMetaTable}
131 WHERE meta_key = '{$postMetaName}';";
132 // Get all ids.
133 $reservedIds = array_keys($this->dbDriver->select($query, OBJECT_K));
134 // Find a unique Id for the new block.
135 do {
136 // Increase by one until finding new unique id.
137 $nextId = parent::getNextId($offset++);
138 } while(in_array($nextId, $reservedIds));
139 // Return new id.
140 return $nextId;
141 }
142
143 /**
144 * put your comment there...
145 *
146 */
147 public function insert($data) {
148 // Prepare New Record data.
149 $data = $this->prepareQueryParameters($data);
150 $data = implode(',', $data);
151 // Insert statement.
152 $query = "INSERT INTO {$this->table} SET {$data};";
153 $this->dbDriver->insert($query);
154 }
155
156 /**
157 * put your comment there...
158 *
159 * @param mixed $data
160 */
161 public function update($block) {
162 // Get block id copy.
163 $id = $block['id'];
164 // Don't update id field.
165 unset($block['id']);
166 if (!empty($block)) {
167 // Prepare New Record data.
168 $block = $this->prepareQueryParameters($block);
169 $block = implode(',', $block);
170 // Insert statement.
171 $query = "UPDATE {$this->table} SET {$block} WHERE `id` = {$id};";
172 $this->dbDriver->update($query);
173 }
174 return $this;
175 }
176
177 } // End class.