18 require_once dirname(__FILE__).
'/../../metadata_field/metadata_field.inc';
43 parent::__construct($assetid);
56 require_once SQ_ATTRIBUTES_PATH.
'/selection/selection.inc';
59 $edit_params = $this->
attr(
'edit_params');
60 if (!empty($edit_params)) {
61 $selection->_edit_params = array_merge($selection->_edit_params, $edit_params);
65 $selection->_params[
'multiple'] = $this->
attr(
'multiple');
66 $selection->_params[
'allow_empty'] = $this->
attr(
'allow_empty');
67 $selection->_params[
'sort'] = $this->
attr(
'hier_sort');
68 $selection->_params[
'structure'] = $this->
attr(
'hier_structure');
70 $default = explode(
'; ', $this->
attr(
'default'));
71 if ($selection->validateValue($default)) {
72 $selection->setValue($default);
73 $selection->_default_value = $default;
97 if ($this->
attr(
'visible_part') ===
'value') {
100 return str_replace(
'\\;',
';', parent::getMetadataValue($asset, $value_str));
116 $option_keys = explode(
'; ', $option_str);
117 if (empty($option_keys))
return $option_str;
122 foreach ($option_keys as $key) {
123 $key = str_replace(
'\\',
'', $key);
124 if (isset($options[$key])) {
125 $value_str .= $options[$key].
'; ';
128 if (strlen($value_str) == 0) {
134 $value_str = substr($value_str, 0, -2);
160 if (array_key_exists(
'cached_hierarchy_options', $this->_tmp) === FALSE) {
161 $this->_tmp[
'cached_hierarchy_options'] = Array();
164 $contextid = $GLOBALS[
'SQ_SYSTEM']->getContextId();
166 if ($contextid === 0) {
169 return $this->
attr(
'hierarchy_options');
172 if (array_key_exists($contextid, $this->_tmp[
'cached_hierarchy_options']) === FALSE) {
174 $hierarchy_options = $this->
attr(
'hierarchy_options');
178 $default_options = $GLOBALS[
'SQ_SYSTEM']->am->getAttributeValuesByName(
'hierarchy_options',
'metadata_field_hierarchy', Array($this->
id), 0);
179 $default_options = unserialize($default_options[$this->
id]);
182 foreach ($hierarchy_options as $hierarchy_key => $hierarchy_value) {
183 if (array_key_exists($hierarchy_key, $default_options) === FALSE) {
184 unset($hierarchy_options[$hierarchy_key]);
190 foreach ($default_options as $default_key => &$default_value) {
191 if (array_key_exists($default_key, $hierarchy_options) === FALSE) {
192 $hierarchy_options[$default_key] = $default_value;
196 $this->_tmp[
'cached_hierarchy_options'][$contextid] = $hierarchy_options;
199 return $this->_tmp[
'cached_hierarchy_options'][$contextid];
218 if (array_key_exists(
'cached_hierarchy_options', $this->_tmp) === TRUE) {
219 $contextid = $GLOBALS[
'SQ_SYSTEM']->getContextId();
221 if ($contextid === 0) {
222 $this->_tmp[
'cached_hierarchy_options'] = Array();
224 if (array_key_exists($contextid, $this->_tmp[
'cached_hierarchy_options']) === TRUE) {
225 unset($this->_tmp[
'cached_hierarchy_options'][$contextid]);
244 $option_keys = explode(
'; ', $option_str);
245 if (empty($option_keys))
return $option_keys;
248 $options = $this->
attr(
'hierarchy_options');
250 foreach ($option_keys as $key) {
251 $key = str_replace(
'\\',
'', $key);
252 foreach($options as $index => $element) {
253 if ($index === $key) {
254 $value_str .= $element.
'\\; ';
258 if (strlen($value_str) == 0) {
264 $value_str = substr($value_str, 0, -3);
296 if ($contextid === NULL) {
297 $contextid = $GLOBALS[
'SQ_SYSTEM']->getContextId();
300 switch ($additional_keyword) {
312 $sql =
'SELECT value FROM '.SQ_TABLE_RUNNING_PREFIX.
'ast_mdata_val ';
313 $where =
'assetid = :host_assetid AND fieldid = :fieldid AND contextid = :contextid';
314 $where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($where);
318 $sub_sql =
'SELECT fieldid, contextid FROM '.SQ_TABLE_RUNNING_PREFIX.
'ast_mdata_val ';
319 $sub_where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause(
'',
'ast_mdata_val');
321 $union_sql =
'SELECT default_val FROM '.SQ_TABLE_RUNNING_PREFIX.
'ast_mdata_dflt_val';
322 $union_where =
'%tuple_keyword%(assetid, contextid) NOT IN ('.$sub_sql.$sub_where.
') AND assetid = :fieldid_1 AND contextid = :contextid_1';
323 $union_where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($union_where,
'ast_mdata_dflt_val');
327 $union_where = str_replace(
'%tuple_keyword%',
'', $union_where);
329 $union_where = str_replace(
'%tuple_keyword%',
'ROW', $union_where);
331 $union_sql .= $union_where;
332 $sql =
'('.$sql.
') UNION ALL ('.$union_sql.
')';
336 'host_assetid' => (
string)$host_assetid,
337 'fieldid' => (
string)$this->
id,
338 'contextid' => (
int)$contextid,
339 'fieldid_1' => (
string)$this->
id,
340 'contextid_1' => (
int)$contextid,
344 foreach ($bind_vars as $bind_var => $bind_value) {
351 if ($key !== FALSE) {
352 if ($additional_keyword ===
'key') {
354 }
else if ($additional_keyword ===
'value') {
364 if (is_null($replacement)){
368 $value_components = $this->
attr(
'value_components');