PluginProbe
Depicter — Popup & Slider Builder / 1.9.2
Depicter — Popup & Slider Builder v1.9.2
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / app / src / Database / Entity / Model.php

Model.php in Depicter — Popup & Slider Builder 1.9.2, at app/src/Database/Entity/Model.php

77 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Depicter\Database\Entity;
3
4 use Averta\Core\Utility\Arr;
5 use TypeRocket\Models\Model as BaseModel;
6
7 class Model extends BaseModel
8 {
9 /**
10 * Determines what fields should be updated automatically.
11 *
12 * @var array
13 */
14 protected $autoFill = [];
15
16 /**
17 * Update resource fields
18 *
19 * @param array $fields
20 *
21 * @return mixed
22 */
23 public function update( $fields = [] )
24 {
25 $fields = $this->formatProperties( $fields );
26 return parent::update( $fields );
27 }
28
29 /**
30 * Create resource by fields
31 *
32 * When a resource is created the Model ID should be set to the
33 * resource's ID.
34 *
35 * @param array $fields
36 *
37 * @return mixed
38 */
39 public function create( $fields = [] )
40 {
41 $fields = $this->formatProperties( $fields );
42 return parent::create( $fields );
43 }
44
45 /**
46 * Format properties
47 *
48 * @param array $fields
49 *
50 * @return array
51 */
52 public function formatProperties( $fields )
53 {
54 $fields = Arr::merge( $fields, $this->autoFill );
55
56 foreach( $fields as $name => $value ) {
57 if( ! empty( $this->format[ $name ] ) && is_callable( $this->format[ $name ] ) ){
58 $fields[ $name ] = call_user_func( $this->format[ $name ], $value );
59 }
60 }
61
62 return $fields;
63 }
64
65
66 /**
67 * Get Date Time
68 *
69 * @return bool|string
70 */
71 public function getDateTime()
72 {
73 return gmdate('Y-m-d H:i:s', time());
74 }
75
76 }
77