Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
workflow_step_condition_edit_fns.inc
1 <?php
18 require_once SQ_INCLUDE_PATH.'/asset_edit/asset_edit_fns.inc';
19 
32 {
33 
34 
39  function __construct()
40  {
41  parent::__construct();
42  unset($this->static_screens['workflow']);
43  unset($this->static_screens['metadataSchemas']);
44  unset($this->static_screens['metadata']);
45 
46  }//end constructor
47 
48 
59  {
60  $write_access = $asset->writeAccess('attributes');
61  $prefix = $asset->getPrefix();
62  $wfm = $GLOBALS['SQ_SYSTEM']->getWorkflowManager();
63  require_once SQ_LIB_PATH.'/html_form/html_form.inc';
64 
65  $cond_logic = $asset->attr('logic');
66  $cond_logic_num = $asset->attr('logic_num');
67  if (!$cond_logic_num) $cond_logic_num = '';
68 
69  $userid = $asset->attr('userid');
70 
71  $user_info = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo(Array($userid), Array('user', 'user_group'), FALSE);
72  if (empty($user_info)) return FALSE;
73 
74  ?>
75  <td class="sq-backend-table-cell"><?php echo get_asset_tag_line($userid); ?></td>
76  <td class="sq-backend-table-cell">
77  <?php
78  $notify = $asset->attr('notify');
79  if (!$write_access) {
80  echo ($notify) ? translate('yes') : translate('no');
81  } else {
82  check_box($prefix.'_notify', '1', $notify);
83  }
84  ?>
85  </td>
86  <td class="sq-backend-table-cell">
87  <?php
88  $require_comment = $asset->attr('require_comment');
89  if (!$write_access) {
90  echo ($require_comment) ? translate('yes') : translate('no');
91  } else {
92  check_box($prefix.'_require_comment', '1', $require_comment);
93  }
94  ?>
95  </td>
96  <td class="sq-backend-table-cell">
97  <?php
98  $user = $GLOBALS['SQ_SYSTEM']->am->getAsset($userid);
99  if (!$write_access) {
100  $user = $GLOBALS['SQ_SYSTEM']->am->getAsset($userid);
101  if (($user instanceof User)) {
102  echo '&nbsp;';
103  } else {
104  if (isset($wfm->_valid_cond_logic[$cond_logic])) {
105  echo '<i>'.$wfm->_valid_cond_logic[$cond_logic];
106  if ($cond_logic_num) {
107  echo ' '.$cond_logic_num.' group member'.(($cond_logic_num > 1) ? 's' : '').' must approve</i>';
108  }
109  }
110  }
111  } else {
112  if (($user instanceof User)) {
113  hidden_field($prefix.'_logic', '>=');
114  hidden_field($prefix.'_logic_num', '1');
115  } else {
116  combo_box($prefix.'_logic', $wfm->_valid_cond_logic, FALSE, $cond_logic);
117  echo '&nbsp;';
118 
119  ob_start();
120  text_box($prefix.'_logic_num', $cond_logic_num, 4);
121  $text_box = ob_get_contents();
122  ob_end_clean();
123  echo translate('members_must_approve', $text_box);
124  }
125  }
126  ?>
127  </td>
128  <?php
129 
130  return TRUE;
131 
132  }//end paintStepCondition()
133 
134 
145  {
146  // need to have write access to make any changes
147  if (!$asset->writeAccess('attributes')) return FALSE;
148 
149  $prefix = $asset->getPrefix();
150 
151  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
152  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
153 
154  $cond_logic = array_get_index($_POST, $prefix.'_logic');
155  if (!$asset->setAttrValue('logic', $cond_logic)) {
156  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
157  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
158  return FALSE;
159  }
160 
161  if (isset($_POST[$prefix.'_logic_num']) && $cond_logic != 'all') {
162  $cond_logic_num = (!empty($_POST[$prefix.'_logic_num'])) ? (int) $_POST[$prefix.'_logic_num'] : 0;
163  } else {
164  $cond_logic_num = 0;
165  }
166  if (!$asset->setAttrValue('logic_num', $cond_logic_num)) {
167  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
168  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
169  return FALSE;
170  }
171 
172  $notify = (bool) array_get_index($_POST, $prefix.'_notify', FALSE);
173  if (!$asset->setAttrValue('notify', $notify)) {
174  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
175  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
176  return FALSE;
177  }
178 
179  $require_comment = (bool) array_get_index($_POST, $prefix.'_require_comment', FALSE);
180  if (!$asset->setAttrValue('require_comment', $require_comment)) {
181  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
182  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
183  return FALSE;
184  }
185 
186  if (!$asset->saveAttributes()) {
187  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
188  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
189  return FALSE;
190  }
191 
192  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
193  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
194 
195  return TRUE;
196 
197  }//end processStepCondition()
198 
199 
212  function generateWorkflowArray(Asset $asset, &$workflow_array)
213  {
214  // work out the logic expression
215  $logic = $asset->attr('logic');
216  $logic_num = $asset->attr('logic_num');
217 
218  $wfm = $GLOBALS['SQ_SYSTEM']->getWorkflowManager();
219  if (in_array($logic, $wfm->_valid_logic_with_right_operand)) {
220  $logic = $logic.(($logic_num) ? " $logic_num" : ' 0');
221  } else {
222  $logic = $logic.(($logic_num) ? " $logic_num" : '');
223  }
224 
225  $publisher = $asset->attr('userid');
226  $workflow_array[$publisher] = Array('logic' => $logic, 'published_by' => Array());
227 
228  // commenting
229  $workflow_array[$publisher]['require_comment'] = $asset->attr('require_comment');
230 
231  return TRUE;
232 
233  }//end generateWorkflowArray()
234 
235 
236 }//end class
237 
238 ?>