| 1 |
<?php |
| 2 |
namespace Depicter\Database\Entity; |
| 3 |
|
| 4 |
use Averta\WordPress\Database\Entity\Model; |
| 5 |
|
| 6 |
class DocumentAnalytics extends Model |
| 7 |
{ |
| 8 |
|
| 9 |
protected $idColumn = 'id'; |
| 10 |
|
| 11 |
protected $idForeign = 'source_id'; |
| 12 |
|
| 13 |
/** |
| 14 |
* Resource name. |
| 15 |
* |
| 16 |
* @var string |
| 17 |
*/ |
| 18 |
protected $resource = 'depicter_document_analytics'; |
| 19 |
|
| 20 |
/** |
| 21 |
* Determines what fields can be saved without be explicitly. |
| 22 |
* |
| 23 |
* @var array |
| 24 |
*/ |
| 25 |
protected $builtin = [ |
| 26 |
'source_id', |
| 27 |
'event_type', |
| 28 |
'ip_address', |
| 29 |
'user_id', |
| 30 |
'session_id', |
| 31 |
'created_at' |
| 32 |
]; |
| 33 |
|
| 34 |
protected $guard = [ 'id' ]; |
| 35 |
|
| 36 |
protected $format = [ |
| 37 |
'created_at' => 'currentDateTime' |
| 38 |
]; |
| 39 |
|
| 40 |
public function currentDateTime() { |
| 41 |
return gmdate('Y-m-d H:i:s', time()); |
| 42 |
} |
| 43 |
|
| 44 |
public function document(){ |
| 45 |
return $this->belongsTo(Document::class, 'source_id', 'id'); |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* Retrieves related meta field models |
| 50 |
* |
| 51 |
* @return Meta|\TypeRocket\Models\Model|null |
| 52 |
*/ |
| 53 |
public function meta(){ |
| 54 |
return $this->hasMany(Meta::class, 'relation_id', $this->idColumn ); |
| 55 |
} |
| 56 |
} |
| 57 |
|