3 CREATE TABLE `builder`.`builder_part` (
4 `id` int(11) NOT NULL AUTO_INCREMENT,
5 `module_id` int(11) NOT NULL,
6 `name` varchar(254) NOT NULL,
7 `json` longtext NOT NULL,
13 * Table Definition for builder_app
15 require_once 'DB/DataObject.php';
18 class Pman_Builder_DataObjects_Builder_part extends DB_DataObject
21 /* the code below is auto generated do not remove the above tag */
23 public $__table = 'builder_part'; // table name
24 public $id; // int(11) not_null primary_key auto_increment
25 public $name; // string(128) not_null
26 public $json; // blob(-1) not_null blob
27 public $jsource; // blob(-1) not_null blob
29 public $module_id; // string(16) not_null
30 public $updated; // string(16) not_null
33 /* the code above is auto generated do not remove the tag below */
35 /*function applySort($au, $sort, $dir, $cols)
37 // DB_DAtaObject::debugLevel(1);
38 $this->orderBy( 'builder.app asc, builder.module asc');
43 function applyFilters($q, $au)
45 //DB_DataObject::debugLEvel(1);
46 if (!empty($q['module_id'])) {
47 // we should only do this on a menu calll to sync. really..
48 $m = DB_DataObject::factory('builder_modules');
49 $m->get($q['module_id']);
58 $m = DB_DataObject::Factory('builder_modules');
59 $m->get($this->module_id);
65 function beforeDelete($deps)
69 $m->gitCommitDelete($this->name . '.bjs');
70 $m->gitCommitDelete($this->name . '.js');
76 function onInsert($req,$roo)
78 // write it to a file... use date time... - which should hopefully be the same as the
79 //event that was created..
80 $this->writeEventFile($roo,$req);
81 $this->syncTemplate();
83 function onUpdate($old , $req, $roo)
85 $this->writeEventFile($roo,$req);
86 $this->syncTemplate();
89 function writeEventFile($roo,$req)
92 // try and commit it..
95 $m->gitCommit($this->name . '.bjs', $this->bjs());
96 $m->gitCommit($this->name . '.js', $this->jsource);
97 if (!empty($req['html'])) {
98 // $roo->jerr("write html? {$this->name}.html");
99 $m->gitCommit($this->name . '.html', $req['html']);
102 // writes to session page?
103 $sp = ini_get('session.save_path').'/Builder/'.date('Y/m');
104 if (!file_exists($sp)) {
105 mkdir($sp, 0755, true);
107 $fn = $sp .'/'. $this->id . '-'. $this->name . '-'. date('d-H-i-s') . '.bjs';
108 require_once 'Services/JSON.php';
109 $json = Services_JSON::stringify(json_decode($this->json), null, 4);
111 file_put_contents($fn , $json);
116 $data = json_decode($this->json);
117 // munge data into bjs format..
119 $data->title = isset($data->title) ? $data->title : $data->name;
122 require_once 'Services/JSON.php';
123 return Services_JSON::stringify($data,null,4);
129 function writeCopy($path,$roo)
132 if (!file_exists($path)) {
137 require_once 'Pman/Builder/Code.php';
138 $x = new Pman_Builder_Code();
139 $this->_new_file = false;
140 if (!file_exists($path.'/'. $this->module.'.js')) {
141 $this->_new_file = true;
143 if (!$this->_new_file && !is_writable($path.'/'. $this->module.'.js')) {
144 $roo->jerr("Can not write to " . $path.'/'. $this->module.'.js');
147 if ($this->_new_file && !is_writable($path)) {
148 $roo->jerr("Can not write to " . $path);
152 file_put_contents($path.'/'. $this->module.'.js',
153 $x->toJSFile(json_decode($this->json))) ;
154 return $path.'/'. $this->module.'.js';
158 function toRooSingleArray()
160 // echo '<PRE>';print_R($this);exit;
162 $ret = $this->toArray();
167 function toRooArray()
169 $ret = $this->toArray();
175 // update return the code.!!!
176 if (isset($_SERVER["REQUEST_METHOD"]) && $_SERVER["REQUEST_METHOD"] == 'POST') {
177 require_once 'Pman/Builder/Code.php';
178 $x = new Pman_Builder_Code();
179 $ret['code'] = $x->toJSFile(json_decode($this->json), $this->json);
185 function syncTemplate()
187 // possibly needs to be cleverer = if template is a dialog etc.?
189 $m = $this->module();
190 $t = DB_DataObject::Factory('cms_template');
191 $t->view_name = $m->name;
192 $t->template = $this->name . '.html';
194 if (!$t->find(true)) {
195 $t->updated = $t->sqlValue('NOW()');
199 $t->updated = $t->sqlValue('NOW()');