PluginProbe
CSS & JavaScript Toolbox / 7.2
CSS & JavaScript Toolbox v7.2
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
← All changes | tables/block-pins.php +23 -12 6.07.2 View file →
@@ -7,11 +7,8 @@
7 7 * No direct access.
8 8 */
9 9 defined('ABSPATH') or die("Access denied");
10 10
11 -// CJTTable class.
12 -require_once CJTOOLBOX_FRAMEWORK . '/db/mysql/table.inc.php';
13 -
14 11 /**
15 12 *
16 13 */
17 14 class CJTBlockPinsTable extends CJTTable {
@@ -43,16 +40,27 @@
43 40 /**
44 41 * put your comment there...
45 42 *
46 43 * @param mixed $ids
44 + * @param mixed $condition
47 45 */
48 - public function get($ids = array()) {
49 - $where = '';
50 - $ids = (array) $ids; // May be single integer.
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.
51 52 if (!empty($ids)) {
52 53 $ids = implode(',', $ids);
53 - $where = " WHERE `blockId` IN ({$ids})";
54 + $where[] = "`blockId` IN ({$ids})";
54 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.
55 63 $query = "SELECT * FROM {$this->table}{$where};";
56 64 return $this->dbDriver->select($query, OBJECT);
57 65 }
58 66
@@ -62,19 +70,22 @@
62 70 * @param mixed $blockId
63 71 * @param mixed $pins
64 72 */
65 73 public function insert($blockId, $pins) {
74 + // Initialize.
66 75 $rows = array();
67 - if (!empty($pins)) {
68 - foreach ($pins as $pin => $values) {
69 - foreach ($values as $value) {
70 - $rows[] = "({$blockId},'{$pin}', {$value})";
71 - }
76 + foreach (((array) $pins) as $pin => $values) {
77 + foreach ($values as $value) {
78 + $rows[] = "({$blockId},'{$pin}', {$value})";
72 79 }
80 + }
81 + // Execute only if there is at least one row to insert.
82 + if (!empty($rows)) {
73 83 $rows = implode(',', $rows);
74 84 $query = "INSERT INTO {$this->table} (`blockId`, `pin`, `value`) VALUES {$rows};";
75 85 $this->dbDriver->insert($query);
76 86 }
87 + // Chaining.
77 88 }
78 89
79 90 /**
80 91 * put your comment there...