CMS  Version 3.9
VersionedContentManager Class Reference

Provides a central management class for event handlers and common functionality for the versioned_content component. More...

Public Member Functions

 VersionedContentManager ()
 

Static Public Member Functions

static onInitialize ()
 
static setDefaults ()
 
static enableVersioning ($form)
 
static registerVersionedContent ()
 
static onSavePreProcess ($form)
 
static onDrawForm ($form)
 
static onDrawInlineControls ($item)
 
static revert ($target)
 Revert the versioned fields on specified target to the current live values. More...
 
static approve ($target)
 
static selectDisplayVersion ($target, $param="version")
 
static renderVersioningControls ($item, $formMode=false)
 
static upgradeComponent ($version)
 

Static Public Attributes

static $versionedContentClasses = array()
 

Detailed Description

Provides a central management class for event handlers and common functionality for the versioned_content component.

Definition at line 13 of file versioned_content_manager.inc.

Member Function Documentation

◆ approve()

static VersionedContentManager::approve (   $target)
static

Definition at line 94 of file versioned_content_manager.inc.

95  {
96  $contentVersion = ContentVersion::getVersion($target, "draft");
97  if (!$contentVersion) throw new FakoliException("No draft found for item");
98  $contentVersion->approve($target);
99  }
static getVersion($target, $version)
FakoliException is the base exception class for all Fakoli errors.
Definition: core.inc:53

◆ enableVersioning()

static VersionedContentManager::enableVersioning (   $form)
static

Definition at line 32 of file versioned_content_manager.inc.

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  }
$form
static loadDraft($target)
Update the versioned fields on target object to the current draft version.
static getValue($component, $name)
Retrieve the value of the specified Setting.
Definition: settings.inc:104
Provides a central management class for event handlers and common functionality for the versioned_con...

◆ onDrawForm()

static VersionedContentManager::onDrawForm (   $form)
static

Definition at line 60 of file versioned_content_manager.inc.

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  }
static renderVersioningControls($item, $formMode=false)

◆ onDrawInlineControls()

static VersionedContentManager::onDrawInlineControls (   $item)
static

Definition at line 70 of file versioned_content_manager.inc.

71  {
73  }

◆ onInitialize()

static VersionedContentManager::onInitialize ( )
static

Definition at line 22 of file versioned_content_manager.inc.

23  {
24  ComponentManager::fireEvent("RegisterVersionedContent");
25  }
static fireEvent($event, $parameter=null, $mustBeConsumed=false)
Fire an event to all subscribers as detailed in their manifests.

◆ onSavePreProcess()

static VersionedContentManager::onSavePreProcess (   $form)
static

Definition at line 52 of file versioned_content_manager.inc.

53  {
54  $target = $form->data;
57  return true;
58  }
static saveDraft($target)
Saves a draft version of the target object to the content version table.
static revert($target)
Revert the versioned fields on specified target to the current live values.

◆ registerVersionedContent()

static VersionedContentManager::registerVersionedContent ( )
static

Definition at line 44 of file versioned_content_manager.inc.

45  {
46  for($i = 0; $i < func_num_args(); ++$i)
47  {
49  }
50  }

◆ renderVersioningControls()

static VersionedContentManager::renderVersioningControls (   $item,
  $formMode = false 
)
static

Definition at line 118 of file versioned_content_manager.inc.

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  }
$out
Definition: page.inc:66
static hasDraft($target)
Determine whether the specified target content item has a draft version outstanding.
Provides the interface to the user model for the application.

◆ revert()

static VersionedContentManager::revert (   $target)
static

Revert the versioned fields on specified target to the current live values.

Parameters
DataItem$targetthe target content object

Definition at line 79 of file versioned_content_manager.inc.

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  }

◆ selectDisplayVersion()

static VersionedContentManager::selectDisplayVersion (   $target,
  $param = "version" 
)
static

Definition at line 101 of file versioned_content_manager.inc.

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  }
static loadVersion($target, $version)
Update the versioned fields on the target object to the specified version.

◆ setDefaults()

static VersionedContentManager::setDefaults ( )
static

Definition at line 27 of file versioned_content_manager.inc.

28  {
29  Settings::setDefaultValue("settings", "enable_content_versioning", false, Boolean, "Enables content versioning for supported content items", "Content Versioning");
30  }
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

◆ upgradeComponent()

static VersionedContentManager::upgradeComponent (   $version)
static

Definition at line 180 of file versioned_content_manager.inc.

181  {
183  $mgr->upgrade($version);
184  }

◆ VersionedContentManager()

VersionedContentManager::VersionedContentManager ( )

Definition at line 15 of file versioned_content_manager.inc.

16  {
17 
18  }

Member Data Documentation

◆ $versionedContentClasses

VersionedContentManager::$versionedContentClasses = array()
static

Definition at line 20 of file versioned_content_manager.inc.


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