*/ WBClass::load('WBDatasource_KeyValuePair_ListMerger'); /** * Key-Value-Pair List Merger: Ordered * * MerĒµing strategy * * @version 1.0.0 * @package WB * @subpackage keyvaluepair * @author gERD Schaufelberger */ class WBDatasource_KeyValuePair_ListMerger_Ordered extends WBDatasource_KeyValuePair_ListMerger { /** * Get List * * @param string|array $id * @param array $params * @return array */ public function get($id, $params = array()) { if (!is_array($id)) { $id = array($id); } if (!empty($params['parent']) && !in_array($params['parent'], $id)) { $id[] = $params['parent']; } $list = $this->kvp->get($id, true); // simple list without merging if (1 == count($id)) { foreach ($list as $j => &$c) { $c['parentvalue'] = ''; $c['class'] = ''; } return $list; } // merge list $merged = array(); foreach ($list as $i => &$l) { if ($id[1] == $l['id']) { foreach ($list as $j => &$c) { if ($id[0] == $c['id'] && $c['key'] == $l['key']) { $c['parentvalue'] = $l['value']; $c['class'] = 'merged'; $merged[] = $c['key']; unset($list[$i]); break; } } $l['parentvalue'] = ''; $l['class'] = ''; } else if (!in_array($l['key'], $merged)) { $l['class'] = 'added'; } } return array_values($list); } }