1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Apps\ActiveRecord; |
4
|
|
|
|
5
|
|
|
use Ffcms\Core\App as MainApp; |
6
|
|
|
use Ffcms\Core\Arch\ActiveModel; |
7
|
|
|
use Ffcms\Core\Cache\MemoryObject; |
8
|
|
|
use Ffcms\Core\Helper\Serialize; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class ProfileField. Active record model for additional profile fields management |
12
|
|
|
* @package Apps\ActiveRecord |
13
|
|
|
* @property int $id |
14
|
|
|
* @property string $type |
15
|
|
|
* @property string $name |
16
|
|
|
* @property string $reg_exp |
17
|
|
|
* @property string $reg_cond |
18
|
|
|
* @property string $created_at |
19
|
|
|
* @property string $updated_at |
20
|
|
|
*/ |
21
|
|
|
class ProfileField extends ActiveModel |
22
|
|
|
{ |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Get all table data using memory cache |
26
|
|
|
* @param array $columns |
27
|
|
|
* @return \Illuminate\Database\Eloquent\Collection|mixed|static[] |
28
|
|
|
*/ |
29
|
|
View Code Duplication |
public static function all($columns = ['*']) |
|
|
|
|
30
|
|
|
{ |
31
|
|
|
$cacheName = 'activerecord.profilefield.all.' . implode('.', $columns); |
32
|
|
|
$records = MemoryObject::instance()->get($cacheName); |
33
|
|
|
if ($records === null) { |
34
|
|
|
$records = parent::all($columns); |
35
|
|
|
MemoryObject::instance()->set($cacheName, $records); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
return $records; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @deprecated |
43
|
|
|
* @return \Illuminate\Database\Eloquent\Collection|mixed|static[] |
44
|
|
|
*/ |
45
|
|
|
public static function getAll() |
46
|
|
|
{ |
47
|
|
|
return self::all(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Get field name locale by field id |
52
|
|
|
* @param int $id |
53
|
|
|
* @return array|null|string |
54
|
|
|
*/ |
55
|
|
|
public static function getNameById($id) |
56
|
|
|
{ |
57
|
|
|
$all = self::all(); |
58
|
|
|
|
59
|
|
|
$record = $all->find($id); |
60
|
|
|
if ($record === null || $record === false) { |
61
|
|
|
return null; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
return Serialize::getDecodeLocale($record->name); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Get field type by field id |
69
|
|
|
* @param int $id |
70
|
|
|
* @return array|null|string |
71
|
|
|
*/ |
72
|
|
|
public static function getTypeById($id) |
73
|
|
|
{ |
74
|
|
|
$all = self::all(); |
75
|
|
|
|
76
|
|
|
$record = $all->find($id); |
77
|
|
|
if ($record === null || $record === false) { |
78
|
|
|
return null; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
return $record->type; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.