53 var $description =
'';
59 var $_params = Array();
65 var $_default_value = NULL;
71 var $_edit_params = Array();
83 var $processed = FALSE;
89 var $is_admin = FALSE;
107 $sql =
'SELECT attrid, name, type, uniq, description, is_admin, parameters_val, default_val
109 WHERE attrid = :attrid';
115 if (empty($result)) {
121 }
catch (Exception $e) {
122 throw new Exception(
'Unable to get information for attribute ID '.$attributeid.
' due to database error: '.$e->getMessage());
125 $this->
id = $row[
'attrid'];
126 $this->name = $row[
'name'];
127 $type = $row[
'type'];
128 $this->uniq = $row[
'uniq'];
129 $this->description = $row[
'description'];
130 $this->is_admin = $row[
'is_admin'];
131 $parameters = $row[
'parameters_val'];
132 $this->_default_value = $row[
'default_val'];
135 if ($type != $this->
type()) {
136 throw new Exception(
'Attribute type mismatch. Attribute ID '.$attributeid.
' was created as a "'.$this->type().
'" attribute but the database believes it is a "'.$type.
'" attribute.');
141 $this->_params = ($parameters) ? unserialize($parameters) : Array();
146 $this->value = $value;
149 foreach ($default_params as $name => $default) {
150 if (!isset($this->_params[$name])) {
151 $this->_params[$name] = $default;
169 function &
loadAttribute($attributeid=0, $value=NULL, $default_params=Array())
171 if ($attributeid == 0) {
178 $sql =
'SELECT type FROM sq_ast_attr
179 WHERE attrid = :attrid';
184 }
catch (Exception $e) {
185 throw new Exception(
'Unable to load attribute ID #'.$attributeid.
' due to database error: '.$e->getMessage());
188 $class =
'Asset_Attribute_'.$type;
189 require_once SQ_ATTRIBUTES_PATH.
'/'.$type.
'/'.$type.
'.inc';
190 $attr =
new $class($attributeid, $value, $default_params);
207 return strtolower(substr(get_class($this), 16));
221 function paint($prefix, $read_only=FALSE)
223 echo translate(
'interface_not_created', ucwords(str_replace(
'_',
' ', $this->
type())));
273 $this->processed = FALSE;
308 trigger_localised_error(
'SYS0073', E_USER_WARNING, $value, $this->
type());
311 $this->value = $value;
329 if (strtolower($node->getName()) != strtolower($this->
type())) {
330 trigger_localised_error(
'SYS0300', E_USER_WARNING, $node->getName(), $this->
type(),
'<pre>'.htmlspecialchars($node->asXml()).
'</pre>');
352 if (isset($this->_edit_params[$field])) {
353 $this->_edit_params[$field] = $value;
356 trigger_localised_error(
'SYS0258', E_USER_NOTICE, $field, $this->
type());
377 if (isset($this->_params[$field])) {
378 $this->_params[$field] = $value;
381 trigger_localised_error(
'SYS0258', E_USER_NOTICE, $field, $this->
type());
411 if ($format !==
'')
return '';
427 $tag_attributes =
'name="'.$this->name.
'" ';
428 $tag_attributes .=
'id="'.$this->id.
'" ';
429 $tag_attributes .=
'uniq="'.$this->uniq.
'" ';
430 $tag_attributes .=
'description="'.$this->description.
'" ';
431 $tag_attributes .=
'default_value="'.$this->_default_value.
'" ';
432 $tag_attributes .=
'processed="'.$this->processed.
'" ';
433 $tag_attributes .=
'is_admin="'.$this->is_admin.
'" ';
435 $open_tag =
'<'.$this->type().
' '.$tag_attributes.
'>';
436 $close_tag =
'</'.$this->type().
'>';
440 $xml = $open_tag.$contents.$close_tag;
457 $xml =
'<value><![CDATA['.$this->getContent().
']]></value>';