CMS  Version 3.9
ContentVersion Class Reference

Inherits DataItem.

Public Member Functions

 approve ($target)
 
 LastModifiedBy ()
 
 ApprovedBy ()
 

Static Public Member Functions

static saveDraft ($target)
 Saves a draft version of the target object to the content version table. More...
 
static loadDraft ($target)
 Update the versioned fields on target object to the current draft version. More...
 
static hasDraft ($target)
 Determine whether the specified target content item has a draft version outstanding. More...
 
static deleteDraft ($target)
 Delete the current draft changes for the specified target (if they exist) More...
 
static approvedVersions ($target, $includeContent=false)
 Returns an array of previously approved versions of this content item. More...
 
static getVersion ($target, $version)
 
static loadVersion ($target, $version)
 Update the versioned fields on the target object to the specified version. More...
 

Public Attributes

 $table = "content_version"
 
 $primary_key = "content_version_id"
 
 $fields
 

Detailed Description

Definition at line 8 of file content_version.inc.

Member Function Documentation

◆ approve()

ContentVersion::approve (   $target)

Definition at line 188 of file content_version.inc.

189  {
190  global $user;
191 
192  $tx = new DataTransaction();
193  try
194  {
195  $this->joinTransaction($tx);
196  $target->joinTransaction($tx);
197  $this->populateTo($target);
198  $target->save();
199  $this->approved=1;
200  $this->approved_by = $user->getPrimaryKeyValue();
201  $this->approved_date = now();
202  $this->save();
203  $tx->commit();
204  }
205  catch (Exception $e)
206  {
207  $tx->rollback();
208  throw $e;
209  }
210  }
global $user

◆ ApprovedBy()

ContentVersion::ApprovedBy ( )

Definition at line 271 of file content_version.inc.

272  {
273  $mgr = new UserManager();
274  return $mgr->getUser($this->approved_by);
275  }
Provides the interface to the user model for the application.

◆ approvedVersions()

static ContentVersion::approvedVersions (   $target,
  $includeContent = false 
)
static

Returns an array of previously approved versions of this content item.

Parameters
DataItem$targetthe target content item
boolean$includeContenttrue to return the content from previous versions, false to exclude content

Definition at line 129 of file content_version.inc.

130  {
131  $query = Query::create(ContentVersion, "WHERE content_class=:c AND content_id=:i AND approved=1 ORDER BY version_number DESC")
132  ->bind(":c", get_class($target), ":i", $target->getPrimaryKeyValue());
133 
134  if (!$includeContent)
135  {
136  $query->filter(new ExclusionFilter("content"));
137  }
138 
139  return $query->execute();
140  }

◆ deleteDraft()

static ContentVersion::deleteDraft (   $target)
static

Delete the current draft changes for the specified target (if they exist)

Parameters
DataItem$target

Definition at line 107 of file content_version.inc.

108  {
109  try
110  {
111  $doomed = Query::create(ContentVersion, "WHERE content_class=:c AND content_id=:i AND approved=0")
112  ->bind(":c", get_class($target), ":i", $target->getPrimaryKeyValue())
113  ->executeSingle();
114  $doomed->delete();
115  }
116  catch(DataNotFoundException $e)
117  {
118  trace("Draft not found", 3);
119  // Nothing to do
120  }
121 
122  }

◆ getVersion()

static ContentVersion::getVersion (   $target,
  $version 
)
static

Definition at line 142 of file content_version.inc.

143  {
144  if ($version == "draft")
145  {
146  // Get current draft
147  try
148  {
149  $contentVersion = Query::create(ContentVersion, "WHERE content_class=:c AND content_id=:i AND approved=0")
150  ->bind(":c", get_class($target), ":i", $target->getPrimaryKeyValue())
151  ->executeSingle();
152  }
153  catch(DataNotFoundException $e)
154  {
155  $contentVersion = null;
156  }
157  }
158  else if ($version == "")
159  {
160  try
161  {
162  $contentVersion = Query::create(ContentVersion, "WHERE content_class=:c AND content_id=:i AND approved=1 ORDER BY version_number DESC LIMIT 1")
163  ->bind(":c", get_class($target), ":i", $target->getPrimaryKeyValue())
164  ->executeSingle();
165  }
166  catch(DataNotFoundException $e)
167  {
168  $contentVersion = null;
169  }
170  }
171  else
172  {
173  try
174  {
175  $contentVersion = Query::create(ContentVersion, "WHERE content_class=:c AND content_id=:i AND version_number=:v AND approved=1")
176  ->bind(":c", get_class($target), ":i", $target->getPrimaryKeyValue(), ":v", $version)
177  ->executeSingle();
178  }
179  catch(DataNotFoundException $e)
180  {
181  $contentVersion = null;
182  }
183  }
184 
185  return $contentVersion;
186  }

