1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
<?php
use Illuminate\Database\Capsule\Manager as DB; use Carbon\Carbon as Carbon;
class Address extends BaseModel{ protected $table = "address";
public function customer(){ return $this->belongsTo('Customer'); }
public function country(){ return $this->belongsTo('Country', 'country_code', 'code'); }
// todo: decrypt on load public function decrypt(){ // $this->decrypted = 1; $this->address1 = aes_crypt($this->address1, 2); $this->address2 = aes_crypt($this->address2, 2); $this->address3 = aes_crypt($this->address3, 2); $this->full_address = $this->address1." ".$this->address2." ".$this->address3; $this->receiver_name = aes_crypt($this->receiver_name, 2); $this->receiver_tel = aes_crypt($this->receiver_tel, 2); return $this; }
public function encrypt(){ // $this->decrypted = 0; $this->address1 = aes_crypt($this->address1, 1); $this->address2 = aes_crypt($this->address2, 1); $this->address3 = aes_crypt($this->address3, 1); $this->receiver_name = aes_crypt($this->receiver_name, 1); $this->receiver_tel = aes_crypt($this->receiver_tel, 1); return $this; }
public function addressTypeName($langcode = false){ switch ($this->address_type) { case 'BILLING_ADDRESS': return 'Billing Address'; case 'DELIVERY_ADDRESS': return 'Delivery Address'; default: return $this->address_type; } }
public function toString($langcode = false){ if(!$langcode){ $langcode = $_SESSION['wlangcode']; } return "{$this->receiver_name}\n{$this->receiver_tel}\n{$this->address1}\n{$this->address2}\n{$this->address3}\n{$this->country->{"name_{$langcode}"}}"; }
public function toString2($langcode = false){ if(!$langcode){ $langcode = $_SESSION['wlangcode']; } return "{$this->address1}\n{$this->address2}\n{$this->address3}\n{$this->country->{"name_{$langcode}"}}"; }
public static function fromJsonString($str){ $obj = json_decode($str);
return new self(array( // 'id' => $obj->id, 'createby' => $obj->createby, 'createdate' => $obj->createdate, 'lastupby' => $obj->lastupby, 'lastupdate' => $obj->lastupdate, 'deleted' => $obj->deleted, 'customer_id' => $obj->customer_id, 'address_type' => $obj->address_type, 'city_code' => $obj->city_code, 'stat_code' => $obj->stat_code, 'country_code' => $obj->country_code, 'address1' => $obj->address1, 'address2' => $obj->address2, 'address3' => $obj->address3, 'default_address' => $obj->default_address, 'receiver_name' => $obj->receiver_name, 'receiver_tel' => $obj->receiver_tel, )); } }
|