PluginProbe
CSS & JavaScript Toolbox / 8.0.3
CSS & JavaScript Toolbox v8.0.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 / models / templates-lookup.php

templates-lookup.php in CSS & JavaScript Toolbox 8.0.3, at models/templates-lookup.php

114 lines 2.9 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 // Import dependencies
7 cssJSToolbox::import('framework:db:mysql:xtable.inc.php');
8
9 /**
10 *
11 */
12 class CJTTemplatesLookupModel {
13
14 /**
15 * put your comment there...
16 *
17 * @var mixed
18 */
19 public $inputs;
20
21 /**
22 * put your comment there...
23 *
24 */
25 public function embedded() {
26 // Read template revision.
27 $revision = CJTxTable::getInstance('template-revision')
28 ->fetchLastRevision($this->inputs['templateId']);
29 // Revision could not be queried!!
30 if (!$revision->get('id')) {
31 throw new Exception('Revision could not be found!!');
32 }
33 $revisionFile = $revision->get('file');
34 // Read revision code.
35 $code = file_get_contents(ABSPATH . "/{$revisionFile}");
36 // Decrypt PHP codes!
37 if (preg_match('/\.php$/', $revisionFile)) {
38 $code = CJTModel::getInstance('template')->decryptCode($code);
39 }
40 return $code;
41 }
42
43 /**
44 * put your comment there...
45 *
46 */
47 public function getItems() {
48 // Initialize variables.
49 foreach (cssJSToolbox::$config->templates->types as $typeId => $object) {
50 $arrangedItems[$typeId] = array();
51 }
52 $query = "SELECT t.id, t.type, t.name, t.description, (t.attributes & 1) systemTemplate,
53 a.name author,
54 bt.blockId linked
55 FROM #__cjtoolbox_templates t
56 LEFT JOIN #__cjtoolbox_authors a
57 ON t.authorId = a.id
58 LEFT JOIN
59 (SELECT *
60 FROM #__cjtoolbox_block_templates
61 WHERE blockId = {$this->inputs['blockId']}
62 ) bt
63 ON t.id = bt.templateId
64 WHERE t.state = 'published'";
65 $items = cssJSToolbox::getInstance()->getDBDriver()->select($query);
66 // First we need to group the templates by its type.
67 $templatesGrouped = array();
68 foreach ($items as $id => $template) {
69 // [TEMPLATE-TYPE][AUTHOR-NAME][TEMPLATE-ID] = TEMPLATE.
70 $arrangedItems[$template->type][$template->author][$id] = $template;
71 }
72 return $arrangedItems;
73 }
74
75 /**
76 * put your comment there...
77 *
78 */
79 public function link() {
80 // Add db record!
81 $map = CJTxTable::getInstance('block-template')
82 ->setData($this->inputs) // Load with data
83 ->save();
84 // There will be an id when successed!
85 return $map->get('id');
86 }
87
88 /**
89 * put your comment there...
90 *
91 */
92 public function unlink() {
93 // Delete record!
94 $map = CJTxTable::getInstance('block-template')
95 ->setData($this->inputs) // Load with data
96 ->delete(array_keys($this->inputs)); // Delete using compound key!
97 // Fields will be cleared when deleted!
98 return $map->getKey();
99 }
100
101 /**
102 * put your comment there...
103 *
104 */
105 public function unlinkAll() {
106 $query = "DELETE FROM #__cjtoolbox_block_templates
107 WHERE blockId = {$this->inputs['blockId']}";
108 cssJSToolbox::getInstance()->getDBDriver()
109 ->delete($query)
110 ->processQueue();
111 }
112
113 } // End class.
114