PluginProbe
CSS & JavaScript Toolbox / 6.0
CSS & JavaScript Toolbox v6.0
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 6.0, at tables/blocks.php

162 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()) {
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 $where[] = (($filters['backupId'] == null) ? ' `backupId` IS NULL' : " `backupId` = {$filters['backupId']}");
73 unset($filters['backupId']);
74 // Filter by parent.
75 if ($filters['parent'] != null) {
76 $filters['parent'] = implode(',', ((array) $filters['parent']));
77 $where[] = " `parent` IN ({$filters['parent']})";
78 unset($filters['parent']);
79 }
80 // Types filter.
81 if ($filters['types']) {
82 $types = '"' . implode('", "', $filters['types']) . '"';
83 $where[] = " `type` IN ({$types})";
84 unset($filters['types']);
85 }
86 // Do other filters as standard where opertions nothing specific here.
87 $where = array_merge($where, $this->prepareQueryParameters($filters));
88 // Build where clause if there.
89 if (!empty($where)) {
90 $where = ' WHERE ' . implode(' AND ', $where);
91 }
92 // Order by Clause.
93 $orderBy = empty($orderBy) ? '' : (" ORDER BY " . implode(',', $orderBy));
94 // Build fields list.
95 $fields = implode(',', $fields);
96 // Build full query.
97 $query = "SELECT {$fields} FROM {$this->table}{$where}{$orderBy};";
98 $resultSet = $this->dbDriver->select($query, OBJECT);
99 // Use block id as key.
100 foreach($resultSet as $block) {
101 $blocks[$block->id] = $block;
102 }
103 return $blocks;
104 }
105
106 /**
107 * Override Parent::getNextId().
108 */
109 public function getNextId($offset = 0) {
110 // Get post meta table name.
111 $postMetaTable = $this->dbDriver->getTableName('postmeta');
112 // Get all reserved blocks/metaboxes id associated with posts.
113 $postMetaName = self::BLOCK_META_BOX_ID_META_NAME;
114 $query = "SELECT meta_value as `value`
115 FROM {$postMetaTable}
116 WHERE meta_key = '{$postMetaName}';";
117 // Get all ids.
118 $reservedIds = array_keys($this->dbDriver->select($query, OBJECT_K));
119 // Find a unique Id for the new block.
120 do {
121 // Increase by one until finding new unique id.
122 $nextId = parent::getNextId($offset++);
123 } while(in_array($nextId, $reservedIds));
124 // Return new id.
125 return $nextId;
126 }
127
128 /**
129 * put your comment there...
130 *
131 */
132 public function insert($data) {
133 // Prepare New Record data.
134 $data = $this->prepareQueryParameters($data);
135 $data = implode(',', $data);
136 // Insert statement.
137 $query = "INSERT INTO {$this->table} SET {$data};";
138 $this->dbDriver->insert($query);
139 }
140
141 /**
142 * put your comment there...
143 *
144 * @param mixed $data
145 */
146 public function update($block) {
147 // Get block id copy.
148 $id = $block['id'];
149 // Don't update id field.
150 unset($block['id']);
151 if (!empty($block)) {
152 // Prepare New Record data.
153 $block = $this->prepareQueryParameters($block);
154 $block = implode(',', $block);
155 // Insert statement.
156 $query = "UPDATE {$this->table} SET {$block} WHERE `id` = {$id};";
157 $this->dbDriver->update($query);
158 }
159 return $this;
160 }
161
162 } // End class.