PluginProbe
CSS & JavaScript Toolbox / 10.1
CSS & JavaScript Toolbox v10.1
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 10.1, at tables/blocks.php

164 lines 4.3 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 /**
109 * Override Parent::getNextId().
110 */
111 public function getNextId($offset = 0) {
112 // Get post meta table name.
113 $postMetaTable = $this->dbDriver->getTableName('postmeta');
114 // Get all reserved blocks/metaboxes id associated with posts.
115 $postMetaName = self::BLOCK_META_BOX_ID_META_NAME;
116 $query = "SELECT meta_value as `value`
117 FROM {$postMetaTable}
118 WHERE meta_key = '{$postMetaName}';";
119 // Get all ids.
120 $reservedIds = array_keys($this->dbDriver->select($query, OBJECT_K));
121 // Find a unique Id for the new block.
122 do {
123 // Increase by one until finding new unique id.
124 $nextId = parent::getNextId($offset++);
125 } while(in_array($nextId, $reservedIds));
126 // Return new id.
127 return $nextId;
128 }
129
130 /**
131 * put your comment there...
132 *
133 */
134 public function insert($data) {
135 // Prepare New Record data.
136 $data = $this->prepareQueryParameters($data);
137 $data = implode(',', $data);
138 // Insert statement.
139 $query = "INSERT INTO {$this->table} SET {$data};";
140 $this->dbDriver->insert($query);
141 }
142
143 /**
144 * put your comment there...
145 *
146 * @param mixed $data
147 */
148 public function update($block) {
149 // Get block id copy.
150 $id = $block['id'];
151 // Don't update id field.
152 unset($block['id']);
153 if (!empty($block)) {
154 // Prepare New Record data.
155 $block = $this->prepareQueryParameters($block);
156 $block = implode(',', $block);
157 // Insert statement.
158 $query = "UPDATE {$this->table} SET {$block} WHERE `id` = {$id};";
159 $this->dbDriver->update($query);
160 }
161 return $this;
162 }
163
164 } // End class.