[go: up one dir, main page]

Menu

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

Download this file

155 lines (103 with data), 3.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
/**
* @package Main
*/
/**
* @package CoCoMa
*/
class Content extends AppModel {
var $name = 'Content';
var $useTable = 'content';
var $primaryKey = 'id';
var $order = array("Content.position" => "ASC", "Content.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',
),
/* 'Parent_content' =>
array('className' => 'Content',
'foreignKey' => 'parent_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;
}
function splitIntoSlides($file)
{
$slides = array();
$reader = new XMLReader();
$reader->open(ini_get('upload_tmp_dir')."/".$file);
// while there are more tags
while($reader->read())
{
if(strcasecmp($reader->name, "div") == 0 && strcasecmp($reader->getAttribute("class"), "slide") == 0)
{
$slides[] = $reader->readInnerXML();
$reader->next();
}
}
$reader->close();
return $slides;
}
function maxPosition($topicId)
{
$query = "SELECT MAX(position) FROM ".$this->tablePrefix.$this->table." WHERE topic_id = ".$topicId;
$value = $this->query($query);
return $value[0][0]['MAX(position)'];
}
}
?>