~vcs-imports/helix/helix

« back to all changes in this revision

Viewing changes to trunk/modules/Core/Generated/Objects/Lookups/CurrencycodeTable.php

  • Committer: damianobrien
  • Date: 2015-07-08 19:49:46 UTC
  • Revision ID: svn-v4:05b9009a-c606-4cef-bdc0-1359a4facf5f::421
changed collection->add call to collection->append in the generator

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
/**
3
 
 * DO NOT EDIT -- This is an auto-generated class from the Helix Class Generator
4
 
 * 
5
 
 * This class represents the currencycode table in the Helix database schema.
6
 
 * Use this class to select, insert, update and delete data in the currencycode
7
 
 * table, as well as access related data in other tables.
8
 
 * 
9
 
 * If you need to extend the functionality of this class, code should be placed in a
10
 
 * class called CurrencycodeExtension, and should extend the CurrencycodeTable
11
 
 * class.  The custom code file should be in the helix/modules/Core folder
12
 
 * and should be called CurrencycodeExtension.php
13
 
 * 
14
 
 * Object -> Currencycode
15
 
 */
16
 
class CurrencycodeTable extends Object {
17
 
        public $logSequence;
18
 
        public $fdate;
19
 
        public $tdate;
20
 
 
21
 
        protected $_cache = array();
22
 
        protected $_initial = array();
23
 
        protected $_snapshot;
24
 
 
25
 
        public $id;
26
 
        public $name;
27
 
        public $description;
28
 
        public $abbreviation;
29
 
        public $number;
30
 
        public $createdById;
31
 
        public $updatedById;
32
 
        public $mdate;
33
 
        public $cdate;
34
 
        public $deleted;
35
 
 
36
 
        public function __construct($id=null, $name=null) {
37
 
                $db = Database::getInstance();
38
 
                $this->id = $id;
39
 
                $this->name = $name;
40
 
                $this->description = null;
41
 
                $this->abbreviation = null;
42
 
                $this->number = null;
43
 
                $this->createdById = null;
44
 
                $this->updatedById = null;
45
 
                $this->mdate = new Date();
46
 
                $this->cdate = new Date();
47
 
                $this->deleted = false;
48
 
 
49
 
                if (isset($id)) {
50
 
                        $condition = "{$db->le}currencycode{$db->re}.{$db->le}id{$db->re}={$db->queryValue($id)}";
51
 
                } else if (isset($name)) {
52
 
                        $condition = "{$db->le}currencycode{$db->re}.{$db->le}name{$db->re}={$db->queryValue($name)}";
53
 
                }
54
 
 
55
 
                if (isset($condition)) {
56
 
                        $query = implode(NL, array(
57
 
                                "SELECT {$db->le}currencycode{$db->re}.{$db->le}id{$db->re}, {$db->le}currencycode{$db->re}.{$db->le}name{$db->re}, {$db->le}currencycode{$db->re}.{$db->le}description{$db->re}, {$db->le}currencycode{$db->re}.{$db->le}abbreviation{$db->re}, {$db->le}currencycode{$db->re}.{$db->le}number{$db->re}, {$db->le}currencycode{$db->re}.{$db->le}created_by_id{$db->re}, {$db->le}currencycode{$db->re}.{$db->le}updated_by_id{$db->re}, {$db->le}currencycode{$db->re}.{$db->le}mdate{$db->re}, {$db->le}currencycode{$db->re}.{$db->le}cdate{$db->re}, {$db->le}currencycode{$db->re}.{$db->le}deleted{$db->re}",
58
 
                                "FROM {$db->le}currencycode{$db->re}",
59
 
                                "WHERE {$condition}"
60
 
                        ));
61
 
 
62
 
                        $db->query($query);
63
 
 
64
 
                        if ($db->getRecord() && $db->getNumRows()===1) {
65
 
                                $this->id = $db->record["id"];
66
 
                                $this->name = $db->record["name"];
67
 
                                $this->description = $db->record["description"];
68
 
                                $this->abbreviation = $db->record["abbreviation"];
69
 
                                $this->number = $db->record["number"];
70
 
                                $this->createdById = $db->record["created_by_id"];
71
 
                                $this->updatedById = $db->record["updated_by_id"];
72
 
                                $this->mdate = is_null(($db->record["mdate"]))?null:new Date($db->record["mdate"]);
73
 
                                $this->cdate = is_null(($db->record["cdate"]))?null:new Date($db->record["cdate"]);
74
 
                                $this->deleted = $db->record["deleted"];
75
 
                        } else {
76
 
                                $this->id = null;
77
 
                        }
78
 
                }
79
 
 
80
 
                $this->_initial["id"] = $this->id;
81
 
                $this->_initial["name"] = $this->name;
82
 
                $this->_initial["description"] = $this->description;
83
 
                $this->_initial["abbreviation"] = $this->abbreviation;
84
 
                $this->_initial["number"] = $this->number;
85
 
                $this->_initial["createdById"] = $this->createdById;
86
 
                $this->_initial["deleted"] = $this->deleted;
87
 
        }
88
 
 
89
 
