public function getRelation($filterContentType = null, $options = [])
{
if (empty($this->relation)) {
return false;
// nothing to do here.
}
// Backwards compatibility: If '$options' is a string, assume we passed an id
if (!is_array($options)) {
$options = ['id' => $options];
}
$records = [];
foreach ($this->relation as $contenttype => $ids) {
if (!empty($filterContentType) && $contenttype != $filterContentType) {
continue;
// Skip other contenttypes, if we requested a specific type.
}
$params = ['hydrate' => true];
$where = ['id' => implode(' || ', $ids)];
$dummy = false;
// If there were other options add them to the 'where'. We potentially overwrite the 'id' here.
if (!empty($options)) {
foreach ($options as $option => $value) {
$where[$option] = $value;
}
}
// Only get published items, unless specifically stated otherwise.
if (!isset($where['status'])) {
$where['status'] = 'published';
}
$tempResult = $this->app['storage']->getContent($contenttype, $params, $dummy, $where);
if (empty($tempResult)) {
continue;
// Go ahead if content not found.
}
// Variable $temp_result can be an array of object.
if (is_array($tempResult)) {
$records = array_merge($records, $tempResult);
} else {
$records[] = $tempResult;
}
}
return $records;
}