/
template.php
63 lines (56 loc) · 1.33 KB
/
template.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
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* Template database model
*
* @package KMS
* @category Modules
* @author Alan Roemen <aroemen@cognitived.com>
* @copyright (c) 2011 Cognitived
* @license http://cognitived.com/kms/license
*/
class Model_Template extends ORM {
/**
* @var string database configuration key
*/
protected $_db = KMS_DATABASE;
/**
* @var array ORM has_many relationships
*/
protected $_has_many = array(
'sites' => array('model' => 'site', 'through' => 'site_templates'),
);
/**
* @var array validation rules
*/
protected $_rules = array(
'name' => array(
'not_empty' => NULL,
'max_length' => array(80),
),
'body' => array(
'not_empty' => NULL,
),
);
/**
* @var string holds the enabled value
*/
private $_enabled = NULL;
/**
* Overrides ORM get magic method to allow for enabled
* @param string name of column/relationship to return
* @return mixed
*/
public function __get( $column ) {
if ( $column != 'enabled' ) {
return parent::__get($column);
} else {
if ($this->_enabled === NULL) {
$this->_enabled = ORM::factory('site_template')
->where('site_id', '=', KMS::instance('site')->id)
->where('template_id', '=', $this->id)
->find()->enabled;
}
return $this->_enabled;
}
}
}