        public static function snapshot($date, $id=null, $name=null) {
90
 
                $object = new Currencycode();
91
 
                $object->_snapshot = $date;
92
 
                $db = Database::getInstance();
93
 
                $database = $db->getDatabase();
94
 
                $db->changeDatabase($database . "_log");
95
 
 
96
 
                if (isset($id)) {
97
 
                        $condition = "{$db->le}currencycode{$db->re}.{$db->le}id{$db->re}={$db->queryValue($id)}";
98
 
                } else if (isset($name)) {
99
 
                        $condition = "{$db->le}currencycode{$db->re}.{$db->le}name{$db->re}={$db->queryValue($name)}";
100
 
                }
101
 
 
102
 
                if (isset($condition)) {
103
 
                        $condition .= " AND ({$db->le}currencycode{$db->re}.{$db->le}tdate{$db->re} IS NOT NULL AND {$db->le}currencycode{$db->re}.{$db->le}fdate{$db->re}<={$db->queryValue($date)} AND {$db->queryValue($date)}<={$db->le}currencycode{$db->re}.{$db->le}tdate{$db->re}) ";
104
 
                        $query = implode(NL, array(
105
 
                                "SELECT {$db->le}currencycode{$db->re}.{$db->le}log_sequence{$db->re}, {$db->le}currencycode{$db->re}.{$db->le}fdate{$db->re}, {$db->le}currencycode{$db->re}.{$db->le}tdate{$db->re}, {$db->le}currencycode{$db->re}.{$db->le}id{$db->re}, {$db->le}currencycode{$db->re}.{$db->le}name{$db->re}, {$db->le}currencycode{$db->re}.{$db->le}description{$db->re}, {$db->le}currencycode{$db->re}.{$db->le}abbreviation{$db->re}, {$db->le}currencycode{$db->re}.{$db->le}number{$db->re}, {$db->le}currencycode{$db->re}.{$db->le}created_by_id{$db->re}, {$db->le}currencycode{$db->re}.{$db->le}updated_by_id{$db->re}, {$db->le}currencycode{$db->re}.{$db->le}mdate{$db->re}, {$db->le}currencycode{$db->re}.{$db->le}cdate{$db->re}, {$db->le}currencycode{$db->re}.{$db->le}deleted{$db->re}",
106
 
                                "FROM {$db->le}currencycode{$db->re}",
107
 
                                "WHERE {$condition}"
108
 
                        ));
109
 
 
110
 
                        $query .= "ORDER BY {$db->le}currencycode{$db->re}.log_sequence desc limit 1";
111
 
                        $db->query($query);
112
 
 
113
 
                        if ($db->getRecord() && $db->getNumRows()===1) {
114
 
                                $object->logSequence = $db->record["log_sequence"];
115
 
                                $object->fdate = new Date($db->record["fdate"]);
116
 
                                $object->tdate = new Date($db->record["tdate"]);
117
 
                                $object->id = $db->record["id"];
118
 
                                $object->name = $db->record["name"];
119
 
                                $object->description = $db->record["description"];
120
 
                                $object->abbreviation = $db->record["abbreviation"];
121
 
                                $object->number = $db->record["number"];
122
 
                                $object->createdById = $db->record["created_by_id"];
123
 
                                $object->updatedById = $db->record["updated_by_id"];
124
 
                                $object->mdate = is_null(($db->record["mdate"]))?null:new Date($db->record["mdate"]);
125
 
                                $object->cdate = is_null(($db->record["cdate"]))?null:new Date($db->record["cdate"]);
126
 
                                $object->deleted = $db->record["deleted"];
127
 
                        } else {
128
 
                                $object->id = null;
129
 
                        }
130
 
                }
131
 
                
132
 
                $db->changeDatabase($database);
133
 
                return $object;
134
 
        }
135
 
 
136
 
