3
* DO NOT EDIT -- This is an auto-generated class from the Helix Class Generator
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.
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
14
* Object -> Currencycode
16
class CurrencycodeTable extends Object {
21
protected $_cache = array();
22
protected $_initial = array();
36
public function __construct($id=null, $name=null) {
37
$db = Database::getInstance();
40
$this->description = null;
41
$this->abbreviation = null;
43
$this->createdById = null;
44
$this->updatedById = null;
45
$this->mdate = new Date();
46
$this->cdate = new Date();
47
$this->deleted = false;
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)}";
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}",
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"];
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;
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");
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)}";
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}",
110
$query .= "ORDER BY {$db->le}currencycode{$db->re}.log_sequence desc limit 1";
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"];
132
$db->changeDatabase($database);
136
public function __call($method, $arguments) {
137
if (preg_match('/^set(.*)$/', $method, $matches)) {
138
$property = lcfirst($matches[1]);
139
$this->{$property} = $arguments[0];
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;
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);
168
public function isDirty() {
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"]);
182
public function save() {
183
if (isset($this->_snapshot)) {return false;}
184
$status = $this->id>0 ? $this->update() : $this->insert();
186
foreach ($this->_cache as $class=>$list) {
187
foreach ($list as $type=>$object) {
189
$this->{"add" . $object->getClass()}($object, $type);
191
unset($this->_cache[$class]);
197
public function insert() {
198
if (isset($this->_snapshot)) {return false;}
199
global $session, $config;
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}",
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),
217
$status = $db->query($query);
218
$this->id = $db->getInsertedId();
220
if ($config["enable_database_log"]) {
227
public function update() {
228
if (isset($this->_snapshot)) {return false;}
229
global $session, $config;
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)}"
244
$status = $db->query($query);
246
if ($config["enable_database_log"]) {
256
protected function log() {
257
if (isset($this->_snapshot)) {return false;}
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){
266
$record[$k] = $dbLog->queryValue($v);
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} (",
278
$status = $dbLog->query($query);
280
$logSequence = $dbLog->getInsertedId();
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)
291
$dbLog->query($query);
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}"
300
$dbLog->query($query);
303
$db->changeDatabase($database);
307
public function delete() {
308
if (isset($this->_snapshot)) {return false;}
309
$this->deleted = true;
310
$status = $this->update();
314
public function unDelete() {
315
if (isset($this->_snapshot)) {return false;}
316
$this->deleted = false;
317
$status = $this->update();
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);
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);
337
public static function select($columns, $order=null, $where=null, $limit=null, $offset=0) {
338
$db = Database::getInstance();
341
$columns = is_array($columns) ? $columns : explode(",", $columns);
343
$query = implode(NL, array(
344
"SELECT " . implode(",", $columns),
345
"FROM {$db->le}currencycode{$db->le}",
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) : "")
354
if (count($columns)>1) {
355
while ($db->getRecord()) {
356
$records[] = $db->record;
359
while ($db->getRecord(false)) {
360
$records[] = $db->record[0];
364
return new Collection($records);
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);
372
public static function objects($order=null, $where=null, $limit=null, $offset=0) {
373
$db = Database::getInstance();
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;
389
return new Collection($objects);
392
public static function search($query=null, $order=null, $where=null, $limit=null, $offset=0) {
396
preg_match_all('/"([^"]+)"/i', $query, $matches, PREG_SET_ORDER);
397
foreach ($matches as $match) {
398
$keywords[] = $match[1];
401
$query = preg_replace('/"[^"]+"/i', '', $query);
402
foreach (preg_split('/ +/i',$query) as $keyword) {
403
$keywords[] = $keyword;
406
foreach ($keywords as $keyword) {
407
$clauses[] = "currencycode.name LIKE '%{$keyword}%' OR currencycode.description LIKE '%{$keyword}%' OR currencycode.abbreviation LIKE '%{$keyword}%'";
410
$search = implode(" AND ", $clauses);
411
$where = isset($where) ? "{$where} AND ({$search})" : "({$search})";
412
return Currencycode::objects($order, $where, $limit, $offset);
415
public function __toString() {
416
return "Currencycode Object [" . alt($this->id, "null") . "]";
419
public function string() {
420
return $this->__toString();
b'\\ No newline at end of file'