<?php
/**
* @package Main
*/
/**
* @package CoCoMa
*/
class Topic extends AppModel {
var $name = 'Topic';
var $primaryKey = 'id';
var $validate = array(
'created_by' => VALID_NOT_EMPTY,
'course_id' => VALID_NOT_EMPTY
);
// var $actsAs = array('Acl' => array('Aco'));
//The Associations below have been created with all possible keys, those that are not needed can be removed
var $hasMany = array(
'Content' =>
array('className' => 'Content',
'conditions' => array('Content.parent_id' => NULL, 'Content.deleted' => 0),
'foreignKey' => 'topic_id',
),
);
var $belongsTo = array(
'Course' =>
array('className' => 'Course',
'foreignKey' => 'course_id',
),
'User' =>
array('className' => 'User',
'foreignKey' => 'created_by',
)
);
function delete($id){
if(empty($id))
return false;
$this->query("UPDATE ".$this->tablePrefix.$this->table." SET deleted = 1 WHERE id = {$id};");
if(!$this->getAffectedRows())
return false;
App::import('Model', 'Content');
$content = new Content_cache;
$content->query("UPDATE ".$content->tablePrefix.$content->table." SET deleted = 1 WHERE topic_id = {$id};");
return true;
}
function unDelete($id){
if(empty($id))
return false;
$this->query("UPDATE ".$this->tablePrefix.$this->table." SET deleted = 0 WHERE id = {$id};");
App::import('Model', 'Content');
$content = new Content_cache;
$content->query("UPDATE ".$content->tablePrefix.$content->table." SET deleted = 0 WHERE topic_id = {$id};");
if(!$this->getAffectedRows())
return false;
return true;
}
function beforeFind($queryData){
$queryData['conditions'][$this->name.'.deleted'] = "0";
return $queryData;
}
/*
function parentNode(){
if (!$this->id) {
return null;
}
$data = $this->read();
if (!$data['Topic']['course_id']){
return null;
} else {
return array('model' => 'Topic', 'foreign_key' => $data['Topic']['course_id']);
}
}
*/
}
?>