        public function __call($method, $arguments) {
137
 
                if (preg_match('/^set(.*)$/', $method, $matches)) {
138
 
                        $property = lcfirst($matches[1]);
139
 
                        $this->{$property} = $arguments[0];
140
 
                }
141
 
                return $this;
142
 
        }
143
 
 
144
 
        public function __get($property) {
145
 
                if (method_exists($this, "get{$property}")) {
146
 
                        return $this->{"get{$property}"}();
147
 
                } else if (strstr($property, "_")) {
148
 
                        list($type, $method) = explode("_", $property, 2);
149
 
                        return method_exists($this, "get{$method}") ? $this->{"get{$method}"}($type) : null;
150
 
                } else {
151
 
                        return null;
152
 
                }
153
 
        }
154
 
 
155
 
        public function __set($property, $value) {
156
 
                if (isset($this->_snapshot)) {return false;}
157
 
                if (method_exists($this, "set{$property}")) {
158
 
                        $this->{"set{$property}"}($value);
159
 
                } else if (strstr($property, "_")) {
160
 
                        list($type, $method) = explode("_", $property, 2);
161
 
                        if (method_exists($this, "set{$method}")) {
162
 
                                $this->{"set{$method}"}($value, $type);
163
 
                        }
164
 
                }
165
 
                return $this;
166
 
        }
167
 
 
168
 
        public function isDirty() {
169
 
                $isDirty = false;
170
 
 
171
 
                $isDirty = $isDirty || ((int)$this->id !== (int)$this->_initial["id"]);
172
 
                $isDirty = $isDirty || ((string)$this->name !== (string)$this->_initial["name"]);
173
 
                $isDirty = $isDirty || ((string)$this->description !== (string)$this->_initial["description"]);
174
 
                $isDirty = $isDirty || ((string)$this->abbreviation !== (string)$this->_initial["abbreviation"]);
175
 
                $isDirty = $isDirty || ((int)$this->number !== (int)$this->_initial["number"]);
176
 
                $isDirty = $isDirty || ((int)$this->createdById !== (int)$this->_initial["createdById"]);
177
 
                $isDirty = $isDirty || ((int)$this->deleted !== (int)$this->_initial["deleted"]);
178
 
 
179
 
                return $isDirty;
180
 
        }
181
 
 
182
 
        public function save() {
183
 
                if (isset($this->_snapshot)) {return false;}
184
 
                $status = $this->id>0 ? $this->update() : $this->insert();
185
 
 
186
 
                foreach ($this->_cache as $class=>$list) {
187
 
                        foreach ($list as $type=>$object) {
188
 
                                $object->save();
189
 
                                $this->{"add" . $object->getClass()}($object, $type);
190
 
                        }
191
 
                        unset($this->_cache[$class]);
192
 
                }
193
 
 
194
 
                return $status;
195
 
        }
196
 
 
197
 
