Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
soap_api_design_lookup_service.inc
1 <?php
18 require_once SQ_PACKAGES_PATH.'/web_services/api/soap_api/soap_api.inc';
19 
31 class Soap_Api_Design_Lookup_Service extends Soap_Api
32 {
33 
34 
41  function __construct($assetid=0)
42  {
43  parent::__construct($assetid);
44 
45  }//end constructor
46 
47 
55  public function getFunctionList()
56  {
57  return Array(
58  'ApplyDesign' => '1',
59  'RemoveDesign' => '1',
60  'GetDesignFromURL' => '1',
61  'ApplyAssetPaintLayout' => '1',
62  'RemoveAssetPaintLayout'=> '1',
63  );
64 
65  }//end getFunctionList()
66 
67 
85  function ApplyDesign($request)
86  {
87  $request_info = (Array) $request;
88  $new_designid = array_get_index($request_info, 'DesignID', '');
89  $assetid = array_get_index($request_info, 'AssetID', '');
90  $design_type = array_get_index($request_info, 'DesignType', '');
91  $user_defined_design_name = array_get_index($request_info, 'UserDefinedDesignName', '');
92 
93  $design_name = self::getDesignNameFromType($design_type);
94  if (empty($design_name)) throw new SoapFault('Server', 'The Design Type is invalid. Operation Aborted.');
95 
96  $designs_ok = TRUE;
97  $design_changed = FALSE;
98 
99  if (!empty($assetid) && !empty($new_designid)) {
100  $asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($assetid);
101  $design = $GLOBALS['SQ_SYSTEM']->am->getAsset($new_designid);
102 
103  if (!($design instanceof Design)) {
104  throw new SoapFault('Server', 'The DesignID Provided Does Not Belong To A Design Asset');
105  }//end if
106 
107  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
108  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
109 
110  $update_design_cascade = FALSE;
111  if ($design_name == ('design::user::'.$user_defined_design_name)) {
112  $old_designid = 0;
113  if (empty($user_defined_design_name)) {
114  throw new SoapFault('Server', 'User Defined Design Name is either empty or not valid.');
115  } else {
116  if ($GLOBALS['SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_NOTICE, 'design', FALSE, $user_defined_design_name)) {
117  throw new SoapFault('Server', 'Design Name '.$user_defined_design_name.' is already in use');
118  trigger_localised_error('SYS0134', E_USER_WARNING, $user_defined_design_name);
119  }// end if
120  }//end else
121  } else {
122  // Is it not user defined design
123  if (in_array($design_type, Array('OverrideUserDefined', 'UserDefined'))) {
124  $design_name = $design_name.$user_defined_design_name;
125  }//end if
126 
127  $old_design_link = $GLOBALS['SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_NOTICE, 'design', FALSE, $design_name);
128  $old_designid = (empty($old_design_link)) ? 0 : $old_design_link['minorid'];
129 
130  }//end else
131 
132  if ($new_designid != $old_designid) {
133 
134  if ($old_designid) {
135  if (!$asset->deleteLink($old_design_link['linkid'])) {
136  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
137  $designs_ok = FALSE;
138  break;
139  }//end if
140  }//end if
141 
142  if ($new_designid) {
143  $design = $GLOBALS['SQ_SYSTEM']->am->getAsset($new_designid);
144  if (is_null($design)) {
145  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
146  $designs_ok = FALSE;
147  break;
148  }//end if
149 
150  if (!$asset->createLink($design, SQ_LINK_NOTICE, $design_name)) {
151  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
152  $designs_ok = FALSE;
153  break;
154  }//end if
155  }//end if
156  $update_design_cascade = TRUE;
157  } else {
158  throw new SoapFault('Server', 'The Design Has Already Been Applied To The Asset. Operation Aborted.');
159  }//end if
160  $designs_changed = TRUE;
161 
162  if ($designs_ok) {
163  if ($designs_changed) {
164  if ($update_design_cascade == TRUE) {
165  $assets_affected_lookups[] = $asset->id;
166  }//end if
167  }//end if
168  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
169  }//end if
170 
171  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
172  $update_lookup_result = $asset->updateLookups();
173 
174  if (!$update_lookup_result) {
175  throw new SoapFault('Server', 'Update Lookups For Asset Failed. Try Running Update Lookups Again Another Time');
176  }//end if
177 
178  return Array (
179  'ApplyDesignResult' => $designs_changed,
180  );
181 
182  } else {
183  throw new SoapFault('Server', 'Asset ID is not valid. Please provide a valid Asset ID');
184  }//end else
185 
186  }//end ApplyDesign()
187 
188 
197  private static function getDesignNameFromType($design_type)
198  {
199  $design_name = '';
200  switch ($design_type) {
201  case 'OverrideFrontend':
202  $design_name = 'override::design::system::frontend';
203  break;
204  case 'OverrideLogin':
205  $design_name = 'override::design::system::login';
206  break;
207  case 'OverrideUserDefined':
208  $design_name = 'override::design::user::';
209  break;
210  case 'Frontend':
211  $design_name = 'design::system::frontend';
212  break;
213  case 'Login':
214  $design_name = 'design::system::login';
215  break;
216  case 'UserDefined':
217  $design_name = 'design::user::';
218  break;
219  default:
220  break;
221  }//end switch
222  return $design_name;
223 
224  }//end getDesignNameFromType()
225 
226 
244  function RemoveDesign($request)
245  {
246  $request_info = (Array) $request;
247  $design_id = array_get_index($request_info, 'DesignID', '');
248  $assetid = array_get_index($request_info, 'AssetID', '');
249  $design_type = array_get_index($request_info, 'DesignType', ''); // ( frontend || user-defined || login ) || override
250  $user_defined_design_name = array_get_index($request_info, 'UserDefinedDesignName', '');
251 
252 
253  if (!empty($assetid) && !empty($design_id)) {
254  $asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($assetid);
255  $design = $GLOBALS['SQ_SYSTEM']->am->getAsset($design_id);
256 
257  $design_name = self::getDesignNameFromType($design_type);
258  $designs_ok = TRUE;
259 
260  if (!($design instanceof Design)) {
261  throw new SoapFault('Server', 'The DesignID Provided Does Not Belong To A Design Asset');
262  }//end if
263 
264  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
265  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
266 
267  // Is it not user defined design
268  if (in_array($design_type, Array('OverrideUserDefined', 'UserDefined'))) {
269  $design_name = $design_name.$user_defined_design_name;
270  }//end if
271 
272  $old_design_link = $GLOBALS['SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_NOTICE, 'design', FALSE, $design_name);
273  $old_designid = (empty($old_design_link)) ? 0 : $old_design_link['minorid'];
274 
275  if ($old_designid && $old_designid == $design_id) {
276  if (!$asset->deleteLink($old_design_link['linkid'])) {
277  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
278  $designs_ok = FALSE;
279  break;
280  }//end if
281  } else {
282  throw new SoapFault('Server', 'No Such Design Found For Asset');
283  }//end else
284 
285  if ($designs_ok) {
286  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
287  }//end if
288 
289  $update_lookup_result = $asset->updateLookups();
290 
291  if (!$update_lookup_result) {
292  throw new SoapFault('Server', 'Update Lookups For Asset Failed. Try Running Update Lookups Again Another Time');
293  }//end if
294 
295  return Array (
296  'RemoveDesignResult' => $designs_ok,
297  );
298 
299  } else {
300  throw new SoapFault('Server', 'Asset ID is not valid. Please provide a valid Asset ID');
301  }//end else
302 
303  }//end RemoveDesign()
304 
305 
321  function GetDesignFromURL($request)
322  {
323  $request_info = (Array) $request;
324  $url = array_get_index($request_info, 'URL', '');
325  $design_type = array_get_index($request_info, 'DesignType', ''); // ( frontend || user-defined || login ) || override
326  $user_defined_design_name = array_get_index($request_info, 'UserDefinedDesignName', '');
327 
328  // Design is associated with the domain bit only (i.e. url without protocol)
329  $url = str_replace('http://' , '', $url);
330  $url = str_replace('https://', '', $url);
331 
332  $design_name = self::getDesignNameFromType($design_type);
333  // Is it not user defined design
334  if (in_array($design_type, Array('OverrideUserDefined', 'UserDefined'))) {
335  $design_name = $design_name.$user_defined_design_name;
336  }//end if
337 
338  if (empty($design_name)) {
339  $design_name = 'design::system::frontend';
340  }//end if
341 
342  $designs = $GLOBALS['SQ_SYSTEM']->am->getDesignFromURL($url, $design_name);
343  $design_result = Array (
344  'DesignID' => $designs['designid'],
345  'TypeCode' => $designs['type_code'],
346  );
347 
348  return Array (
349  'GetDesignFromURLResult' => $design_result,
350  );
351 
352  }//end GetDesignFromURL()
353 
354 
370  function ApplyAssetPaintLayout($request)
371  {
372  $request_info = (Array) $request;
373  $paint_layout_id = array_get_index($request_info, 'PaintLayoutID', '');
374  $assetid = array_get_index($request_info, 'AssetID', '');
375  $paint_layout_type = array_get_index($request_info, 'PaintLayoutType', ''); // ( Frontend | OverrideFrontend )
376 
377  if (!empty($assetid)) {
378  $asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($assetid);
379  if (empty($paint_layout_id)) {
380  throw new SoapFault('Server', 'The PaintLayoutID provided is invalid');
381  }//end if
382 
383  $result = self::changePaintLayout($asset, $paint_layout_id, $paint_layout_type);
384 
385  return Array (
386  'ApplyAssetPaintLayoutResult' => $result,
387  );
388 
389  } else {
390  throw new SoapFault('Server', 'The AssetID supplied is either empty or not valid');
391  }//end else
392 
393  }//end ApplyPaintLayout()
394 
395 
411  function RemoveAssetPaintLayout($request)
412  {
413  $request_info = (Array) $request;
414  $paint_layout_id = array_get_index($request_info, 'PaintLayoutID', '');
415  $assetid = array_get_index($request_info, 'AssetID', '');
416  $paint_layout_type = array_get_index($request_info, 'PaintLayoutType', ''); // ( Frontend | OverrideFrontEnd )
417 
418  if (!empty($assetid)) {
419  $asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($assetid);
420  // We should check whether they are telling the truth
421  $paint_layout_end_name = '::system::frontend';
422  $value_name = $paint_layout_type == 'Frontend' ? 'paint_layout' : 'override::paint_layout';
423  $paint_layout_name = $value_name.$paint_layout_end_name;
424  $existing_layout_link = $GLOBALS['SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_NOTICE, 'paint_layout_page', TRUE, $paint_layout_name);
425  if (empty($existing_layout_link) || ($existing_layout_link['minorid'] != $paint_layout_id)) {
426  throw new SoapFault('Server', 'The Asset Does Not Have A PaintLayout Applied With The Provided PaintLayoutID');
427  }//end if
428 
429  $paint_layout_end_name = '::system::frontend';
430  $value_name = $paint_layout_type == 'Frontend' ? 'paint_layout' : 'override::paint_layout';
431  $paint_layout_name = $value_name.$paint_layout_end_name;
432 
433  // All we are going to do in here is to delete the linn, delete lookup value and then run update lookup
434  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
435  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
436  $GLOBALS['SQ_SYSTEM']->am->acquireLock($asset->id, 'all');
437 
438  $layouts_changed = FALSE;
439  $layouts_ok = TRUE;
440  $result = FALSE;
441 
442  // First we are going to get the link
443  $existing_layout_link = $GLOBALS['SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_NOTICE, 'paint_layout_page', TRUE, $paint_layout_name);
444 
445  // If we have hte link, lets delete it
446  if ($existing_layout_link) {
447  if (!$asset->deleteLink($existing_layout_link['linkid'])) {
448  // If unable to delete, lets roll back
449  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
450  $layouts_ok = FALSE;
451  break;
452  } else {
453  $layouts_changed = TRUE;
454  }//end if
455 
456  // also need to delete any other URLs which use the same value
457  // deleting an asset based value means all other URLs which use the same value are also deleted
458  if (!$new_values = $asset->deleteLookupValue($paint_layout_name, $existing_layout_link['minorid'])) {
459  // If we can not delete the lookup value, rollback
460  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
461  $layouts_ok = FALSE;
462  break;
463  }//end if
464  }//end if
465 
466  if ($layouts_ok) {
467  if ($layouts_changed) {
468  if (!$asset->updateLookups()) {
469  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
470  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
471  return FALSE;
472  } else {
473  $result = TRUE;
474  }//end else
475  }//end if
476  }//end if
477 
478  $GLOBALS['SQ_SYSTEM']->am->releaseLock($asset->id, 'all');
479  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
480  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
481 
482  return Array (
483  'RemoveAssetPaintLayoutResult' => $result,
484  );
485  } else {
486  throw new SoapFault('Server', 'The AssetID supplied is either empty or not valid');
487  }//end else
488  }//end RemoveAssetPaintLayout()
489 
490 
501  private static function changePaintLayout($asset, $paint_layout_id, $paint_layout_type)
502  {
503  $paint_layout = NULL;
504  // We are removing asset based paint layout
505  if ($paint_layout_id != 0) {
506  $paint_layout = $GLOBALS['SQ_SYSTEM']->am->getAsset($paint_layout_id);
507  if (!($paint_layout instanceof Paint_Layout_Page)) {
508  throw new SoapFault('Server', 'The PaintLayoutID Provided Does Not Belong To A Paint Layout Page Asset');
509  }//end if
510  }//end if
511 
512  $paint_layout_end_name = '::system::frontend';
513  $value_name = $paint_layout_type == 'Frontend' ? 'paint_layout' : 'override::paint_layout';
514  $paint_layout_name = $value_name.$paint_layout_end_name;
515 
516  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
517  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
518  $GLOBALS['SQ_SYSTEM']->am->acquireLock($asset->id, 'all');
519 
520  $lookup_values = $asset->getLookupValues(FALSE);
521  $existing_layout_link = $GLOBALS['SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_NOTICE, 'paint_layout_page', TRUE, $paint_layout_name);
522  $layouts_changed = FALSE;
523  $layouts_ok = TRUE;
524  $values = Array (
525  'asset' => Array (
526  'paint_layout' => Array (
527  'value' => '',
528  ),
529  'override::paint_layout' => Array (
530  'value' => '',
531  ),
532  ),
533  );
534 
535  $create_new = $delete_existing = FALSE;
536  if (empty($existing_layout_link)) {
537  $create_new = TRUE;
538  // We are creating new layout notice link
539  } else if ($existing_layout_link['minorid'] !== $paint_layout_id) {
540  $delete_existing = TRUE;
541  $create_new = TRUE;
542  }//end else
543 
544  if ($delete_existing) {
545  if ($existing_layout_link) {
546  if (!$asset->deleteLink($existing_layout_link['linkid'])) {
547  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
548  $layouts_ok = FALSE;
549  break;
550  } else {
551  $layouts_changed = TRUE;
552  }//end if
553 
554  // also need to delete any other URLs which use the same value
555  // deleting an asset based value means all other URLs which use the same value are also deleted
556  if (!$new_values = $asset->deleteLookupValue($paint_layout_name, $existing_layout_link['minorid'])) {
557  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
558  $layouts_ok = FALSE;
559  break;
560  } else {
561  $lookup_values = $new_values;
562  unset($new_values);
563  }//end if
564  }//end if
565  }//end if
566 
567  if ($create_new) {
568  // create new notice link
569  if (is_null($paint_layout)) {
570  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
571  $layouts_ok = FALSE;
572  } else if (!$asset->createLink($paint_layout, SQ_LINK_NOTICE, $paint_layout_name)) {
573  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
574  $layouts_ok = FALSE;
575  break;
576  } else {
577  $layouts_changed = TRUE;
578  }//end else
579  }//end if
580  // delete if no value
581 
582  if (empty($paint_layout_id)) {
583  if (isset($lookup_values['asset'][$paint_layout_name])) {
584  unset($lookup_values['asset'][$paint_layout_name]);
585  }//end if
586 
587  // if value is deleted, run updateLookups() so the asset based definition can take effect if there is one defined
588  $layouts_changed = TRUE;
589  } else {
590  if (!isset($lookup_values['asset'])) {
591  $lookup_values['asset'] = Array();
592  }//end if
593  $lookup_values['asset'][$value_name] = Array('value' => $paint_layout_id);
594  }//end else
595 
596  if (!$asset->setLookupValues($lookup_values)) {
597  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
598  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
599  return FALSE;
600  }//end if
601 
602  if ($layouts_ok) {
603  if ($layouts_changed) {
604  if (!$asset->updateLookups()) {
605  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
606  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
607  return FALSE;
608  }//end if
609  }//end if
610  }//end if
611 
612  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
613  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
614  $GLOBALS['SQ_SYSTEM']->am->releaseLock($asset->id, 'all');
615 
616  return TRUE;
617 
618  }//end changePaintLayout()
619 
620 
627  public static function getComplexElements($func_list=Array())
628  {
629  $obj_optional = self::getArgType('AssetObject', 0, 1);
630  $design_link_summary = self::getArgType('DesignLinkSummary', 0, 1);
631 
632  $complex_types = Array (
633  'ApplyDesign' => Array (
634  'ApplyDesign' => Array (
635  'DesignID' => self::$string_non_optional,
636  'AssetID' => self::$string_non_optional,
637  'DesignType' => self::$string_non_optional,
638  'UserDefinedDesignName' => self::$string_optional,
639  ),
640  'ApplyDesignResponse' => Array (
641  'ApplyDesignResult' => self::$boolean_optional,
642  ),
643  ),
644  'RemoveDesign' => Array (
645  'RemoveDesign' => Array (
646  'DesignID' => self::$string_non_optional,
647  'AssetID' => self::$string_non_optional,
648  'DesignType' => self::$string_optional,
649  'UserDefinedDesignName' => self::$string_optional,
650  ),
651  'RemoveDesignResponse' => Array (
652  'RemoveDesignResult' => self::$boolean_optional,
653  ),
654  ),
655  'GetDesignFromURL' => Array (
656  'GetDesignFromURL' => Array (
657  'URL' => self::$string_non_optional,
658  'DesignType' => self::$string_optional,
659  'UserDefinedDesignName' => self::$string_optional,
660  ),
661  'GetDesignFromURLResponse' => Array (
662  'GetDesignFromURLResult' => $design_link_summary,
663  ),
664  ),
665  'ApplyAssetPaintLayout' => Array (
666  'ApplyAssetPaintLayout' => Array (
667  'PaintLayoutID' => self::$string_non_optional,
668  'AssetID' => self::$string_optional,
669  'PaintLayoutType' => self::$string_non_optional,
670  ),
671 
672  'ApplyAssetPaintLayoutResponse' => Array (
673  'ApplyAssetPaintLayoutResult' => self::$boolean_optional,
674  ),
675  ),
676  'RemoveAssetPaintLayout' => Array (
677  'RemoveAssetPaintLayout' => Array (
678  'PaintLayoutID' => self::$string_non_optional,
679  'AssetID' => self::$string_optional,
680  'PaintLayoutType' => self::$string_non_optional,
681  ),
682 
683  'RemoveAssetPaintLayoutResponse' => Array (
684  'RemoveAssetPaintLayoutResult' => self::$boolean_optional,
685  ),
686  ),
687 
688  'ApplyURLPaintLayout' => Array (
689  'ApplyURLPaintLayout' => Array (
690 
691  ),
692 
693  'ApplyURLPaintLayoutResponse' => Array (
694  'ApplyURLPaintLayoutResult' => self::$boolean_optional,
695  ),
696  ),
697  );
698 
699  $complex_types_available = parent::getComplexElements($complex_types);
700 
701  return $complex_types_available;
702 
703  }//end getComplexTypes();
704 
705 
712  public static function getComplexTypes($func_list=Array())
713  {
714  $complex_types = Array (
715  'GetDesignFromURL' => Array (
716  'DesignLinkSummary' => Array (
717  'DesignID' => self::$string_non_optional,
718  'TypeCode' => self::$string_optional,
719  ),
720  ),
721  );
722 
723  $complex_types_available = parent::getComplexElements($complex_types);
724 
725  return $complex_types_available;
726 
727  }//end getComplexTypes()
728 
729 
736  public static function getSimpleRestrictedTypes($func_list=Array())
737  {
738  $design_type = Array (
739  'restriction_base' => 'string',
740  'enumeration' => Array (
741  'Frontend', 'OverrideFrontend', 'Login', 'OverrideLogin', 'UserDefined', 'OverrideUserDefined',
742  ),
743  );
744 
745  $simple_restricted_types = Array (
746  'ApplyDesign' => Array (
747  'DesignType' => $design_type,
748  ),
749  'RemoveDesign' => Array (
750  'DesignType' => $design_type,
751  ),
752  'GetDesignFromURL' => Array (
753  'DesignType' => $design_type,
754  ),
755  );
756 
757  $simple_restricted_types_available = parent::getSimpleRestrictedTypes($simple_restricted_types);
758 
759  return $simple_restricted_types_available;
760 
761  }//end getSimpleRestrictedTypes()
762 
763 
764 }//end class
765 ?>