Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
assetid.inc
1 <?php
18 require_once SQ_INCLUDE_PATH.'/asset_attribute.inc';
19 
37 {
38 
39 
47  function Asset_Attribute_Assetid($attributeid=0, $value=NULL)
48  {
49  $this->Asset_Attribute($attributeid, $value);
50  $this->_edit_params['type_codes'] = Array();
51 
52  // default values
53  $this->_edit_params['type_codes'] = Array();
54 
55  }//end constructor
56 
57 
67  function setEditParams(&$node)
68  {
69  if (!parent::setEditParams($node)) return FALSE;
70 
71  $this->_edit_params['type_codes'] = Array();
72  if (isset($node->attributes()->type_codes)) {
73  $codes = explode(',', (string)$node->attributes()->type_codes);
74  foreach ($codes as $code_name) {
75  list($code, $flag) = explode(':', $code_name);
76  $this->_edit_params['type_codes'][$code] = $flag;
77  }
78  }
79 
80  return TRUE;
81 
82  }//end setEditParams()
83 
84 
94  function paint($prefix, $read_only=FALSE)
95  {
96  if ($read_only) {
97  if (!$this->value) {
98  echo translate('no_asset_selected');
99  } else {
100  echo get_asset_tag_line($this->value);
101  }
102  return;
103  }
104 
105  require_once SQ_LIB_PATH.'/html_form/html_form.inc';
106  asset_finder($prefix, $this->value, $this->_edit_params['type_codes']);
107 
108  }//end paint()
109 
110 
119  function process($prefix)
120  {
121  $type_code_flag = TRUE;
122  if (!isset($_REQUEST[$prefix]['assetid'])) {
123  return FALSE;
124  }
125  $value = $_REQUEST[$prefix]['assetid'];
126  if ($value != 0) {
127  $type_code_flag = empty($this->_edit_params['type_codes']) ? TRUE : FALSE;
128  $value_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($value);
129  foreach ($this->_edit_params['type_codes'] as $type_accepted => $inheritance) {
130  if ($value_asset instanceof $type_accepted) {
131  $type_code_flag = TRUE;
132  break;
133  }
134  }
135  }
136 
137  if (!$type_code_flag) {
138  $this->processed = FALSE;
139  return $type_code_flag;
140  }
141  if ($this->value != $value && $this->setValue($value)) {
142  $this->processed = TRUE;
143  } else {
144  $this->processed = FALSE;
145  }
146 
147  }//end process()
148 
149 
158  function validateValue(&$value)
159  {
160  if ($value) {
161  $error_msg = translate('fail_setting_assetid', $this->name, $this->id);
162  if (!assert_valid_assetid($value, $error_msg, TRUE, FALSE)) {
163  return FALSE;
164  }
165  $asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($value);
166  if (is_null($asset)) return FALSE;
167  }
168  return TRUE;
169 
170  }//end validateValue()
171 
172 
173 }//end class
174 
175 ?>