Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
promotional_code_edit_fns.inc
1 <?php
18 require_once SQ_INCLUDE_PATH.'/asset_edit/asset_edit_fns.inc';
19 
32 {
33 
34 
38  function __construct()
39  {
40  parent::__construct();
41  $this->static_screens['details']['force_unlock'] = FALSE;
42 
43  }//end constructor
44 
45 
56  function paintAppliedAssets(&$asset, &$o, $prefix)
57  {
58  $link_value = $asset->attr('code');
59 
60  return $this->paintNoticeLinkedAsset($asset, $link_value, Array('asset' => 'D'), 'applied_assets', TRUE);
61 
62  }//end paintAppliedAssets()
63 
64 
75  function processAppliedAssets(&$asset, &$o, $prefix)
76  {
77  // The 'code' attribute value might be changed already, so we will try to get the old value
78  $link_value = $asset->getOldAttrValue('code');
79 
80  return $this->processNoticeLinkedAsset($asset, $link_value, 'applied_assets', TRUE);
81 
82  }//end processAppliedAssets()
83 
84 
95  function paintRules(&$asset, &$o, $prefix)
96  {
97  $rules = $asset->attr('rules');
98  if (empty($rules)) {
99  $rules[] = Array('rule_type_code' => 'promotional_rule_type_quantity', 'rule_data' => NULL);
100  }
101 
102  $am = $GLOBALS['SQ_SYSTEM']->am;
103  $write_access = $asset->writeAccess('attributes');
104 
105  for ($i = 0; $i < count($rules); $i++) {
106  $rule = $rules[$i];
107  $rule_type_code = $rule['rule_type_code'];
108  $am->includeAsset($rule_type_code);
109  $rule_asset = new $rule_type_code();
110  $rule_edit_fns = $rule_asset->getEditFns();
111 
112  // Paint each promotional rule in a section
113  $o->openSection($am->getTypeInfo($rule_type_code, 'name'));
114  $rule_edit_fns->paintRule($rule_asset, $o, $prefix.'_rule_'.$i, $rule['rule_data'], $write_access);
115  $o->closeSection();
116  }
117 
118  }//end paintRules()
119 
120 
131  function processRules(&$asset, &$o, $prefix)
132  {
133  if (!$asset->writeAccess('attributes')) return FALSE;
134 
135  $rules = $asset->attr('rules');
136  if (empty($rules)) {
137  $rules[] = Array('rule_type_code' => 'promotional_rule_type_quantity', 'rule_data' => NULL);
138  }
139 
140  $success = TRUE;
141  for ($i = 0; $i < count($rules); $i++) {
142  $rule =& $rules[$i];
143  $rule_type_code = $rule['rule_type_code'];
144  $GLOBALS['SQ_SYSTEM']->am->includeAsset($rule_type_code);
145  $rule_asset = new $rule_type_code();
146  $rule_edit_fns = $rule_asset->getEditFns();
147 
148  if (!$rule_edit_fns->processRule($rule_asset, $o, $prefix.'_rule_'.$i, $rule['rule_data'])) {
149  $success = FALSE;
150  break;
151  }
152  }
153 
154  return $success && $asset->setAttrValue('rules', $rules);
155 
156  }//end processRules()
157 
158 
159 }//end class
160 
161 ?>