Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
asset_status_bundle_pending_approval.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_PENDING_APPROVAL;
54 
55  }//end constructor
56 
57 
65  public static function getDescription()
66  {
67  return translate('core_workflow_bundle_approving');
68 
69  }//end getDescription()
70 
71 
79  function getAvailableStatii()
80  {
81  $available_statuses = Array();
82 
83  // The workflow can be advanced if at least one asset in the
84  // bundle can have its changes approved
85  $can_approve = FALSE;
86 
87  // The workflow can be completed only if all remaining assets
88  // with workflow will be completed if its changes are approved
89  $can_complete = TRUE;
90 
91  // The workflow can be rejected if:
92  // - The user has *effective* Admin permission to the bundle
93  // - The user has *effective* Admin permission to any asset in
94  // the bundle
95  // - At least one asset in the bundle can have its changes
96  // approved (since ability to approve comes with the ability
97  // to reject)
98  $can_reject = FALSE;
99 
100  // If we have admin access to the bundle,
101  // we can always reject changes
102  if ($this->owner->adminAccess('') === TRUE) {
103  $can_reject = TRUE;
104  }
105 
106  $wfm = $GLOBALS['SQ_SYSTEM']->getWorkflowManager();
107  $mm = $GLOBALS['SQ_SYSTEM']->getMetadataManager();
108 
109  $our_asset_links = $GLOBALS['SQ_SYSTEM']->am->getLinks($this->owner->id, SQ_LINK_NOTICE);
110  foreach ($our_asset_links as $our_asset_link) {
111  // Check for admin permission
112  if ($can_reject === FALSE) {
113  $asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($our_asset_link['minorid']);
114  if ($asset->adminAccess('') === TRUE) {
115  $can_reject = TRUE;
116  }
117  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($asset);
118  unset($asset);
119  }
120 
121  if ($can_approve === FALSE) {
122  $next_publishers = $wfm->whoCanPublish($our_asset_link['minorid']);
123  if (in_array($GLOBALS['SQ_SYSTEM']->currentUserId(), $next_publishers) !== FALSE) {
124  $can_approve = TRUE;
125  $can_reject = TRUE;
126  }
127  }
128 
129  if ($can_complete === TRUE) {
130  if ($wfm->testPublish($our_asset_link['minorid'], $GLOBALS['SQ_SYSTEM']->currentUserId()) === FALSE) {
131  $can_complete = FALSE;
132  }
133  }
134  }
135 
136  // Either the workflow can be completed, or it can't but workflow
137  // can progress, or we can't progress workflow at all
138  if ($can_complete === TRUE) {
139  $available_statuses[SQ_STATUS_APPROVED] = translate('status_change_approve');
140  } else if ($can_approve === TRUE) {
141  $available_statuses[SQ_STATUS_PENDING_APPROVAL] = translate('status_change_approve_changes');
142  }
143 
144  // But may be allowed to reject regardless
145  if ($can_reject === TRUE) {
146  $available_statuses[SQ_STATUS_UNDER_CONSTRUCTION] = translate('status_change_reject_changes');
147  }
148 
149  return $available_statuses;
150 
151  }//end getAvailableStatii()
152 
153 
154 }//end class
155 
156 ?>