[go: up one dir, main page]

Menu

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

Download this file

101 lines (74 with data), 2.2 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
<?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']);
}
}
*/
}
?>