<?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;
}
}
?>