Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
asset_status_bundle_under_construction.inc
1 <?php
17 require_once SQ_INCLUDE_PATH.'/asset_status/asset_status.inc';
18 
41 {
42 
43 
50  {
51  assert_is_a($owner, 'Workflow_Bundle');
52  $this->Asset_Status($owner);
53  $this->status_tag = SQ_STATUS_UNDER_CONSTRUCTION;
54 
55  }//end constructor
56 
57 
65  public static function getDescription()
66  {
67  return translate('core_workflow_bundle_editing');
68 
69  }//end getDescription()
70 
71 
79  function getAvailableStatii()
80  {
81  $available_statuses = Array();
82 
83  // cant do anything without write access
84  if (!$this->owner->writeAccess('')) {
85  return $available_statuses;
86  }
87 
88  // Status changes available:
89  // - Live: when all assets have no workflow
90  // - Approving: when at least some assets have workflow
91  // (assets without workflow will go live)
92  // - Approved: when at least some assets have workflow,
93  // but would be completed straight away
94  // (assets without workflow will go live)
95  //
96  // With multiple streams, "would be completed straight away"
97  // involves a test for all streams if the user has Admin
98  // permission to the bundled asset.
99  $has_workflow = FALSE;
100  $needs_workflow = FALSE;
101  $can_complete = FALSE;
102 
103  $m_complete = TRUE;
104 
105  $wfm = $GLOBALS['SQ_SYSTEM']->getWorkflowManager();
106  $mm = $GLOBALS['SQ_SYSTEM']->getMetadataManager();
107 
108  $our_asset_links = $GLOBALS['SQ_SYSTEM']->am->getLinks($this->owner->id, SQ_LINK_NOTICE);
109 
110  foreach ($our_asset_links as $our_asset_link) {
111  // If an asset is in Safe Editing mode, then we must treat it as a
112  // special case since it cannot go straight to Live - only to Safe
113  // Editing Approved (since Live cancels it). So treat it as if it
114  // had a completable workflow (ie. provide "Approve" link, not "Make
115  // Live").
116  $asset_info = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo($our_asset_link['minorid']);
117 
118  if ($has_workflow === FALSE) {
119  $status = (int)$asset_info[$our_asset_link['minorid']]['status'];
120  if ($status === SQ_STATUS_EDITING) {
121  $has_workflow = TRUE;
122  } else {
123  $schemas = $wfm->getSchemas($our_asset_link['minorid'], TRUE);
124  if (count($schemas) > 0) {
125  $has_workflow = TRUE;
126  }
127  }
128  }
129 
130  // Check for complete metadata
131  if ($m_complete === TRUE) {
132  if ($mm->allowsMetadata($this->owner->id) && !$GLOBALS['SQ_SYSTEM']->am->isDependant($this->owner->id)) {
133  $m_complete = $mm->requiredFieldsComplete($this->owner->id);
134  }
135  }
136 
137  // Both trigger conditions
138  if (($has_workflow === TRUE) && ($m_complete === FALSE)) {
139  break;
140  }
141 
142  }//end foreach
143 
144  if ($has_workflow === TRUE) {
145  if ($m_complete === FALSE) {
146  $available_statuses[SQ_STATUS_PENDING_APPROVAL] = translate('status_change_apply_for_approval');
147  } else {
148  $all_streams = $this->owner->getAllBundleStreams();
149  $bypassable_streams = $this->owner->getAllBypassableBundleStreams();
150  $default_bypassable = $this->owner->isDefaultStreamBypassable();
151 
152  $needs_approve = FALSE;
153  $needs_apply = FALSE;
154 
155  if ($default_bypassable === TRUE) {
156  // Default stream is bypassable
157  $needs_approve = TRUE;
158  } else if (count($bypassable_streams) > 0) {
159  // At least one bypassable stream
160  $needs_approve = TRUE;
161  }
162 
163  if (($default_bypassable === FALSE) || (count($bypassable_streams) < count($all_streams))) {
164  // Default stream is not bypassable, or at least one un-bypassable stream
165  $needs_apply = TRUE;
166  }
167 
168  // If we have to apply for approval on at least one stream
169  if ($needs_apply === TRUE) {
170  $available_statuses[SQ_STATUS_PENDING_APPROVAL] = translate('status_change_apply_for_approval');
171  }
172 
173  // If we can complete something through at least one stream
174  if ($needs_approve === TRUE) {
175  $available_statuses[SQ_STATUS_APPROVED] = translate('status_change_approve');
176  }
177  }
178  } else {
179  $available_statuses[SQ_STATUS_LIVE] = translate('status_change_approve_and_make_live');
180  }//end if has workflow
181 
182  return $available_statuses;
183 
184  }//end getAvailableStatii()
185 
186 
194  {
195  // TODO: Incomplete metadata message.
196  return '';
197 
198  }//end getStatusChangeMessage()
199 
200 
201 }//end class
202 
203 ?>