/** inheritdoc */ public static function displayList($value, $edit_link, &$settings, &$model) { $target_class = $settings['mapping']['targetEntity']; $target_table = \Admin::getTableForClass($target_class); if ($value instanceof \Doctrine\Common\Collections\Collection && count($value) > 0) { return \Html::anchor("/admin/{$target_table}", count($value) . ' »'); } else { return '0'; } }
/** inheritdoc */ public static function displayList($value, $edit_link, &$settings, &$model) { $target_class = $settings['mapping']['targetEntity']; $target_table = \Admin::getTableForClass($target_class); if ($value instanceof \Doctrine\Common\Collections\Collection && count($value) > 0) { $values = $value->toArray(); $output = ''; foreach ($values as $val) { $output .= \Html::anchor("/admin/{$target_table}/" . $val->id . "/edit", $val->display()) . ', '; } return rtrim($output, ', '); } else { return '-'; } }
protected function processItem(&$entity, $delete = false) { if (!empty($entity)) { if (!empty($entity->settings) && isset($entity->settings['original_id']) && $entity->settings['original_id'] > 0) { $tableName = \Admin::getTableForClass($entity->getEntityClass()); if (empty($this->jsonObject)) { $this->jsonObject = new \stdClass(); $this->jsonObject->data = new \stdClass(); } if (empty($this->jsonObject->data->{$tableName})) { $this->jsonObject->data->{$tableName} = array(); } $object = $entity->jsonLanguageDataObject($delete); if (!in_array($object, $this->jsonObject->data->{$tableName})) { $this->jsonObject->data->{$tableName}[] = $object; } } } }
protected function buildSingleResult($entity, &$results) { $root_type = $this->root; // Get metadata for this result $resultClass = get_class($entity); $resultMeta = $resultClass::metadata(); $resultClass = $resultMeta->name; $field_list = $this->getFieldsForModel($resultClass); $associations = array_intersect($field_list, $resultMeta->getAssociationNames()); $fields = array_intersect($field_list, $resultMeta->getFieldNames()); $entity->__original_url_canonical = !empty($entity->url) && $entity->url instanceof \CMF\Model\URL ? rtrim(\Uri::base(false), '/') . '/' . ltrim($entity->url->url, '/') : ""; // Create a simple array version of the result $output = $entity->toArray($fields); $output_type = $resultMeta->name; $output_id = $entity->id; $this->addDiscriminator($entity, $output); // Put the associations into their respective sideloaded arrays foreach ($associations as $assoc) { $assoc_class = $resultMeta->getAssociationTargetClass($assoc); $type = \Inflector::pluralize(\Admin::getTableForClass($assoc_class)); if (!isset($this->output['included'][$type])) { $this->output['included'][$type] = array(); } if ($resultMeta->isCollectionValuedAssociation($assoc)) { $output[$assoc] = array('ids' => array(), 'type' => $type, 'href' => \Uri::base(false) . "api/{$root_type}/{$output_id}/{$assoc}"); if (empty($entity->{$assoc})) { continue; } foreach ($entity->{$assoc} as $assoc_value) { $assoc_id = $assoc_value->id; $output[$assoc]['ids'][] = $assoc_id; if (!isset($this->output['included'][$type][$assoc_id]) && !($type == $this->root && (isset($this->output[$this->rootOutput][$assoc_id]) || $this->entityInResultSet($assoc_value, $results)))) { $this->output['included'][$type][$assoc_id] = array(); $this->output['included'][$type][$assoc_id] = $this->buildSingleResult($assoc_value, $results); } } } else { if (empty($entity->{$assoc})) { $output[$assoc] = null; continue; } $assoc_id = $entity->{$assoc}->id; $output[$assoc] = array('id' => $assoc_id, 'type' => $type, 'href' => \Uri::base(false) . "api/{$type}/{$assoc_id}"); if (!isset($this->output['included'][$type][$assoc_id]) && !($type == $this->root && (isset($this->output[$this->rootOutput][$assoc_id]) || $this->entityInResultSet($entity->{$assoc}, $results)))) { $this->output['included'][$type][$assoc_id] = array(); $this->output['included'][$type][$assoc_id] = $this->buildSingleResult($entity->{$assoc}, $results); } } } return $output; }
/** * @see \CMF\Model\Base::$_import_type * @return string */ public static function importType() { $called_class = get_called_class(); if (empty($called_class::$_import_type)) { return \Admin::getTableForClass($called_class); } return $called_class::$_import_type; }