        public function insert() {
198
 
                if (isset($this->_snapshot)) {return false;}
199
 
                global $session, $config;
200
 
 
201
 
                $db = Database::getInstance();
202
 
                $query = implode(NL, array(
203
 
                        "INSERT INTO {$db->le}currencycode{$db->re} (",
204
 
                        "       {$db->le}name{$db->re}, {$db->le}description{$db->re}, {$db->le}abbreviation{$db->re}, {$db->le}number{$db->re}, {$db->le}created_by_id{$db->re}, {$db->le}updated_by_id{$db->re}, {$db->le}mdate{$db->re}, {$db->le}cdate{$db->re}, {$db->le}deleted{$db->re}",
205
 
                        ") VALUES (",
206
 
                                $db->queryValue($this->name) . ",",
207
 
                                $db->queryValue($this->description) . ",",
208
 
                                $db->queryValue($this->abbreviation) . ",",
209
 
                                $db->queryValue(is_null($this->number)?null:(int)$this->number) . ",",
210
 
                                $db->queryValue((int)$session->getUserId()) . ",",
211
 
                                $db->queryValue((int)$session->getUserId()) . ",",
212
 
                                $db->queryValue(timestamp()) . ",",
213
 
                                $db->queryValue(timestamp()) . ",",
214
 
                                $db->queryValue(is_null($this->deleted)?null:(int)$this->deleted),
215
 
                        ")"
216
 
                ));
217
 
                $status = $db->query($query);
218
 
                $this->id = $db->getInsertedId();
219
 
 
220
 
                if ($config["enable_database_log"]) {
221
 
                        $this->log();
222
 
                }
223
 
 
224
 
                return $status;
225
 
        }
226
 
 
227
 
        public function update() {
228
 
                if (isset($this->_snapshot)) {return false;}
229
 
                global $session, $config;
230
 
 
231
 
                if ($this->isDirty()) {
232
 
                        $db = Database::getInstance();
233
 
                        $query = implode(NL, array(
234
 
                                "UPDATE {$db->le}currencycode{$db->re} SET",
235
 
                                        "{$db->le}name{$db->re}={$db->queryValue($this->name)},",
236
 
                                        "{$db->le}description{$db->re}={$db->queryValue($this->description)},",
237
 
                                        "{$db->le}abbreviation{$db->re}={$db->queryValue($this->abbreviation)},",
238
 
                                        "{$db->le}number{$db->re}={$db->queryValue(is_null($this->number)?null:(int)$this->number)},",
239
 
                                        "{$db->le}updated_by_id{$db->re}={$db->queryValue((int)$session->getUserId())},",
240
 
                                        "{$db->le}mdate{$db->re}={$db->queryValue(timestamp())},",
241
 
                                        "{$db->le}deleted{$db->re}={$db->queryValue(is_null($this->deleted)?null:(int)$this->deleted)}",
242
 
                                "WHERE id={$db->queryValue((int)$this->id)}"
243
 
                        ));
244
 
                        $status = $db->query($query);
245
 
 
246
 
                        if ($config["enable_database_log"]) {
247
 
                                $this->log();
248
 
                        }
249
 
 
250
 
                        return $status;
251
 
                } else {
252
 
                        return false;
253
 
                }
254
 
        }
255
 
 
256
 