◆ hasDraft()

static ContentVersion::hasDraft (   $target)
static

Determine whether the specified target content item has a draft version outstanding.

Parameters
DataItem$targetthe target content item
Returns
true if a draft version has been created, false otherwise

Definition at line 96 of file content_version.inc.

97  {
98  return Query::create(ContentVersion, "WHERE content_class=:c AND content_id=:i AND approved=0")
99  ->bind(":c", get_class($target), ":i", $target->getPrimaryKeyValue())
100  ->exists();
101  }

◆ LastModifiedBy()

ContentVersion::LastModifiedBy ( )

Definition at line 265 of file content_version.inc.

266  {
267  $mgr = new UserManager();
268  return $mgr->getUser($this->last_modified_by);
269  }

◆ loadDraft()

static ContentVersion::loadDraft (   $target)
static

Update the versioned fields on target object to the current draft version.

Parameters
DataItem$targetthe target content object

Definition at line 71 of file content_version.inc.

72  {
73  try
74  {
75  trace(print_r($target, true), 3);
76 
77  $contentVersion = Query::create(ContentVersion, "WHERE content_class=:c AND content_id=:i AND approved=0")
78  ->bind(":c", get_class($target), ":i", $target->getPrimaryKeyValue())
79  ->executeSingle();
80 
81  $contentVersion->populateTo($target);
82  }
83  catch(DataNotFoundException $e)
84  {
85  trace("Draft not found", 3);
86  // Nothing to do
87  }
88 
89  }

◆ loadVersion()

static ContentVersion::loadVersion (   $target,
  $version 
)
static

Update the versioned fields on the target object to the specified version.

Parameters
DataItem$targetthe target content object
int$versionthe target version number
Exceptions
FakoliException

Definition at line 218 of file content_version.inc.

219  {
220  checkNumeric($version);
221  try
222  {
223  $contentVersion = Query::create(ContentVersion, "WHERE content_class=:c AND content_id=:i AND version_number=:v")
224  ->bind(":c", get_class($target), ":i", $target->getPrimaryKeyValue(), ":v", $version)
225  ->executeSingle();
226 
227  $contentVersion->populateTo($target);
228  }
229  catch(DataNotFoundException $e)
230  {
231  throw new FakoliException("Version $version not found");
232  }
233 
234  }
FakoliException is the base exception class for all Fakoli errors.
Definition: core.inc:53

◆ saveDraft()

static ContentVersion::saveDraft (   $target)
static

Saves a draft version of the target object to the content version table.

Parameters
DataItem$targetthe target to save

Definition at line 28 of file content_version.inc.

29  {
30  global $user;
31 
32  $tx = new DataTransaction();
33  try
34  {
35  try
36  {
37  $contentVersion = Query::create(ContentVersion, "WHERE content_class=:c AND content_id=:i AND approved=0")
38  ->bind(":c", get_class($target), ":i", $target->getPrimaryKeyValue())
39  ->executeSingle();
40  }
41  catch (DataNotFoundException $e)
42  {
43  $contentVersion = new ContentVersion();
44  $contentVersion->content_class = get_class($target);
45  $contentVersion->content_id = $target->getPrimaryKeyValue();
46  $contentVersion->version_number = ContentVersion::nextVersion($target, $tx);
47  $contentVersion->approved = false;
48  $contentVersion->approved_by = 0;
49  }
50 
51  $contentVersion->last_modified_by = $user->getPrimaryKeyValue();
52  $contentVersion->last_modified = now();
53 
54  $contentVersion->populateFrom($target);
55 
56  $contentVersion->joinTransaction($tx);
57  $contentVersion->save();
58 
59  $tx->commit();
60  }
61  catch(Exception $e)
62  {
63  $tx->rollback();
64  }
65  }

Member Data Documentation

◆ $fields

ContentVersion::$fields
Initial value:
= array("content_version_id" => Number,
"content_class" => String,
"content_id" => Number,
"version_number" => Number,
"content" => Text,
"last_modified" => DateTime,
"last_modified_by" => Number,
"approved" => Boolean,
"approved_date" => DateTime,
"approved_by" => Number)

Definition at line 13 of file content_version.inc.

◆ $primary_key

ContentVersion::$primary_key = "content_version_id"

Definition at line 11 of file content_version.inc.

◆ $table

ContentVersion::$table = "content_version"

Definition at line 10 of file content_version.inc.


The documentation for this class was generated from the following file: