forked from stackboxcms/stackboxcms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Entity.php
66 lines (58 loc) · 1.9 KB
/
Entity.php
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
<?php
namespace Module\Site;
use Stackbox, Spot;
/**
* Site entity - what properties define a site
*/
class Entity extends Stackbox\EntityAbstract
{
const STATUS_ACTIVE = 1;
const STATUS_DISABLED = 0;
// Table
protected static $_datasource = "sites";
/**
* Fields
*/
public static function fields() {
return array(
'id' => array('type' => 'int', 'primary' => true, 'serial' => true),
'reseller_id' => array('type' => 'int', 'index' => true, 'default' => 0),
'shortname' => array('type' => 'string', 'required' => true, 'unique' => true),
'title' => array('type' => 'string', 'required' => true),
'theme' => array('type' => 'string'),
'status' => array('type' => 'int', 'length' => 1, 'default' => self::STATUS_ACTIVE),
'date_created' => array('type' => 'datetime'),
'date_modified' => array('type' => 'datetime')
);
}
/**
* Relations
*/
public static function relations() {
return array(
// Modules in regions on page
'modules' => array(
'type' => 'HasMany',
'entity' => 'Module\Page\Module\Entity',
'where' => array('site_id' => ':entity.site_id', 'page_id' => ':entity.id'),
'order' => array('ordering' => 'ASC')
)
) + parent::relations();
}
/**
* Formats shortname on save
* All lowercase, alphanumeric characters only
*/
public function beforeSave(Spot\Mapper $mapper)
{
$this->__set('shortname', strtolower(preg_replace("/[^a-zA-Z0-9]/g", "", $this->__get('shortname'))));
return parent::beforeSave($mapper);
}
/**
* Get array of themes available to site for use
*/
public function themes()
{
return array_map('trim', explode(',', $this->theme));
}
}