        protected function log() {
257
 
                if (isset($this->_snapshot)) {return false;}
258
 
                parent::log();
259
 
                $db = Database::getInstance();
260
 
                $database = $db->getDatabase();
261
 
                $record = Currencycode::select($db->encapsulate("currencycode") . ".mdate as fdate,null as tdate,{$db->encapsulate("currencycode")}.*",null,$db->encapsulate("currencycode").".id={$this->id}")->first();
262
 
                $log = "{$database}_log";
263
 
                $dbLog = Database::getInstance(null,null,null,null,$log);
264
 
                foreach($record as $k=>$v){
265
 
                    if(!is_int($v)){
266
 
                        $record[$k] = $dbLog->queryValue($v);
267
 
                    }
268
 
                }
269
 
                $insertColumns = $dbLog->le.implode("{$dbLog->le},{$dbLog->re}",array_keys($record)).$dbLog->re;
270
 
                $insertValues = implode(",",$record);
271
 
                $query = implode(NL, array(
272
 
                        "INSERT INTO {$dbLog->le}currencycode{$dbLog->re} (",
273
 
                        $insertColumns,
274
 
                        ") VALUES (",
275
 
                        $insertValues,
276
 
                        ")"
277
 
                ));
278
 
                $status = $dbLog->query($query);
279
 
 
280
 
                $logSequence = $dbLog->getInsertedId();
281
 
 
282
 
                if ($logSequence){
283
 
                        $query = implode(NL, array(
284
 
                                "SELECT {$dbLog->le}log_sequence{$dbLog->re}",
285
 
                                "FROM {$dbLog->le}currencycode{$dbLog->re}",
286
 
                                "WHERE {$dbLog->le}currencycode{$dbLog->re}.{$dbLog->le}id{$dbLog->re}={$this->id}",
287
 
                                "       AND {$dbLog->le}log_sequence{$dbLog->re}<{$logSequence}",
288
 
                                "ORDER BY {$dbLog->le}log_sequence{$dbLog->re} DESC",
289
 
                                $dbLog::limitOffsetString(1,0)
290
 
                        ));
291
 
                        $dbLog->query($query);
292
 
 
293
 
                        if ($dbLog->getRecord()) {
294
 
                                $updateSequence = (int)$dbLog->record["log_sequence"];
295
 
                                $query = implode(NL, array(
296
 
                                        "UPDATE {$dbLog->le}currencycode{$dbLog->re}",
297
 
                                        "SET {$dbLog->le}tdate{$dbLog->re}={$record["mdate"]}",
298
 
                                        "where log_sequence={$updateSequence}"
299
 
                                ));
300
 
                                $dbLog->query($query);
301
 
                        }
302
 
                }
303
 
                $db->changeDatabase($database);
304
 
                return $status;
305
 
        }
306
 
 
307
 
        public function delete() {
308
 
                if (isset($this->_snapshot)) {return false;}
309
 
                $this->deleted = true;
310
 
                $status = $this->update();
311
 
                return $status;
312
 
        }
313
 
 
314
 
        public function unDelete() {
315
 
                if (isset($this->_snapshot)) {return false;}
316
 
                $this->deleted = false;
317
 
                $status = $this->update();
318
 
                return $status;
319
 
        }
320
 
 
321
 
        public function purge() {
322
 
                if (isset($this->_snapshot)) {return false;}
323
 
                $db = Database::getInstance();
324
 
                $query = "DELETE FROM " . $db->encapsulate("currencycode") . " WHERE id={$db->queryValue($this->id)}";
325
 
                $status = $db->query($query);
326
 
                return $status;
327
 
        }
328
 
 
329
 
        public static function deleteAll($where=null) {
330
 
                $db = Database::getInstance();
331
 
                $condition = isset($where) ? "WHERE {$where}" : "";
332
 
                $query = "UPDATE " . $db->encapsulate("currencycode") . " SET deleted=1 {$condition}";
333
 
                $status = $db->query($query);
334
 
                return $status;
335
 
        }
336
 
 
337
 
        public static function select($columns, $order=null, $where=null, $limit=null, $offset=0) {
338
 
                $db = Database::getInstance();
339
 
 
340
 
                $records = array();
341
 
                $columns = is_array($columns) ? $columns : explode(",", $columns);
342
 
 
343
 
                $query = implode(NL, array(
344
 
                        "SELECT " . implode(",", $columns),
345
 
                        "FROM {$db->le}currencycode{$db->le}",
346
 
 
347
 
                        "WHERE {$db->le}currencycode{$db->re}.{$db->le}deleted{$db->re}=0" . (isset($where) ? " AND ({$where})" : ""),
348
 
                        (isset($order) ? "ORDER BY {$order}" : ""),
349
 
                        (isset($limit) ? $db::limitOffsetString($limit,$offset) : "")
350
 
                ));
351
 
 
352
 
                $db->query($query);
353
 
 
354
 
                if (count($columns)>1) {
355
 
                        while ($db->getRecord()) {
356
 
                                $records[] = $db->record;
357
 
                        }
358
 
                } else {
359
 
                        while ($db->getRecord(false)) {
360
 
                                $records[] = $db->record[0];
361
 
                        }
362
 
                }
363
 
 
364
 
                return new Collection($records);
365
 
        }
366
 
 
367
 
