Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
asset_status_under_construction.inc
1 <?php
17 require_once SQ_INCLUDE_PATH.'/asset_status/asset_status.inc';
18 
36 {
37 
38 
45  {
46  $this->Asset_Status($owner);
47  $this->status_tag = SQ_STATUS_UNDER_CONSTRUCTION;
48 
49  }//end constructor
50 
51 
59  public static function getDescription()
60  {
61  return translate('status_under_construction');
62 
63  }//end getDescription()
64 
65 
73  function getAvailableStatii()
74  {
75  $statii = Array();
76 
77  // cant do anything without write access
78  if (!$this->owner->writeAccess('')) return $statii;
79 
80  // any admin can change the status to ARCHIVED
81  if ($this->owner->adminAccess('')) {
82  $statii[SQ_STATUS_ARCHIVED] = translate('status_change_archive');
83  }
84 
85  $wfm = $GLOBALS['SQ_SYSTEM']->getWorkflowManager();
86  $running_schemas = $wfm->getSchemas($this->owner->id, true, true);
87 
88  if (!empty($running_schemas)) {
89  // workflow is currently running, but it should not be
90  // because UNDER_CONSTRUCTION does not require workflow
91  pre_echo('FIXME: SOMETHING HAS GONE WRONG HERE');
92  } else {
93  // workflow is not currently running for this asset
94  $schemas = $wfm->getSchemas($this->owner->id, true);
95  if (empty($schemas)) {
96  // no workflow defined, so any admin can make this live
97  if ($this->owner->adminAccess('')) {
98  if (!$GLOBALS['SQ_SYSTEM']->am->isDependant($this->owner->id)) {
99  if (!isset($this->_tmp['metadata_complete'])) {
100  $mm = $GLOBALS['SQ_SYSTEM']->getMetadataManager();
101  $this->_tmp['metadata_complete'] = $mm->requiredFieldsComplete($this->owner->id);
102  }
103  } else {
104  $this->_tmp['metadata_complete'] = TRUE;
105  }
106  if ($this->_tmp['metadata_complete']) {
107  $statii[SQ_STATUS_LIVE] = translate('status_change_approve_and_make_live');
108  }
109  }
110  } else {
111  // so we have workflows, but none of them are running so lets see what will happen
112  // if this user approves to determine if they can live edit
113  if ($this->owner->adminAccess('')) {
114  // If we are an admin, we should test all the streams
115  // to see if some need workflow and others don't
116  $needs_workflow = FALSE;
117  $wf_complete = FALSE;
118 
119  foreach ($schemas as $schemaid) {
120  $streams = $wfm->getStreams($schemaid);
121 
122  foreach ($streams as $streamid => $stream_name) {
123  $publish_result = $wfm->testPublish($this->owner->id, $GLOBALS['SQ_SYSTEM']->currentUserId(), $stream_name);
124  if ($publish_result === TRUE) {
125  $wf_complete = TRUE;
126  } else {
127  $needs_workflow = TRUE;
128  }
129  }
130  }
131  } else {
132  // If we are a normal user, we can only use the default
133  // stream, so only test that instead
134  $wf_complete = $wfm->testPublish($this->owner->id, $GLOBALS['SQ_SYSTEM']->currentUserId(), '');
135  $needs_workflow = !$wf_complete;
136  }
137 
138  // we also need to check what if all the required metadata fields are completed
139  $mm = $GLOBALS['SQ_SYSTEM']->getMetadataManager();
140  if ($mm->allowsMetadata($this->owner->id)) {
141 
142  $m_complete = $mm->requiredFieldsComplete($this->owner->id);
143  $is_dependant = $GLOBALS['SQ_SYSTEM']->am->isDependant($this->owner->id);
144 
145  // In the case of multiple streams, we may need to provide
146  // BOTH 'approve' and 'apply for approval' if some streams
147  // can be approved bypassing workflow, and some can't.
148  if ($wf_complete === TRUE && (($m_complete === TRUE && !$is_dependant) || $is_dependant)) {
149  $statii[SQ_STATUS_APPROVED] = translate('status_change_approve');
150  }
151  if (($needs_workflow === TRUE) || ($m_complete === FALSE && !$is_dependant)) {
152  $statii[SQ_STATUS_PENDING_APPROVAL] = translate('status_change_apply_for_approval');
153  }
154  } else {
155  // this asset needs to allow status "apply for approval" and "approve change" (if workflow is complete),
156  // because asset does not allows metadata
157  if ($wf_complete) {
158  $statii[SQ_STATUS_APPROVED] = translate('status_change_approve');
159  }
160  $statii[SQ_STATUS_PENDING_APPROVAL] = translate('status_change_apply_for_approval');
161  }
162  }
163 
164  }//end if workflow running
165 
166  return $statii;
167 
168  }//end getAvailableStatii()
169 
170 
178  {
179  if (!isset($this->_tmp['metadata_complete'])) {
180  $mm = $GLOBALS['SQ_SYSTEM']->getMetadataManager();
181  $this->_tmp['metadata_complete'] = $mm->requiredFieldsComplete($this->owner->id);
182  }
183  if (!$this->_tmp['metadata_complete']) {
184  $replace_string_vars = Array (
185  'asset_ei_screen' => 'metadata',
186  'am_section' => 'edit_asset',
187  'assetid' => $this->owner->id,
188  );
189  $metadata_screen_url = htmlspecialchars(replace_query_string_vars($replace_string_vars));
190  return translate('cannot_make_live_metadata_incomplete', '<a href="'.$metadata_screen_url.'">'.strtolower(translate('metadata')).'</a>');
191 
192  }
193  return '';
194 
195  }//end getStatusChangeMessage()
196 
197 
208  function processStatusChange($new_status, $update_parent=true)
209  {
210  if (!parent::processStatusChange($new_status, $update_parent)) {
211  return false;
212  }
213 
214  // so we know we can set the status but we need to
215  // do some workflow stuff if we are changing to PENDING APPROVAL
216  switch ($new_status) {
217  case SQ_STATUS_PENDING_APPROVAL:
218  $wfm = $GLOBALS['SQ_SYSTEM']->getWorkflowManager();
219 
220  // we are going to make this asset live by starting the workflow process
221  $current_userid = $GLOBALS['SQ_SYSTEM']->currentUserId();
222 
223  if (!$wfm->startWorkflow($this->owner->id)) {
224  trigger_localised_error('SYS0262', E_USER_WARNING, $this->owner->name);
225  return false;
226  }
227 
228  // log a message to let people know that workflow has started
229  $ms = $GLOBALS['SQ_SYSTEM']->getMessagingService();
230  $user = $GLOBALS['SQ_SYSTEM']->am->getAsset($current_userid);
231  $msg_reps = Array();
232 
233  if (!$wfm->silentWorkflowParty($this->owner->id)) {
234  $log = $ms->newMessage();
235  $msg_reps = Array(
236  'user_name' => $user->name,
237  'workflow_user' => $user->name,
238  'type_code' => $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($this->owner->type(), 'name'),
239  'asset_name' => $this->owner->name,
240  'status' => $this->getDescription(),
241  'workflow_url' => current_url().$this->owner->getBackendHref('workflow', FALSE),
242  );
243  $log->replacements = $msg_reps;
244  $asset_edt_fns = $this->owner->getEditFns();
245  if (isset($asset_edt_fns->static_screens['preview'])) {
246  $log->replacements['preview_url'] = current_url().$this->owner->getBackendHref('preview', FALSE);
247  } else {
248  $log->replacements['preview_url'] = current_url().$this->owner->getBackendHref('details', FALSE);
249  }
250 
251  $log->type = 'asset.workflow.log.started';
252  $log->parameters['assetid'] = $this->owner->id;
253  $log->parameters['version'] = substr($this->owner->version, 0, strrpos($this->owner->version, '.'));
254  $ms->enqueueMessage($log);
255 
256  $running_schemas = $wfm->getSchemas($this->owner->id, TRUE, TRUE);
257  foreach ($running_schemas as $schemaid) {
258  $publishers = $wfm->whoCanPublish($this->owner->id, $schemaid);
259  if (count($publishers) > 0) {
260  $msg = $ms->newMessage();
261  $msg->type = 'asset.workflow.announce.started';
262 
263  // see if we have the 'from' field set
264  $schema = $GLOBALS['SQ_SYSTEM']->am->getAsset($schemaid);
265  if ($schema->attr('schema_reply_to_email_address') != '') {
266  $msg->parameters['reply_to'] = $schema->attr('schema_reply_to_email_address');
267  } else {
268  $msg->parameters['reply_to'] = $GLOBALS['SQ_SYSTEM']->currentUserId();
269  }
270  if ($schema->attr('schema_from_email_address') != '') {
271  $msg->from = $schema->attr('schema_from_email_address');
272  }
273 
274  $msg->to = array_merge($msg->to, $publishers);
275  $msg->replacements = $msg_reps;
276  $msg->parameters['assetid'] = $this->owner->id;
277  $ms->enqueueMessage($msg);
278  }
279  }
280  }
281  break;
282 
283  case SQ_STATUS_LIVE:
284  // notify people that the asset has gone live
285  $wfm = $GLOBALS['SQ_SYSTEM']->getWorkflowManager();
286  if (!$wfm->notifyOnLive($this->owner->id, $this->status_tag)) {
287  return false;
288  }
289 
290  // update the last published date
291  if (!$this->owner->setDate('published', time())) {
292  return false;
293  }
294  break;
295 
296  case SQ_STATUS_APPROVED :
297 
298  $wfm = $GLOBALS['SQ_SYSTEM']->getWorkflowManager();
299 
300  // we are going approve this asset instead of initiating the workflow
301  $current_userid = $GLOBALS['SQ_SYSTEM']->currentUserId();
302  $wfm->setCurrentUserAsLastStarted($current_userid, $this->owner->id);
303 
304  break;
305  }
306 
307  return true;
308 
309  }//end processStatusChange()
310 
311 
312 }//end class
313 
314 ?>