Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
paint_layout_page_edit_fns.inc
1 <?php
18 require_once SQ_CORE_PACKAGE_PATH.'/page_templates/page_standard/page_standard_edit_fns.inc';
19 require_once SQ_CORE_PACKAGE_PATH.'/paint_layout/paint_layout_page/paint_layout_page.inc';
20 
33 {
34 
35 
40  function __construct()
41  {
42  parent::__construct();
43 
44  }//end constructor
45 
46 
57  public function paintCurrentAssetTypes(Paint_Layout_Page $asset, Backend_Outputter $o, $prefix)
58  {
59  $write_access = $asset->writeAccess('content');
60  $folder = $asset->getFolder('type_formats');
61 
62  $types = $asset->attr('types');
63  if (empty($types) || !is_array($types)) {
64  echo 'There are no types defined';
65  return FALSE;
66  }
67  $type_names = $GLOBALS['SQ_SYSTEM']->am->getTypeInfo(array_keys($types), 'name');
68  ?>
69  <table class="sq-backend-table">
70  <tr>
71  <td class="sq-backend-table-header"><?php echo translate('asset_type'); ?></td>
72  <td class="sq-backend-table-header"><?php echo translate('inherit_types'); ?></td>
73  <?php
74  if ($write_access) {
75  ?>
76  <td class="sq-backend-table-header"><?php echo translate('remove_question'); ?></td>
77  <?php
78  }
79  ?>
80  </tr>
81  <?php
82  foreach ($types as $type => $inherit) {
83  ?>
84  <tr>
85  <td class="sq-backend-table-cell">
86  <?php
87  echo $type_names[$type];
88  ?>
89  </td>
90  <td class="sq-backend-table-cell">
91  <?php
92  if ($write_access) {
93  check_box($prefix.'_inherit_types[]', $type, $inherit);
94  } else {
95  echo ($inherit) ? translate('yes') : translate('no');
96  }
97  ?>
98  </td>
99  <?php
100  if ($write_access) {
101  ?>
102  <td class="sq-backend-table-cell">
103  <?php
104  check_box($prefix.'_remove[]', $type, FALSE);
105  ?>
106  </td>
107  <?php
108  }
109  ?>
110  </tr>
111  <?php
112  }//end foreach $types
113  ?>
114  </table>
115  <?php
116  return TRUE;
117 
118  }//end paintCurrentAssetTypes()
119 
120 
131  public function processCurrentAssetTypes(Paint_Layout_Page $asset, Backend_Outputter $o, $prefix)
132  {
133  $types = $asset->attr('types');
134  $folder = $asset->getFolder('type_formats');
135  $formats = $asset->getFormats('type_formats');
136 
137  // Remove type format bodycopies
138  $removed = array_get_index($_POST, $prefix.'_remove', Array());
139  foreach ($removed as $type) {
140  if (isset($types[$type])) {
141  unset($types[$type]);
142 
143  if (in_array($type, $formats)) {
144  // we also want to send the bodycopy to the trash
145  $link = $GLOBALS['SQ_SYSTEM']->am->getLink($folder->id, SQ_LINK_TYPE_2, SQ_PAINT_LAYOUT_FORMAT_ASSET_TYPE, TRUE, $type);
146  if (empty($link)) {
147  trigger_localised_error('CORE0216', E_USER_WARNING);
148  } else {
149  // back up in your trash with the resurection
150  $folder->deleteLink($link['linkid']);
151  }
152  }
153  }
154  }
155 
156  // update type format array
157  if (!isset($_POST[$prefix.'_inherit_types'])) {
158  $_POST[$prefix.'_inherit_types'] = Array();
159  }
160 
161  for (reset($types); NULL !== ($k = key($types)); next($types)) {
162  $types[$k] = (in_array($k, $_POST[$prefix.'_inherit_types'])) ? TRUE : FALSE;
163  }
164  $asset->setAttrValue('types', $types);
165 
166  return TRUE;
167 
168  }//end processCurrentAssetTypes()
169 
170 
181  public function paintAddAssetType(Paint_Layout_Page $asset, Backend_Outputter $o, $prefix)
182  {
183  if (!$asset->writeAccess('content')) return FALSE;
184 
185  $types = $GLOBALS['SQ_SYSTEM']->am->getTypeList();
186  $types = array_diff($types, $asset->attr('types'));
187 
188  $type_options = $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($types, 'name');
189  asort($type_options);
190  $type_options = Array('' => '- Select asset type -') + $type_options;
191  combo_box($prefix.'_new_type', $type_options, FALSE, '');
192 
193  }//end paintAddAssetType()
194 
195 
206  public function processAddAssetType(Paint_Layout_Page $asset, Backend_Outputter $o, $prefix)
207  {
208  $ret = FALSE;
209 
210  if (isset($_POST[$prefix.'_new_type'])) {
211 
212  $type = trim($_POST[$prefix.'_new_type']);
213 
214  if (!empty($type)) {
215  // add new type in the types list
216  $types = $asset->attr('types');
217  if (!isset($types[$type])) {
218  $types[$type] = TRUE;
219  $asset->setAttrValue('types', $types);
220  $ret = TRUE;
221 
222  $ret = ($asset->createTypeFormatBodycopy($type));
223  }
224  }
225 
226  }
227 
228  return $ret;
229 
230  }//end processAddAssetType()
231 
232 
243  public function paintUsage(Paint_Layout_Page $asset, Backend_Outputter $o, $prefix)
244  {
245  $o->openRaw();
246  echo '<p><i>'.translate('design_usage_explanation').'</i></p>';
247  echo '<div style="line-height: 160%">';
248  $res = $GLOBALS['SQ_SYSTEM']->am->getAssetidsByLookupValue('paint_layout::%', $asset->id, TRUE);
249  $res = $this->_getTreeTops($res);
250  $singular = strtolower(translate('child'));
251  $plural = strtolower(translate('children'));
252  $paginate = (count($res) > 20);
253  if ($paginate) {
254  $current_page_no = array_get_index($_REQUEST, 'usage_page_no', 0);
255  $total_pages = ceil(count($res) / 20);
256  $res = array_slice($res, $current_page_no * 20, 20);
257  }
258  foreach ($res as $entry) {
259  $count = $entry['child_count'];
260  echo get_asset_tag_line($entry['assetid'], 'lookupValues');
261  if (!empty($count)) {
262  echo ' and '.$count.' '.(($count > 1) ? $plural : $singular);
263  }
264  echo '<br />';
265  }
266  echo '</div>';
267  if ($paginate) {
268  echo '<p>';
269  if ($current_page_no > 0) {
270  echo '<a href="'.htmlspecialchars(replace_query_string_vars(Array('usage_page_no' => $current_page_no-1))).'">'.translate('previous_page').'</a> &nbsp; ';
271  }
272  echo translate('page_number', $current_page_no + 1, $total_pages);
273  if ($current_page_no < ($total_pages-1)) {
274  echo ' &nbsp; <a href="'.htmlspecialchars(replace_query_string_vars(Array('usage_page_no' => $current_page_no+1))).'">'.translate('next_page').'</a> ';
275  }
276  echo '</p>';
277  }
278  $o->closeRaw();
279 
280  }//end paintUsage()
281 
282 
299  protected function _getTreeTops(Array $treeids)
300  {
301  $all_treeids = Array();
302  foreach ($treeids as $assetid => $asset_treeids) {
303  foreach ($asset_treeids[0] as $asset_treeid) {
304  if (($asset_treeid === 'override') || ($asset_treeid === 'not_override')) {
305  continue;
306  }
307  $all_treeids[$asset_treeid] = $assetid;
308  }
309  }
310  uksort($all_treeids, Array($this, '_strlenCmp'));
311  $res = Array();
312  foreach ($all_treeids as $treeid => $assetid) {
313  $treeid_copy = $treeid;
314  while (!empty($treeid_copy)) {
315  if (isset($res[$treeid_copy])) {
316  $res[$treeid_copy]['child_count']++;
317  continue(2);
318  }
319  $treeid_copy = substr($treeid_copy, 0, -SQ_CONF_ASSET_TREE_SIZE);
320  }
321  $res[$treeid]['assetid'] = $assetid;
322  $res[$treeid]['child_count'] = 0;
323  }
324  ksort($res); // put in treeid order
325  return $res;
326 
327  }//end _getTreeTops()
328 
329 
339  protected function _strlenCmp($a, $b)
340  {
341  return strlen($a) > strlen($b);
342 
343  }//end _strlenCmp()
344 
345 
346 }//end class
347 ?>