PluginProbe
CSS & JavaScript Toolbox / 11.3
CSS & JavaScript Toolbox v11.3
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 / block-pins.php

block-pins.php in CSS & JavaScript Toolbox 11.3, at tables/block-pins.php

118 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 *
4 */
5
6 /**
7 * No direct access.
8 */
9 defined('ABSPATH') or die("Access denied");
10
11 /**
12 *
13 */
14 class CJTBlockPinsTable extends CJTTable {
15
16 /**
17 * put your comment there...
18 *
19 */
20 public function __construct(&$dbDriver) {
21 // Inirialize parent class.
22 parent::__construct($dbDriver, cssJSToolbox::$config->database->tables->blockPins, 'blockId');
23 }
24
25 /**
26 * put your comment there...
27 *
28 * @param mixed $ids
29 */
30 public function delete($blocks = array()) {
31 $where = '';
32 $blocks = (array) $blocks; // $blocks may be passed as single integer.
33 if (!empty($blocks)) {
34 $where = ' WHERE `blockId` IN (' . implode(',', ((array) $blocks)) . ')';
35 }
36 $query = "DELETE FROM {$this->table}{$where};";
37 $this->dbDriver->delete($query);
38 }
39
40 /**
41 * put your comment there...
42 *
43 * @param mixed $ids
44 * @param mixed $condition
45 */
46 public function get($ids = array(), $condition = null) {
47 // Initialize.
48 $where = array();
49 // May be single integer.
50 $ids = (array) $ids;
51 // Retrieve specific list of IDs.
52 if (!empty($ids)) {
53 $ids = implode(',', $ids);
54 $where[] = "`blockId` IN ({$ids})";
55 }
56 // Get CONDITIONS expression.
57 if ($condition !== null) {
58 $where = array_merge($where, $this->prepareQueryParameters($condition));
59 }
60 // Use WHERE CLAUSE only if there is Ids or Condition specified.
61 $where = !empty($where) ? (' WHERE ' . implode(' AND ', $where)) : '';
62 // Get result.
63 $query = "SELECT * FROM {$this->table}{$where};";
64 return $this->dbDriver->select($query, OBJECT);
65 }
66
67 /**
68 * put your comment there...
69 *
70 * @param mixed $blockId
71 * @param mixed $pins
72 */
73 public function insert($blockId, $pins) {
74 // Initialize.
75 $rows = array();
76 foreach (((array) $pins) as $pin => $values) {
77 foreach ($values as $value) {
78 $rows[] = "({$blockId},'{$pin}', {$value})";
79 }
80 }
81 // Execute only if there is at least one row to insert.
82 if (!empty($rows)) {
83 $rows = implode(',', $rows);
84 $query = "INSERT INTO {$this->table} (`blockId`, `pin`, `value`) VALUES {$rows};";
85 $this->dbDriver->insert($query);
86 }
87 // Chaining.
88 }
89
90 /**
91 * put your comment there...
92 *
93 * @param mixed $blockId
94 * @param mixed $pins
95 */
96 public function insertRaw($blockId, $pins) {
97 $rows = array();
98 foreach ($pins as $pin) {
99 $rows[] = "({$blockId},'{$pin->pin}', {$pin->value})";
100 }
101 $rows = implode(',', $rows);
102 $query = "INSERT INTO {$this->table} (`blockId`, `pin`, `value`) VALUES {$rows};";
103 $this->dbDriver->insert($query);
104 }
105
106 /**
107 * put your comment there...
108 *
109 * @param mixed $data
110 */
111 public function update($blockId, $pins) {
112 // Delete old block pins.
113 $this->delete($blockId);
114 // Add new block pins.
115 $this->insert($blockId, $pins);
116 }
117
118 } // End class.