17 require_once SQ_INCLUDE_PATH.
'/asset_status/asset_status.inc';
47 $this->status_tag = SQ_STATUS_UNDER_CONSTRUCTION;
61 return translate(
'status_under_construction');
78 if (!$this->owner->writeAccess(
''))
return $statii;
81 if ($this->owner->adminAccess(
'')) {
82 $statii[SQ_STATUS_ARCHIVED] = translate(
'status_change_archive');
85 $wfm = $GLOBALS[
'SQ_SYSTEM']->getWorkflowManager();
86 $running_schemas = $wfm->getSchemas($this->owner->id,
true,
true);
88 if (!empty($running_schemas)) {
91 pre_echo(
'FIXME: SOMETHING HAS GONE WRONG HERE');
94 $schemas = $wfm->getSchemas($this->owner->id,
true);
95 if (empty($schemas)) {
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);
104 $this->_tmp[
'metadata_complete'] = TRUE;
106 if ($this->_tmp[
'metadata_complete']) {
107 $statii[SQ_STATUS_LIVE] = translate(
'status_change_approve_and_make_live');
113 if ($this->owner->adminAccess(
'')) {
116 $needs_workflow = FALSE;
117 $wf_complete = FALSE;
119 foreach ($schemas as $schemaid) {
120 $streams = $wfm->getStreams($schemaid);
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) {
127 $needs_workflow = TRUE;
134 $wf_complete = $wfm->testPublish($this->owner->id, $GLOBALS[
'SQ_SYSTEM']->currentUserId(),
'');
135 $needs_workflow = !$wf_complete;
139 $mm = $GLOBALS[
'SQ_SYSTEM']->getMetadataManager();
140 if ($mm->allowsMetadata($this->owner->id)) {
142 $m_complete = $mm->requiredFieldsComplete($this->owner->id);
143 $is_dependant = $GLOBALS[
'SQ_SYSTEM']->am->isDependant($this->owner->id);
148 if ($wf_complete === TRUE && (($m_complete === TRUE && !$is_dependant) || $is_dependant)) {
149 $statii[SQ_STATUS_APPROVED] = translate(
'status_change_approve');
151 if (($needs_workflow === TRUE) || ($m_complete === FALSE && !$is_dependant)) {
152 $statii[SQ_STATUS_PENDING_APPROVAL] = translate(
'status_change_apply_for_approval');
158 $statii[SQ_STATUS_APPROVED] = translate(
'status_change_approve');
160 $statii[SQ_STATUS_PENDING_APPROVAL] = translate(
'status_change_apply_for_approval');
179 if (!isset($this->_tmp[
'metadata_complete'])) {
180 $mm = $GLOBALS[
'SQ_SYSTEM']->getMetadataManager();
181 $this->_tmp[
'metadata_complete'] = $mm->requiredFieldsComplete($this->owner->id);
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,
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>');
210 if (!parent::processStatusChange($new_status, $update_parent)) {
216 switch ($new_status) {
217 case SQ_STATUS_PENDING_APPROVAL:
218 $wfm = $GLOBALS[
'SQ_SYSTEM']->getWorkflowManager();
221 $current_userid = $GLOBALS[
'SQ_SYSTEM']->currentUserId();
223 if (!$wfm->startWorkflow($this->owner->id)) {
224 trigger_localised_error(
'SYS0262', E_USER_WARNING, $this->owner->name);
229 $ms = $GLOBALS[
'SQ_SYSTEM']->getMessagingService();
230 $user = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($current_userid);
233 if (!$wfm->silentWorkflowParty($this->owner->id)) {
234 $log = $ms->newMessage();
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),
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);
248 $log->replacements[
'preview_url'] = current_url().$this->owner->getBackendHref(
'details', FALSE);
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);
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';
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');
268 $msg->parameters[
'reply_to'] = $GLOBALS[
'SQ_SYSTEM']->currentUserId();
270 if ($schema->attr(
'schema_from_email_address') !=
'') {
271 $msg->from = $schema->attr(
'schema_from_email_address');
274 $msg->to = array_merge($msg->to, $publishers);
275 $msg->replacements = $msg_reps;
276 $msg->parameters[
'assetid'] = $this->owner->id;
277 $ms->enqueueMessage($msg);
285 $wfm = $GLOBALS[
'SQ_SYSTEM']->getWorkflowManager();
286 if (!$wfm->notifyOnLive($this->owner->id, $this->status_tag)) {
291 if (!$this->owner->setDate(
'published', time())) {
296 case SQ_STATUS_APPROVED :
298 $wfm = $GLOBALS[
'SQ_SYSTEM']->getWorkflowManager();
301 $current_userid = $GLOBALS[
'SQ_SYSTEM']->currentUserId();
302 $wfm->setCurrentUserAsLastStarted($current_userid, $this->owner->id);