PluginProbe
CSS & JavaScript Toolbox / 8.1
CSS & JavaScript Toolbox v8.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 / models / package.php

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

135 lines 3.4 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 */
112 public function save($package) {
113 // Add package.
114 return CJTxTable::getInstance('package')
115 ->setData($package)
116 ->save()->get('id');
117 }
118
119 /**
120 * put your comment there...
121 *
122 * @param mixed $name
123 * @param mixed $value
124 */
125 public function setParam($name, $value) {
126 // Set internal parameter value.
127 $this->params[$name] = $value;
128 // Chaining.
129 return $this;
130 }
131
132 } // End class.
133
134 // Hookable!
135 CJTPackageModel::define('CJTPackageModel', array('hookType' => CJTWordpressEvents::HOOK_FILTER));