[go: up one dir, main page]

Menu

[r2]: / models / course.php  Maximize  Restore  History

Download this file

95 lines (66 with data), 2.1 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
<?php
/**
* @package Main
*/
/**
* @package CoCoMa
*/
class Course extends AppModel {
var $name = 'Course';
var $primaryKey = 'id';
//The Associations below have been created with all possible keys, those that are not needed can be removed
var $hasMany = array(
'Topic' =>
array('className' => 'Topic',
'foreignKey' => 'course_id',
'conditions' => array('Topic.deleted' => 0)
)
);
var $belongsTo = array(
'User' =>
array('className' => 'User',
'foreignKey' => 'created_by',
)
);
function beforeFind($queryData){
$queryData['conditions'][$this->name.'.deleted'] = "0";
return $queryData;
}
function afterFind($results){
// echo "<pre>"; var_dump($results); var_dump($this->Session); echo "</pre>";
return $results;
}
function getAllowed($user_id, $Acl, $action=":index"){
if(empty($user_id))
return null;
$controller = Inflector::pluralize($this->name);
$assocClassName = "AssocGroup".$this->name;
$assoc_obj = new $assocClassName();
if(empty($assoc_obj))
return NULL;
$assoc = $assoc_obj->findAll(array('user_id' => $user_id));
$model_group = array();
foreach($assoc as $val){
$model_group[$val["AssocGroup".$this->name][low($this->name)."_id"]] = $val["AssocGroup".$this->name]["group_id"];
}
$not_allowed = array();
foreach(array_unique($model_group) as $group){
$alias = $Acl->Aro->find(array("foreign_key" => $group), "alias", null, -1);
if(!$Acl->check($alias['Aro']['alias'], $controller."/".$action, "*"))
$not_allowed[] = $group;
}
return(array_diff($model_group, $not_allowed));
}
function delete($id){
if(empty($id))
return false;
$this->query("UPDATE ".$this->tablePrefix.$this->table." SET deleted = 1 WHERE id = {$id};");
/**
* @todo cascading "delete"
*/
if(!$this->getAffectedRows())
return false;
return true;
}
}
?>