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