public function getChildren($object, CollectionInterface $collection) { $config = $collection->getConfig(); if (empty($config['is_child'])) { throw new \Exception('wrong config'); } if (isset($object['children'])) { return $object['children']; } return array(); }
/** * * @param mixed $object * @param CollectionInterface $config * @return array */ public function getChildren($object, CollectionInterface $collection) { $config = $collection->getConfig(); if (empty($config['parentfield'])) { throw new \midcom_error('parentfield was not defined in config'); } $parentfield = $config['parentfield']; // if storage is not defined, we assume it's the same as object if (empty($config['storage'])) { $storage = get_class($object); } else { $storage = $config['storage']; } $reflector = new \midgard_reflection_property(\midcom_helper_reflector::resolve_baseclass($storage)); if (!$reflector->is_link($parentfield)) { throw new \midcom_error('could not determine storage class'); } $qb = call_user_func(array($storage, 'new_query_builder')); $qb->add_constraint($parentfield, '=', $object->id); // order the children by their score values $qb->add_order('score', 'ASC'); return $qb->execute(); }