1
|
|
|
<?php defined('SYSPATH') OR die('No direct script access.'); |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @author Ivan Kerin <[email protected]> |
5
|
|
|
* @copyright (c) 2014 Clippings Ltd. |
6
|
|
|
* @license http://spdx.org/licenses/BSD-3-Clause |
7
|
|
|
*/ |
8
|
|
|
class Kohana_Model_Term extends Jam_Model |
9
|
|
|
{ |
10
|
1 |
|
public static function initialize(Jam_Meta $meta) |
11
|
|
|
{ |
12
|
|
|
$meta |
13
|
1 |
|
->table('terms') |
14
|
1 |
|
->name_key('name'); |
15
|
|
|
|
16
|
1 |
|
$meta->behaviors(array( |
17
|
1 |
|
'nested' => Jam::behavior('Nested'), |
18
|
1 |
|
'sluggable' => Jam::behavior('Sluggable', array('uses_primary_key' => FALSE, 'auto_save' => FALSE, 'unique' => TRUE)) |
19
|
|
|
)); |
20
|
|
|
|
21
|
1 |
|
$meta->associations(array( |
22
|
1 |
|
'vocabulary' => Jam::association('belongsto', array('inverse_of' => 'terms')), |
23
|
|
|
)); |
24
|
|
|
|
25
|
1 |
|
$meta->fields(array( |
26
|
1 |
|
'id' => Jam::field('primary'), |
27
|
1 |
|
'name' => Jam::field('string'), |
28
|
|
|
|
29
|
1 |
|
'is_hidden' => Jam::field('boolean', array()), // whether to show / hide the term |
30
|
|
|
|
31
|
|
|
// Analytics |
32
|
1 |
|
'created_at' => Jam::field('timestamp', array('auto_now_create' => TRUE, 'format' => 'Y-m-d H:i:s')), |
33
|
1 |
|
'updated_at' => Jam::field('timestamp', array('auto_now_update' => TRUE, 'format' => 'Y-m-d H:i:s')), |
34
|
|
|
)); |
35
|
|
|
|
36
|
|
|
$meta |
37
|
1 |
|
->validator('name', array('present' => TRUE)); |
38
|
1 |
|
} |
39
|
|
|
|
40
|
|
|
public function only_children(array $terms) |
41
|
|
|
{ |
42
|
|
|
return $this->children->where('slug', 'IN', $terms); |
|
|
|
|
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
public static function unique_key($value) |
47
|
|
|
{ |
48
|
|
|
return (is_numeric($value) OR $value === NULL) ? 'id' : 'slug'; |
49
|
|
|
} |
50
|
|
|
} |
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.