        public static function ids($order=null, $where=null, $limit=null, $offset=0) {
368
 
                $db = Database::getInstance();
369
 
                return Currencycode::select("{$db->le}currencycode{$db->le}.id", $order, $where, $limit, $offset);
370
 
        }
371
 
 
372
 
        public static function objects($order=null, $where=null, $limit=null, $offset=0) {
373
 
                $db = Database::getInstance();
374
 
                $objects = array();
375
 
                foreach (Currencycode::select("{$db->le}currencycode{$db->re}.{$db->le}id{$db->re}, {$db->le}currencycode{$db->re}.{$db->le}name{$db->re}, {$db->le}currencycode{$db->re}.{$db->le}description{$db->re}, {$db->le}currencycode{$db->re}.{$db->le}abbreviation{$db->re}, {$db->le}currencycode{$db->re}.{$db->le}number{$db->re}, {$db->le}currencycode{$db->re}.{$db->le}created_by_id{$db->re}, {$db->le}currencycode{$db->re}.{$db->le}updated_by_id{$db->re}, {$db->le}currencycode{$db->re}.{$db->le}mdate{$db->re}, {$db->le}currencycode{$db->re}.{$db->le}cdate{$db->re}, {$db->le}currencycode{$db->re}.{$db->le}deleted{$db->re}", $order, $where, $limit, $offset) as $record) {
376
 
                        $object = new Currencycode();
377
 
                                $object->id = $record["id"];
378
 
                                $object->name = $record["name"];
379
 
                                $object->description = $record["description"];
380
 
                                $object->abbreviation = $record["abbreviation"];
381
 
                                $object->number = $record["number"];
382
 
                                $object->createdById = $record["created_by_id"];
383
 
                                $object->updatedById = $record["updated_by_id"];
384
 
                                $object->mdate = is_null(($record["mdate"]))?null:new Date($record["mdate"]);
385
 
                                $object->cdate = is_null(($record["cdate"]))?null:new Date($record["cdate"]);
386
 
                                $object->deleted = $record["deleted"];
387
 
                        $objects[] = $object;
388
 
                }
389
 
                return new Collection($objects);
390
 
        }
391
 
 
392
 
        public static function search($query=null, $order=null, $where=null, $limit=null, $offset=0) {
393
 
                $keywords = array();
394
 
                $clauses = array();
395
 
 
396
 
                preg_match_all('/"([^"]+)"/i', $query, $matches, PREG_SET_ORDER);
397
 
                foreach ($matches as $match) {
398
 
                        $keywords[] = $match[1];
399
 
                }
400
 
 
401
 
                $query = preg_replace('/"[^"]+"/i', '', $query);
402
 
                foreach (preg_split('/ +/i',$query) as $keyword) {
403
 
                        $keywords[] = $keyword;
404
 
                }
405
 
 
406
 
                foreach ($keywords as $keyword) {
407
 
                        $clauses[] = "currencycode.name LIKE '%{$keyword}%' OR currencycode.description LIKE '%{$keyword}%' OR currencycode.abbreviation LIKE '%{$keyword}%'";
408
 
                }
409
 
 
410
 
                $search = implode(" AND ", $clauses);
411
 
                $where = isset($where) ? "{$where} AND ({$search})" : "({$search})";
412
 
                return Currencycode::objects($order, $where, $limit, $offset);
413
 
        }
414
 
 
415
 
        public function __toString() {
416
 
                return "Currencycode Object [" . alt($this->id, "null") . "]";
417
 
        }
418
 
 
419
 
        public function string() {
420
 
                return $this->__toString();
421
 
        }
422
 
 
423
 
 
424
 
 
425
 
 
426
 
 
427
 
}
428
 
?>
 
 
b'\\ No newline at end of file'