Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
asset_status_live_approval.inc
1 <?php
17 require_once SQ_INCLUDE_PATH.'/asset_status/asset_status.inc';
18 
39 {
40 
41 
47  function Asset_Status_Live_Approval($owner)
48  {
49  $this->Asset_Status($owner);
50  $this->status_tag = SQ_STATUS_LIVE_APPROVAL;
51 
52  }//end constructor
53 
54 
62  public static function getDescription()
63  {
64  return translate('status_live_approval');
65 
66  }//end getDescription()
67 
68 
76  function getAvailableStatii()
77  {
78  $statii = Array();
79 
80  // cant do anything without write access
81  if (!$this->owner->readAccess()) return $statii;
82 
83  if ($this->owner->adminAccess('')) {
84  $statii[SQ_STATUS_EDITING] = translate('status_change_safe_edit');
85  }
86 
87  $wfm = $GLOBALS['SQ_SYSTEM']->getWorkflowManager();
88  $running_schemas = $wfm->getSchemas($this->owner->id, true, true);
89 
90  if (!empty($running_schemas)) {
91  $userid = $GLOBALS['SQ_SYSTEM']->currentUserId();
92 
93  // check to see if the user logged in can publish
94  $publishers = $wfm->whoCanPublish($this->owner->id);
95 
96  // if nobody can publish we better let admins do it
97  $admin_access = $this->owner->adminAccess('');
98 
99  if (in_array($userid, $publishers) || $admin_access) {
100  // the current user can approve this asset to keep the workflow going
101  $wf_complete = $wfm->testPublish($this->owner->id, $GLOBALS['SQ_SYSTEM']->currentUserId());
102 
103  // we also need to check what if all the required metadata fields are completed
104  $mm = $GLOBALS['SQ_SYSTEM']->getMetadataManager();
105  $is_dependant = $GLOBALS['SQ_SYSTEM']->am->isDependant($this->owner->id);
106 
107  if ($mm->allowsMetadata($this->owner->id)) {
108  $m_complete = $mm->requiredFieldsComplete($this->owner->id);
109  if ($wf_complete && ((!$is_dependant && $m_complete) || $is_dependant)) {
110  $statii[SQ_STATUS_LIVE] = translate('status_change_approve_and_make_live');
111  } else if (in_array($userid, $publishers)) {
112  $statii[SQ_STATUS_LIVE_APPROVAL] = translate('status_change_approve_review');
113  }
114  } else {
115  // this asset needs to allow both statuses because it cant check metadata requirements
116  // due to it not allowing metadata
117  $statii[SQ_STATUS_LIVE] = translate('status_change_approve_and_make_live');
118  $statii[SQ_STATUS_LIVE_APPROVAL] = translate('status_change_approve_review');
119  }
120 
121  $statii[SQ_STATUS_EDITING] = translate('status_change_safe_edit');
122  }
123  } else {
124  // no running workflow means that anyone with admin access can
125  // make this live (up for review is just a flag in this case)
126  $statii[SQ_STATUS_LIVE] = translate('status_change_approve_and_make_live');
127  if ($this->owner->adminAccess('')) {
128  $statii[SQ_STATUS_ARCHIVED] = translate('status_change_archive');
129  }
130 
131  }//end if workflow running
132 
133  return $statii;
134 
135  }//end getAvailableStatii()
136 
137 
148  function processStatusChange($new_status, $update_parent=true)
149  {
150  if (!parent::processStatusChange($new_status, $update_parent)) {
151  return false;
152  }
153 
154  $wfm = $GLOBALS['SQ_SYSTEM']->getWorkflowManager();
155  $current_userid = $GLOBALS['SQ_SYSTEM']->currentUserId();
156 
157  if ($new_status == SQ_STATUS_EDITING) {
158 
159  $running_schemas = $wfm->getSchemas($this->owner->id, true, true);
160  if (!empty($running_schemas)) {
161  // someone has rejected the approval, so we need to cancel the workflow
162  $user = $GLOBALS['SQ_SYSTEM']->am->getAsset($GLOBALS['SQ_SYSTEM']->currentUserId());
163 
164  $ms = $GLOBALS['SQ_SYSTEM']->getMessagingService();
165  $msg = $ms->newMessage();
166  $msg_reps = Array(
167  'workflow_user' => $user->name,
168  'type_code' => $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($this->owner->type(), 'name'),
169  'asset_name' => $this->owner->name,
170  'assetid' => $this->owner->id,
171  'status' => get_status_description($new_status),
172  'workflow_url' => current_url().$this->owner->getBackendHref('workflow', FALSE),
173  );
174  $msg->replacements = $msg_reps;
175  $msg->type = 'asset.workflow.review.cancel';
176  $asset_edt_fns = $this->owner->getEditFns();
177  if (isset($asset_edt_fns->static_screens['preview'])) {
178  $msg->replacements['preview_url'] = current_url().$this->owner->getBackendHref('preview', FALSE);
179  } else {
180  $msg->replacements['preview_url'] = current_url().$this->owner->getBackendHref('details', FALSE);
181  }
182 
183  if (!$wfm->cancelWorkflow($this->owner->id, $msg)) {
184  trigger_localised_error('SYS0260', E_USER_WARNING);
185  return false;
186  }
187  }
188 
189  // we are safe editing
190  if (!$this->owner->saveSystemVersion()) {
191  trigger_localised_error('SYS0208', E_USER_WARNING);
192  return false;
193  }
194 
195  require_once SQ_INCLUDE_PATH.'/general_occasional.inc';
196 
197  // send an internal message
198  $ms = $GLOBALS['SQ_SYSTEM']->getMessagingService();
199  $user = $GLOBALS['SQ_SYSTEM']->am->getAsset($current_userid);
200 
201  if (!$wfm->silentWorkflowParty($this->owner->id)) {
202  $log = $ms->newMessage();
203  $msg_reps = Array(
204  'workflow_user' => $user->name,
205  'type_code' => $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($this->owner->type(), 'name'),
206  'asset_name' => $this->owner->name,
207  'status' => get_status_description($new_status),
208  'workflow_url' => current_url().$this->owner->getBackendHref('workflow', FALSE),
209  );
210  $log->replacements = $msg_reps;
211  $asset_edt_fns = $this->owner->getEditFns();
212  if (isset($asset_edt_fns->static_screens['preview'])) {
213  $log->replacements['preview_url'] = current_url().$this->owner->getBackendHref('preview', FALSE);
214  } else {
215  $log->replacements['preview_url'] = current_url().$this->owner->getBackendHref('details', FALSE);
216  }
217 
218  $log->type = 'asset.workflow.log.review.cancel';
219  $log->parameters['assetid'] = $this->owner->id;
220  $log->parameters['version'] = substr($this->owner->version, 0, strrpos($this->owner->version, '.'));
221  $log->send();
222  }
223 
224  } else {
225 
226  $running_schemas = $wfm->getSchemas($this->owner->id, true, true);
227  if (!empty($running_schemas)) {
228 
229  // if we are trying to approve this asset, we might not actually be a person
230  // in the workflow process - sounds weird (I know) but this could be a plain old
231  // admin that is trying to approve because metadata is now complete.
232  // the result is that this workflow process may already be complete
233  $mm = $GLOBALS['SQ_SYSTEM']->getMetadataManager();
234  $m_complete = !$mm->allowsMetadata($this->owner->id) || $mm->requiredFieldsComplete($this->owner->id) || $GLOBALS['SQ_SYSTEM']->am->isDependant($this->owner->id);
235 
236  if ($wfm->isWorkflowComplete($this->owner->id) && $m_complete && ($new_status & SQ_STATUS_LIVE)) {
237  if (!$wfm->completeWorkflow($this->owner->id)) {
238  trigger_localised_error('SYS0261', E_USER_WARNING);
239  return false;
240  }
241  } else {
242  // we are doing a workflow and someone has just approved the asset, so record this
243  if (!$wfm->recordPublish($this->owner->id, $current_userid)) {
244  trigger_localised_error('SYS0077', E_USER_WARNING, $current_userid, $this->owner->name);
245  return false;
246  }
247 
248  // if the workflow process is now complete, we can go ahead and clear out the schemas
249  // as long as all our metadata is also complete
250  if ($wfm->isWorkflowComplete($this->owner->id) && $m_complete && ($new_status & SQ_STATUS_LIVE)) {
251  if (!$wfm->completeWorkflow($this->owner->id)) {
252  trigger_localised_error('SYS0261', E_USER_WARNING);
253  return false;
254  }
255  }
256  }
257 
258  if ($new_status == SQ_STATUS_LIVE) {
259  // notify people that the asset has gone live
260  $wfm = $GLOBALS['SQ_SYSTEM']->getWorkflowManager();
261  if (!$wfm->notifyOnLive($this->owner->id, $this->status_tag)) {
262  return false;
263  }
264 
265  // update the last published date
266  if (!$this->owner->setDate('published', time())) {
267  return false;
268  }
269 
270  // log an internal message
271  $ms = $GLOBALS['SQ_SYSTEM']->getMessagingService();
272  $user = $GLOBALS['SQ_SYSTEM']->am->getAsset($current_userid);
273 
274  if (!$wfm->silentWorkflowParty($this->owner->id)) {
275  $log = $ms->newMessage();
276  $msg_reps = Array(
277  'user_name' => $user->name,
278  'workflow_user' => $user->name,
279  'type_code' => $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($this->owner->type(), 'name'),
280  'asset_name' => $this->owner->name,
281  'status' => get_status_description($new_status),
282  'workflow_url' => current_url().$this->owner->getBackendHref('workflow', FALSE),
283  );
284  $log->replacements = $msg_reps;
285  //$log->to = Array(0);
286  $log->type = 'asset.workflow.log.review.complete';
287  $asset_edt_fns = $this->owner->getEditFns();
288  if (isset($asset_edt_fns->static_screens['preview'])) {
289  $log->replacements['preview_url'] = current_url().$this->owner->getBackendHref('preview', FALSE);
290  } else {
291  $log->replacements['preview_url'] = current_url().$this->owner->getBackendHref('details', FALSE);
292  }
293 
294  $log->parameters['assetid'] = $this->owner->id;
295  $log->parameters['version'] = substr($this->owner->version, 0, strrpos($this->owner->version, '.'));
296  $ms->enqueueMessage($log);
297  }
298  }
299 
300  }//end if
301 
302  }//end else
303 
304  return true;
305 
306  }//end processStatusChange()
307 
308 
309 }//end class
310 
311 ?>