Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
asset_status_pending_approval.inc
1 <?php
17 require_once SQ_INCLUDE_PATH.'/asset_status/asset_status.inc';
18 
39 {
40 
41 
48  {
49  $this->Asset_Status($owner);
50  $this->status_tag = SQ_STATUS_PENDING_APPROVAL;
51 
52  }//end constructor
53 
54 
62  public static function getDescription()
63  {
64  return translate('status_pending_approval');
65 
66  }//end getDescription()
67 
68 
76  function getAvailableStatii()
77  {
78 
79  $statii = Array();
80 
81  // cant do anything without write access
82  if (!$this->owner->readAccess()) return $statii;
83 
84  $wfm = $GLOBALS['SQ_SYSTEM']->getWorkflowManager();
85  $running_schemas = $wfm->getSchemas($this->owner->id, TRUE, TRUE);
86 
87  if (!empty($running_schemas)) {
88  $userid = $GLOBALS['SQ_SYSTEM']->currentUserId();
89 
90  // check to see if the user logged in can publish
91  $publishers = $wfm->whoCanPublish($this->owner->id);
92 
93  // if nobody can publish we better let admins do it
94  $admin_access = $this->owner->adminAccess('');
95 
96  if (in_array($userid, $publishers) || $admin_access) {
97  // the current user can approve this asset to keep the workflow going
98  $wf_complete = $wfm->testPublish($this->owner->id, $GLOBALS['SQ_SYSTEM']->currentUserId());
99 
100  // we also need to check what if all the required metadata fields are completed
101  $mm = $GLOBALS['SQ_SYSTEM']->getMetadataManager();
102  if ($mm->allowsMetadata($this->owner->id)) {
103  $m_complete = $mm->requiredFieldsComplete($this->owner->id);
104  $is_dependant = $GLOBALS['SQ_SYSTEM']->am->isDependant($this->owner->id);
105 
106  if ($wf_complete && (($m_complete && !$is_dependant) || $is_dependant)) {
107  $statii[SQ_STATUS_APPROVED] = translate('status_change_approve');
108  } else if (in_array($userid, $publishers)) {
109  $statii[SQ_STATUS_PENDING_APPROVAL] = translate('status_change_approve_changes');
110  }
111  } else {
112  // this asset needs to allow both statuses because it cant check metadata requirements
113  // due to it not allowing metadata, but only if workflow is complete
114  if ($wf_complete) {
115  $statii[SQ_STATUS_APPROVED] = translate('status_change_approve');
116  $statii[SQ_STATUS_PENDING_APPROVAL] = translate('status_change_approve_changes');
117  }
118  }
119 
120  $statii[SQ_STATUS_UNDER_CONSTRUCTION] = translate('status_change_reject_changes');
121  }
122  } else {
123  // workflow is not currently running for this asset
124  // but it should be because we are waiting for it to complete
125  pre_echo('FIXME: SOMETHING HAS GONE WRONG HERE');
126  }//end if workflow running
127 
128  return $statii;
129 
130  }//end getAvailableStatii()
131 
132 
143  function processStatusChange($new_status, $update_parent=TRUE)
144  {
145  if (!parent::processStatusChange($new_status, $update_parent)) {
146  return FALSE;
147  }
148 
149  $wfm = $GLOBALS['SQ_SYSTEM']->getWorkflowManager();
150  $current_userid = $GLOBALS['SQ_SYSTEM']->currentUserId();
151 
152  if ($new_status & SQ_SC_STATUS_CAN_APPROVE) {
153  // someone has rejected the changes, so we need to cancel the workflow
154  if (!$wfm->cancelWorkflow($this->owner->id)) {
155  trigger_localised_error('SYS0260', E_USER_WARNING);
156  return FALSE;
157  } else {
158  require_once SQ_INCLUDE_PATH.'/general_occasional.inc';
159 
160  // log an internal message
161  $ms = $GLOBALS['SQ_SYSTEM']->getMessagingService();
162  $user = $GLOBALS['SQ_SYSTEM']->am->getAsset($current_userid);
163  if (!$wfm->silentWorkflowParty($this->owner->id)) {
164  $log = $ms->newMessage();
165  $msg_reps = Array(
166  'user_name' => $user->name,
167  'workflow_user' => $user->name,
168  'type_code' => $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($this->owner->type(), 'name'),
169  'asset_name' => $this->owner->name,
170  'status' => get_status_description($new_status),
171  'workflow_url' => current_url().$this->owner->getBackendHref('workflow', FALSE),
172  );
173  $log->replacements = $msg_reps;
174  $asset_edt_fns = $this->owner->getEditFns();
175  if (isset($asset_edt_fns->static_screens['preview'])) {
176  $log->replacements['preview_url'] = current_url().$this->owner->getBackendHref('preview', FALSE);
177  } else {
178  $log->replacements['preview_url'] = current_url().$this->owner->getBackendHref('details', FALSE);
179  }
180  $log->type = 'asset.workflow.log.reject';
181  $log->parameters['assetid'] = $this->owner->id;
182  $log->parameters['version'] = substr($this->owner->version, 0, strrpos($this->owner->version, '.'));
183  $log->send();
184  }
185  }
186 
187  } else {
188 
189  $running_schemas = $wfm->getSchemas($this->owner->id, TRUE, TRUE);
190  if (!empty($running_schemas)) {
191 
192  // if we are trying to approve this asset, we might not actually be a person
193  // in the workflow process - sounds weird (I know) but this could be a plain old
194  // admin that is trying to approve because metadata is now complete.
195  // the result is that this workflow process may already be complete
196  $mm = $GLOBALS['SQ_SYSTEM']->getMetadataManager();
197  $m_complete = !$mm->allowsMetadata($this->owner->id) || $mm->requiredFieldsComplete($this->owner->id) || $GLOBALS['SQ_SYSTEM']->am->isDependant($this->owner->id);
198 
199  if ($wfm->isWorkflowComplete($this->owner->id) && $m_complete && ($new_status & SQ_SC_STATUS_ALL_APPROVED)) {
200  if (!$wfm->completeWorkflow($this->owner->id)) {
201  trigger_localised_error('SYS0261', E_USER_WARNING);
202  return FALSE;
203  }
204  } else {
205  // we are doing a workflow and someone has just approved the asset, so record this
206  if (!$wfm->recordPublish($this->owner->id, $current_userid)) {
207  trigger_localised_error('SYS0077', E_USER_WARNING, $current_userid,$this->owner->name);
208  return FALSE;
209  }
210 
211  // if the workflow process is now complete, we can go ahead and clear out the schemas
212  // as long as all our metadata is also complete
213  if ($wfm->isWorkflowComplete($this->owner->id) && $m_complete && ($new_status & SQ_SC_STATUS_ALL_APPROVED)) {
214  if (!$wfm->completeWorkflow($this->owner->id)) {
215  trigger_localised_error('SYS0261', E_USER_WARNING);
216  return FALSE;
217  }
218  }
219  }
220 
221  // Since asset_status_editing_approval inherit from this object, it inherits this function, so when the asset go either from pending approval to approved, or editing approval to approved, lets send the asset workflow complete log message.
222  if ($new_status == SQ_STATUS_APPROVED || $new_status == SQ_STATUS_EDITING_APPROVED) {
223 
224  $ms = $GLOBALS['SQ_SYSTEM']->getMessagingService();
225  $user = $GLOBALS['SQ_SYSTEM']->am->getAsset($current_userid);
226  if (!$wfm->silentWorkflowParty($this->owner->id)) {
227  $log = $ms->newMessage();
228  $log->subject = 'Workflow Completed';
229  $msg_reps = Array(
230  'type_code' => $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($this->owner->type(), 'name'),
231  'asset_name' => $this->owner->name,
232  'workflow_url' => current_url().$this->owner->getBackendHref('workflow', FALSE),
233  );
234 
235  $log->replacements = $msg_reps;
236  $asset_edt_fns = $this->owner->getEditFns();
237  if (isset($asset_edt_fns->static_screens['preview'])) {
238  $log->replacements['preview_url'] = current_url().$this->owner->getBackendHref('preview', FALSE);
239  } else {
240  $log->replacements['preview_url'] = current_url().$this->owner->getBackendHref('details', FALSE);
241  }
242 
243  $log->type = 'asset.workflow.log.complete';
244  $log->parameters['assetid'] = $this->owner->id;
245  $log->parameters['version'] = substr($this->owner->version, 0, strrpos($this->owner->version, '.'));
246  $ms->enqueueMessage($log);
247  }
248 
249  }
250 
251  }//end if
252 
253  }//end else
254 
255  return TRUE;
256 
257  }//end processStatusChange()
258 
259 
260 }//end class
261 
262 ?>