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
css-javascript-toolbox / models / package.php

package.php in CSS & JavaScript Toolbox 7.2, at models/package.php

152 lines 4.2 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 // Disllow direct access.
7 defined('ABSPATH') or die('Access denied');
8
9 // Import dependencies.
10 cssJSToolbox::import('framework:db:mysql:xtable.inc.php');
11
12 /**
13 *
14 */
15 class CJTPackageModel extends CJTHookableClass {
16
17 /**
18 * put your comment there...
19 *
20 * @var mixed
21 */
22 protected $params = array();
23
24 /**
25 * Delete single package.
26 *
27 * This method is going to delete the package
28 * and all the templates and blocks associated to it,
29 * therefor it'll unlink/break-down the relationship
30 * between those templates and blocks.
31 *
32 * @param Integer Package Id.
33 * @return CJTPackageModel Return $this.
34 */
35 public function delete($id) {
36 // Initialize.
37 $modelTemplates = CJTModel::getInstance('templates-manager');
38 $dbd = cssJSToolbox::getInstance()->getDBDriver();
39 $assoObjectsQueryTmp = 'SELECT objectId
40 FROM #__cjtoolbox_package_objects
41 WHERE packageId = %d AND objectType = "%s" AND relType = "%s";';
42 // Delete the package.
43 CJTxTable::getInstance('package')
44 ->set('id', $id)
45 ->delete();
46 // Delete blocks.
47 $blockIds = array_keys($dbd->select(sprintf($assoObjectsQueryTmp, $id, 'block', 'add')));
48 if (!empty($blockIds)) {
49 // Delete blocks!
50 CJTModel::getInstance('blocks')
51 ->delete($blockIds)
52 ->save();
53 }
54 // Delete templates.
55 $modelTemplates->inputs['ids'] = array_keys($dbd->select(sprintf($assoObjectsQueryTmp, $id, 'template', 'add')));
56 // Templates muct be in trash state before deleted!
57 $modelTemplates->inputs['state'] = 'trash';
58 // Move to Trash + Delete only if there is at least one Id!
59 empty($modelTemplates->inputs['ids']) OR ($modelTemplates->changeState() AND $modelTemplates->delete());
60 // Delete package objects map.
61 CJTxTable::getInstance('package-objects')
62 ->set('packageId', $id)
63 ->delete(array('packageId'));
64 }
65
66 /**
67 * put your comment there...
68 *
69 * @param mixed $packageName
70 */
71 public function exists($packageName) {
72 // Load by name.
73 $tablePackage = CJTxTable::getInstance('package')
74 ->set('name', $packageName)
75 ->load(array('name'));
76 // The object table if exists FALSE otherwise.
77 return ($tablePackage->get('id') ? $tablePackage : FALSE);
78 }
79
80 /**
81 * put your comment there...
82 *
83 */
84 public function getFileContent() {
85 // Get package ID.
86 $packageId = $_REQUEST['packageId'];
87 // Get Field/File to read.
88 $file = $this->getParam('file');
89 // LOAD file content from database.
90 $tblPackage = CJTxTable::getInstance('package');
91 $content = $tblPackage->set('id', $packageId)
92 ->load(array('id'))
93 ->get($file);
94 // Return file content.
95 return $content;
96 }
97
98 /**
99 * put your comment there...
100 *
101 * @param mixed $name
102 */
103 public function getParam($name) {
104 return isset($this->params[$name]) ? $this->params[$name] : null;
105 }
106
107 /**
108 * put your comment there...
109 *
110 * @param mixed $package
111 * @param mixed $objects
112 * @return CJTxTable
113 */
114 public function save($package, $types) {
115 // Add package.
116 $tablePackage = CJTxTable::getInstance('package')
117 ->setData($package)
118 ->save();
119 // Add package objects map.
120 $tablePackageObjects = CJTxTable::getInstance('package-objects');
121 // Fetch objects under each type (block ,template).
122 foreach ($types as $type => $objects) {
123 // For each types get all object IDs!
124 foreach ($objects as $object) {
125 $tablePackageObjects->setItem() // Reset is needed as the object used accross multiple records
126 // and might cause interfering between records!
127 ->setData($object)
128 ->set('packageId', $tablePackage->get('id'))
129 ->set('objectType', $type)
130 ->save();
131 }
132 }
133 return $tablePackage->get('id');
134 }
135
136 /**
137 * put your comment there...
138 *
139 * @param mixed $name
140 * @param mixed $value
141 */
142 public function setParam($name, $value) {
143 // Set internal parameter value.
144 $this->params[$name] = $value;
145 // Chaining.
146 return $this;
147 }
148
149 } // End class.
150
151 // Hookable!
152 CJTPackageModel::define('CJTPackageModel', array('hookType' => CJTWordpressEvents::HOOK_FILTER));