-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp_model.php
54 lines (44 loc) · 1.23 KB
/
app_model.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
<?php
class appModel extends model
{
var $actsAs = array('Containable', 'CmscoutCore');
var $recursive = -1;
function __construct($id = false, $table = null, $ds = null)
{
if(isset($this->plugin))
{
$this->tablePrefix = Inflector::underscore($this->plugin) . '_';
}
if($this->tablePrefix != '')
{
$config = $this->getDataSource()->config;
if(isset($config['prefix']))
$this->tablePrefix = $config['prefix'] . $this->tablePrefix;
}
parent::__construct($id, $table, $ds);
}
function toggleField($field, $id=null)
{
if(empty($id))
{
$id = $this->id;
}
$field = $this->escapeField($field);
return $this->updateAll(array($field => '1 -' . $field),
array($this->escapeField() => $id)
);
}
function doesIdExist($id)
{
return !$this->isUnique(array($this->alias . '.id' => $id));
}
function findById($id, $contain = false)
{
return $this->find('first', array('conditions' => array($this->alias . '.id' => $id), 'contain' => $contain));
}
function findBySlug($slug, $contain = false)
{
return $this->find('first', array('conditions' => array($this->alias . '.slug' => $slug), 'contain' => $contain));
}
}
?>