Repository navigation
Expand file tree
/
Copy pathapp_model.php
More file actions
executable file
·106 lines (96 loc) · 2.96 KB
/
Copy pathapp_model.php
File metadata and controls
executable file
·106 lines (96 loc) · 2.96 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
/* SVN FILE: $Id$ */
/**
* Ósmosis LMS: <http://www.osmosislms.org/>
* Copyright 2008, Ósmosis LMS
*
* This file is part of Ósmosis LMS.
* Ósmosis LMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Ósmosis LMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Ósmosis LMS. If not, see <http://www.gnu.org/licenses/>.
*
* @filesource
* @copyright Copyright 2008, Ósmosis LMS
* @link http://www.osmosislms.org/
* @package org.osmosislms
* @subpackage org.osmosislms.app
* @since Version 2.0
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
*/
class AppModel extends Model{
var $actsAs = array('Containable');
/**
* Validation rule to check if a field is unique.cnl
*
* @param array $data
* @param string $name
* @return void
*/
function validateUnique($data, $name) {
if (!empty($this->id)) {
$conditions = array('NOT' => array($this->primaryKey => $this->id, $name => $data[$name]));
} else {
$conditions = array($name => $data[$name]);
}
return !$this->field($this->primaryKey, $conditions);
}
protected function setErrorMessage($path, $message) {
$this->validate = Set::insert($this->validate, $path . '.message', $message);
}
/**
* Alias for ContainableBehavior::contain
*
* @param mixed $args
* @return void
*/
function restrict($args) {
$this->contain($args);
trigger_error(__('Please use "contain" instead of "restrict"', true), E_USER_WARNING);
}
function beforeFind($queryData) {
if (isset($queryData['restrict'])) {
$queryData['contain'] = $queryData['restrict'];
unset($queryData['restrict']);
trigger_error(__('Please use "contain" instead of "restrict"', true), E_USER_WARNING);
}
}
function isOwner($member,$id) {
if (isset($this->belongsTo) && !empty($this->belongsTo)) {
$foreign = false;
foreach($this->belongsTo as $alias => $assoc) {
if ($alias == 'Member' || $assoc['className'] == 'Member')
$foreign = $alias;
}
if (!$foreign)
return false;
return $this->find('count',array(
'conditions' => array(
$this->alias.'.id' => $id,
$this->alias.'.'.$this->belongsTo[$foreign]['foreignKey'] => $member
)
)) == 1;
}
return false;
}
/**
* Returns the parent course related to this model (assumes $this->id is set)
*
* @return mixed Parent Course id or false if not found
**/
function getParentCourse() {
return false;
}
}
?>