[go: up one dir, main page]

Menu

[3822d7]: / core / Message.php  Maximize  Restore  History

Download this file

153 lines (128 with data), 3.6 kB

  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
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
namespace ICT\Core;
/* * ***************************************************************
* Copyright © 2014 ICT Innovations Pakistan All Rights Reserved *
* Developed By: Nasir Iqbal *
* Website : http://www.ictinnovations.com/ *
* Mail : nasir@ictinnovations.com *
* *************************************************************** */
use JsonSerializable;
class Message implements JsonSerializable
{
protected static $table = 'message';
protected static $fields = array(
'message_id'
);
protected static $read_only = array(
'message_id'
);
/**
* @property-read integer $message_id
* @var integer
*/
protected $message_id = NULL;
/** @var string */
public $name = NULL;
/** @var string */
public $data = NULL;
/**
* @property-read integer $user_id
* owner id of current record
* @var integer
*/
public $user_id = NULL;
/**
* Default mime type for this message type, when no type is available
* @var string
*/
public static $media_default = 'application/octet-stream';
/**
* Array of all supported file extensions along with mime types as keys
* @var array $media_supported
*/
public static $media_supported = array(
'dat' => 'application/octet-stream'
);
public function __construct($message_id = NULL)
{
if (!empty($message_id)) {
$this->message_id = $message_id;
$this->load();
}
}
public static function construct_from_array($aData)
{
$oMessage = new static();
foreach ($aData as $field => $value) {
$oMessage->$field = $value;
}
return $oMessage;
}
public static function search($aFilter = array())
{
Corelog::log("message search filter: " . print_r($aFilter, true), Corelog::CRUD);
}
protected function load()
{
// load, delete and save are table spacific so leaving them empty in parent class
}
public function delete()
{
// load, delete and save are table spacific so leaving them empty in parent class
}
public function __isset($field)
{
$method_name = 'isset_' . $field;
if (method_exists($this, $method_name)) {
return $this->$method_name();
} else {
return isset($this->$field);
}
}
public function jsonSerialize():mixed
{
$json = array();
foreach($this as $key => $value) {
$json[$key] = $value;
}
$extra_fields = array_diff(static::$read_only, array_keys($json));
foreach($extra_fields as $key) {
$json[$key] = $this->$key;
}
return $json;
}
public function __get($field)
{
$method_name = 'get_' . $field;
if (method_exists($this, $method_name)) {
return $this->$method_name();
} else if (!empty($field) && isset($this->$field)) {
return $this->$field;
}
return NULL;
}
public function __set($field, $value)
{
$method_name = 'set_' . $field;
if (method_exists($this, $method_name)) {
$this->$method_name($value);
} else if (empty($field) || in_array($field, static::$read_only)) {
return;
} else {
$this->$field = $value;
}
}
public function get_id()
{
return $this->message_id;
}
public function save()
{
// load, delete and save are table spacific so leaving them empty in parent class
}
public function token_apply(Token $oToken, $default_value = Token::KEEP_ORIGNAL)
{
// replace tokens with given values, if current message type support this
$this->data = $oToken->render_variable($this->data, $default_value);
}
}