13 var
$fields = array(
"content_version_id" => Number,
14 "content_class" => String,
15 "content_id" => Number,
16 "version_number" => Number,
18 "last_modified" => DateTime,
19 "last_modified_by" => Number,
20 "approved" => Boolean,
21 "approved_date" => DateTime,
22 "approved_by" => Number);
32 $tx =
new DataTransaction();
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())
41 catch (DataNotFoundException $e)
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;
51 $contentVersion->last_modified_by =
$user->getPrimaryKeyValue();
52 $contentVersion->last_modified = now();
54 $contentVersion->populateFrom(
$target);
56 $contentVersion->joinTransaction(
$tx);
57 $contentVersion->save();
75 trace(print_r(
$target,
true), 3);
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())
81 $contentVersion->populateTo(
$target);
83 catch(DataNotFoundException $e)
85 trace(
"Draft not found", 3);
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())
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())
116 catch(DataNotFoundException $e)
118 trace(
"Draft not found", 3);
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());
134 if (!$includeContent)
136 $query->filter(
new ExclusionFilter(
"content"));
139 return $query->execute();
144 if ($version ==
"draft")
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())
153 catch(DataNotFoundException $e)
155 $contentVersion =
null;
158 else if ($version ==
"")
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())
166 catch(DataNotFoundException $e)
168 $contentVersion =
null;
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)
179 catch(DataNotFoundException $e)
181 $contentVersion =
null;
185 return $contentVersion;
192 $tx =
new DataTransaction();
195 $this->joinTransaction(
$tx);
200 $this->approved_by =
$user->getPrimaryKeyValue();
201 $this->approved_date = now();
220 checkNumeric($version);
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)
227 $contentVersion->populateTo(
$target);
229 catch(DataNotFoundException $e)
236 private function populateFrom(
$target)
238 $representation = array();
244 $this->content = json_encode($representation);
247 private function populateTo(
$target)
249 $representation = json_decode($this->content,
true);
256 private static function nextVersion(
$target,
$tx)
258 $version = Query::create(
ContentVersion,
"WHERE content_class=:c AND content_id=:i")
259 ->bind(
":c", get_class(
$target),
":i",
$target->getPrimaryKeyValue())
260 ->executeValue(
"MAX(version_number)");
262 return intval($version) + 1;
268 return $mgr->getUser($this->last_modified_by);
274 return $mgr->getUser($this->approved_by);
static approvedVersions($target, $includeContent=false)
Returns an array of previously approved versions of this content item.
static saveDraft($target)
Saves a draft version of the target object to the content version table.
static loadVersion($target, $version)
Update the versioned fields on the target object to the specified version.
static deleteDraft($target)
Delete the current draft changes for the specified target (if they exist)
static getVersion($target, $version)
static hasDraft($target)
Determine whether the specified target content item has a draft version outstanding.
static loadDraft($target)
Update the versioned fields on target object to the current draft version.
FakoliException is the base exception class for all Fakoli errors.
Provides the interface to the user model for the application.