*/ 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_Leading 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); } $list = $this->kvp->get($id, true); // simple list without merging if (empty($params['parent']) || in_array($params['parent'], $id)) { foreach ($list as $j => &$l) { $l['parentvalue'] = ''; $l['class'] = ''; } return $list; } // remove duplicates $pList = $this->kvp->get($params['parent'], true); $found = array(); foreach ($pList as $pk => &$pv) { $pv['parentvalue'] = ''; $pv['class'] = ''; foreach ($list as $lk => &$lv) { if ($lv['key'] == $pv['key']) { $found[] = $lk; $lv['parentvalue'] = $pv['value']; $lv['class'] = 'merged'; unset($pList[$pk]); break; } if (!in_array($lk, $found)) { $lv['parentvalue'] = ''; $lv['class'] = 'added'; } } } $pList = array_values($pList); return array_merge($list, $pList); } }