[go: up one dir, main page]

Menu

[r4]: / models / content_cache.php  Maximize  Restore  History

Download this file

114 lines (82 with data), 2.6 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
107
108
109
110
111
112
113
114
<?php
/**
* @package Main
*/
/**
* @package CoCoMa
*/
class Content_cache extends AppModel {
var $name = 'Content_cache';
var $useTable = 'content_caches';
var $table = 'content_caches';
var $primaryKey = 'id';
var $order = array (
"Content_cache.position" => "ASC",
"Content_cache.id" => "ASC"
);
var $validate = array (
'topic_id' => VALID_NUMBER,
'created_by' => VALID_NUMBER,
'position' => VALID_NUMBER,
);
//The Associations below have been created with all possible keys, those that are not needed can be removed
var $belongsTo = array (
'Topic' => array (
'className' => 'Topic',
'foreignKey' => 'topic_id',
),
);
var $hasMany = array (
'ContentRevisions' => array (
'className' => 'Content',
'foreignKey' => 'parent_id',
'conditions' => array (
'ContentRevisions.deleted' => 0
),
'order' => 'ContentRevisions.id ASC',
),
);
function beforeFind($queryData) {
$queryData['conditions'][$this->name . '.deleted'] = "0";
return $queryData;
}
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;
return true;
}
function unDelete($id) {
if (empty ($id))
return false;
$this->query("UPDATE " . $this->tablePrefix . $this->table . " SET deleted = 0 WHERE id = {$id};");
if (!$this->getAffectedRows())
return false;
return true;
}
function approveRevision($id) {
if (empty ($id))
return false;
$revision = $this->read(null, $id);
if (empty ($revision['Content']['parent_id']))
return false;
$query = "SELECT id FROM " . $this->tablePrefix . $this->table . " WHERE parent_id = " . $revision['Content']['parent_id'] . " AND id <> " . $revision['Content']['id'];
$result = $this->query($query);
$tmp = array ();
if (!empty ($result))
foreach ($result as $value)
$tmp[] = $value[$this->tablePrefix .
$this->table]['id'];
$tmp[] = $revision['Content']['parent_id'];
$revisionIds = join(",", $tmp);
$this->query("UPDATE " . $this->tablePrefix . $this->table . " SET parent_id = " . $revision['Content']['id'] .
" WHERE id IN ({$revisionIds})");
$this->query("UPDATE " . $this->tablePrefix . $this->table . " SET parent_id = NULL WHERE id = " . $revision['Content']['id']);
if (!$this->getAffectedRows())
return false;
return true;
}
}
?>