Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
asset_status_live.inc
1 <?php
17 require_once SQ_INCLUDE_PATH.'/asset_status/asset_status.inc';
18 
36 {
37 
38 
44  function Asset_Status_Live($owner)
45  {
46  $this->Asset_Status($owner);
47  $this->status_tag = SQ_STATUS_LIVE;
48 
49  }//end constructor
50 
51 
59  public static function getDescription()
60  {
61  return translate('status_live');
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  $wfm = $GLOBALS['SQ_SYSTEM']->getWorkflowManager();
81  $running_schemas = $wfm->getSchemas($this->owner->id, true, true);
82 
83  if (!empty($running_schemas)) {
84  // workflow is currently running, but it should not be
85  // because LIVE doesnt need workflow
86  pre_echo('FIXME: SOMETHING HAS GONE WRONG HERE');
87  } else {
88  // workflow is not currently running for this asset
89  $statii[SQ_STATUS_LIVE_APPROVAL] = translate('status_change_place_up_for_review');
90  $statii[SQ_STATUS_EDITING] = translate('status_change_safe_edit');
91  if ($this->owner->adminAccess('')) {
92  $statii[SQ_STATUS_UNDER_CONSTRUCTION] = translate('status_change_place_under_construction');
93  $statii[SQ_STATUS_ARCHIVED] = translate('status_change_archive');
94  }
95  }//end if workflow running
96 
97  return $statii;
98 
99  }//end getAvailableStatii()
100 
101 
112  function processStatusChange($new_status, $update_parent=true)
113  {
114  if (!parent::processStatusChange($new_status, $update_parent)) {
115  return false;
116  }
117 
118  switch ($new_status) {
119  case SQ_STATUS_LIVE_APPROVAL :
120  // up for review basically means that we need to start
121  // the workflow process and get this asset re-approved
122  $wfm = $GLOBALS['SQ_SYSTEM']->getWorkflowManager();
123  $current_userid = $GLOBALS['SQ_SYSTEM']->currentUserId();
124 
125  // send an internal message
126  $ms = $GLOBALS['SQ_SYSTEM']->getMessagingService();
127  $user = $GLOBALS['SQ_SYSTEM']->am->getAsset($current_userid);
128 
129  $schemas = $wfm->getSchemas($this->owner->id, true);
130  if (!empty($schemas)) {
131  $ms = $GLOBALS['SQ_SYSTEM']->getMessagingService();
132  $msg = $ms->newMessage();
133  $msg->subject = 'Asset Up For Review';
134  $msg->type = 'asset.workflow.review';
135 
136  $msg_reps = Array(
137  'workflow_user' => $user->name,
138  'assetid' => $this->owner->id,
139  'type_code' => $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($this->owner->type(), 'name'),
140  'asset_name' => $this->owner->name,
141  'workflow_url' => current_url().$this->owner->getBackendHref('workflow', FALSE),
142  );
143  $msg->replacements = $msg_reps;
144  $asset_edt_fns = $this->owner->getEditFns();
145  if (isset($asset_edt_fns->static_screens['preview'])) {
146  $msg->replacements['preview_url'] = current_url().$this->owner->getBackendHref('preview', FALSE);
147  } else {
148  $msg->replacements['preview_url'] = current_url().$this->owner->getBackendHref('details', FALSE);
149  }
150 
151  if (!$wfm->startWorkflow($this->owner->id, false, $msg)) {
152  trigger_localised_error('SYS0262', E_USER_WARNING, $this->owner->name);
153  return false;
154  }
155  }
156 
157  if (!$wfm->silentWorkflowParty($this->owner->id)) {
158  $log = $ms->newMessage();
159  $log->type = 'asset.workflow.log.review';
160  $msg_reps = Array(
161  'user_name' => $user->name,
162  'workflow_user' => $user->name,
163  'type_code' => $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($this->owner->type(), 'name'),
164  'asset_name' => $this->owner->name,
165  'workflow_url' => current_url().$this->owner->getBackendHref('workflow', FALSE),
166  );
167  //$log->to = Array(0);
168  $log->replacements = $msg_reps;
169  $asset_edt_fns = $this->owner->getEditFns();
170  if (isset($asset_edt_fns->static_screens['preview'])) {
171  $log->replacements['preview_url'] = current_url().$this->owner->getBackendHref('preview', FALSE);
172  } else {
173  $log->replacements['preview_url'] = current_url().$this->owner->getBackendHref('details', FALSE);
174  }
175  $log->parameters['assetid'] = $this->owner->id;
176  $log->parameters['version'] = substr($this->owner->version, 0, strrpos($this->owner->version, '.'));
177  $ms->enqueueMessage($log);
178  }
179 
180  break;
181 
182  case SQ_STATUS_EDITING :
183  // we are safe editing
184  if (!$this->owner->saveSystemVersion()) {
185  trigger_localised_error('SYS0208', E_USER_WARNING);
186  return false;
187  }
188  break;
189  }
190 
191  return true;
192 
193  }//end processStatusChange()
194 
195 
196 }//end class
197 
198 ?>