CMS  Version 3.9
versioned_content_manager.inc
Go to the documentation of this file.
1 <?php
14 {
16  {
17 
18  }
19 
20  static $versionedContentClasses = array();
21 
22  static function onInitialize()
23  {
24  ComponentManager::fireEvent("RegisterVersionedContent");
25  }
26 
27  static function setDefaults()
28  {
29  Settings::setDefaultValue("settings", "enable_content_versioning", false, Boolean, "Enables content versioning for supported content items", "Content Versioning");
30  }
31 
32  static function enableVersioning($form)
33  {
34  if (!Settings::getValue("settings", "enable_content_versioning")) return;
35 
36  $target = &$form->data;
37 
39  $form->onDrawStart = array(VersionedContentManager, "onDrawForm");
40  $form->onSavePreProcess = array(VersionedContentManager, 'onSavePreProcess');
41 
42  }
43 
44  static function registerVersionedContent()
45  {
46  for($i = 0; $i < func_num_args(); ++$i)
47  {
49  }
50  }
51 
52  static function onSavePreProcess($form)
53  {
54  $target = $form->data;
57  return true;
58  }
59 
60  static function onDrawForm($form)
61  {
62  $target = $form->data;
63  $versionControls = VersionedContentManager::renderVersioningControls($form->data, true);
64  if ($versionControls)
65  {
66  echo "<p class='version_info'>$versionControls</p>";
67  }
68  }
69 
70  static function onDrawInlineControls($item)
71  {
73  }
74 
79  static function revert($target)
80  {
81  $class = get_class($target);
82  $reversion = new $class;
83  $id = $target->getPrimaryKeyValue();
84  if (!$id) return;
85 
86  $reversion->load($id);
87 
88  foreach($reversion->versioned_fields as $field)
89  {
90  $target->set($field, $reversion->get($field));
91  }
92  }
93 
94  static function approve($target)
95  {
96  $contentVersion = ContentVersion::getVersion($target, "draft");
97  if (!$contentVersion) throw new FakoliException("No draft found for item");
98  $contentVersion->approve($target);
99  }
100 
101  static function selectDisplayVersion($target, $param = "version")
102  {
103  if (!isset($_GET[$param])) return $target;
104  $version = $_GET[$param];
105 
106  if ($version == 'draft')
107  {
109  return;
110  }
111 
112  checkNumeric($version);
113 
115  }
116 
117 
118  static function renderVersioningControls($item, $formMode = false)
119  {
120  if (!Settings::getValue("settings", "enable_content_versioning")) return;
121 
122  if ($formMode)
123  {
124  $version = "draft";
125  }
126  else
127  {
128  $param = "version";
129 
130  $version = $_GET[$param];
131  if (!$version) $version = "";
132 
133  $params = array();
134 
135  $qs = getCleanQueryString();
136  parse_str($qs, $params);
137 
138  unset($params[$param]);
139  }
140 
141  $liveQs = http_build_query($params);
142  $params[$param] = "draft";
143  $draftQs = http_build_query($params);
144  $hasDraft = ContentVersion::hasDraft($item);
145 
146  if (!$hasDraft && $formMode)
147  {
148  $version = "";
149  }
150 
151  $out = "";
152 
153  if ($hasDraft && !$formMode)
154  {
155  $draftSelected = ($version == "draft") ? " selected" : "";
156  $liveSelected = ($version == "") ? " selected" : "";
157 
158  $out .= " <a class='pushbutton first{$liveSelected}' href='?{$liveQs}'>Live</a><a class='pushbutton last{$draftSelected}' href='?{$draftQs}'> Draft</a>";
159  }
160 
161  $selectedVersion = ContentVersion::getVersion($item, $version);
162  if ($selectedVersion)
163  {
164  $mgr = new UserManager();
165  $owner = $mgr->getUserFullName($selectedVersion->LastModifiedBy());
166 
167  $out .= $selectedVersion->format("<span class='version'>Version {version_number} Last Edited By {$owner} on {last_modified}</span>");
168  }
169 
170  if ($version == "draft" && $hasDraft)
171  {
172  $class = get_class($item);
173  $pkval = $item->getPrimaryKeyValue();
174  $out .= "<a class='approve' href='#' onclick='VersionedContentManager.approve(\"{$class}\", {$pkval}); return false'>Approve</a>";
175  $out .= "&nbsp;<a class='revert' href='#' onclick='VersionedContentManager.revert(\"{$class}\", {$pkval}); return false'>Discard Changes</a>";
176  }
177  return $out;
178  }
179 
180  static function upgradeComponent($version)
181  {
183  $mgr->upgrade($version);
184  }
185 }
186 ?>
$form
$out
Definition: page.inc:66
static fireEvent($event, $parameter=null, $mustBeConsumed=false)
Fire an event to all subscribers as detailed in their manifests.
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 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.
Definition: core.inc:53
static getValue($component, $name)
Retrieve the value of the specified Setting.
Definition: settings.inc:104
static setDefaultValue($component, $name, $value, $field_type="String", $annotation="", $category="", $options="", $weight=0)
Sets the default value of the given component setting.
Definition: settings.inc:174
Provides the interface to the user model for the application.
Provides a central management class for event handlers and common functionality for the versioned_con...
static selectDisplayVersion($target, $param="version")
static revert($target)
Revert the versioned fields on specified target to the current live values.
static renderVersioningControls($item, $formMode=false)