Exemple #1
0
 /**
  * {@inheritDoc}
  */
 public function getBranch($pk = null, Condition $condition = null, $depth = 1, $scope = null, $options = null)
 {
     $result = null;
     if (!$pk || !$pk['path']) {
         return [['path' => '/', 'title' => 'Admin Access']];
     } else {
         if ('/' == $pk['path']) {
             foreach ($this->jarves->getBundles() as $bundle) {
                 $item = array('path' => $bundle->getName(), 'title' => $bundle->getName());
                 $this->setChildren(strtolower($bundle->getName()), $item, $depth);
                 $result[] = $item;
             }
         } else {
             self::normalizePath($pk['path']);
             $adminUtils = new \Jarves\Admin\Utils($this->jarves);
             $entryPoint = $adminUtils->getEntryPoint($pk['path']);
             if ($entryPoint && $entryPoint->getChildren()) {
                 foreach ($entryPoint->getChildren() as $entryPoint) {
                     $item = array('path' => $pk['path'] . '/' . $entryPoint->getPath(), 'type' => $entryPoint->getType(), 'title' => $entryPoint->getLabel() ? $entryPoint->getLabel() : $entryPoint->getPath());
                     $this->setChildren($pk['path'] . '/' . $entryPoint->getPath(), $item, $depth);
                     $result[] = $item;
                 }
             }
         }
     }
     return $result;
 }
Exemple #2
0
 public function handle(ApiDoc $annotation, array $annotations, Route $route, \ReflectionMethod $method)
 {
     if (!($objectName = $route->getDefault('_jarves_object')) || !($object = $this->objects->getDefinition($objectName))) {
         return;
     }
     if ($entryPointPath = $route->getDefault('_jarves_entry_point')) {
         $adminUtils = new \Jarves\Admin\Utils($this->jarves);
         $entryPoint = $adminUtils->getEntryPoint($entryPointPath);
         $annotation->setSection(sprintf('%s %s %s', $entryPoint->isFrameworkWindow() ? 'Framework Window: ' : '', $entryPoint->getBundle() ? ($entryPoint->getBundle()->getLabel() ?: $entryPoint->getBundle()->getBundleName()) . ', ' : 'No Bundle, ', $entryPoint->getLabel() ?: $entryPoint->getPath()));
     } else {
         $objectKey = $route->getDefault('_jarves_object_section') ?: $route->getDefault('_jarves_object');
         $objectSection = $this->objects->getDefinition($objectKey);
         $annotation->setSection(sprintf('Object %s', $objectKey));
     }
     $filters = $annotation->getFilters();
     if (@$filters['fields']) {
         $fields = [];
         foreach ($object->getFields() as $field) {
             if ('object' === $field->getId()) {
                 $foreignObject = $this->objects->getDefinition($field->getObject());
                 foreach ($foreignObject->getFields() as $fField) {
                     $filters[] = $field->getId() . '.' . $fField->getId();
                 }
             } else {
                 $fields[] = $field->getId();
             }
         }
         $annotation->addFilter('fields', ['requirement' => '.*', 'description' => "Comma separated list of fields. Possible fields to select: \n" . implode(', ', $fields)]);
     }
     $annotation->setDescription(str_replace('%object%', $object->getBundle()->getBundleName() . ':' . lcfirst($object->getId()), $annotation->getDescription()));
     $isRelationRoute = $route->getDefault('_jarves_object_relation');
     $requirePk = $route->getDefault('_jarves_object_requirePk');
     $method = explode(':', $route->getDefault('_controller'))[1];
     //        maybe in version 1.1
     //        if ($isRelationRoute) {
     //            $objectKey = $route->getDefault('_jarves_object_section') ? : $route->getDefault('_jarves_object');
     //            $objectParent = $this->jarves->getObjects()->getDefinition($objectKey);
     //
     //            foreach ($objectParent->getFields() as $field) {
     //                if ($field->isPrimaryKey()) {
     //                    $annotation->addRequirement(
     //                        $field->getId(),
     //                        [
     //                            'requirement' => $field->getRequiredRegex(),
     //                            'dataType' => $field->getPhpDataType(),
     //                            'description' => '(' . $objectParent->getId() . ') ' . $field->getDescription()
     //                        ]
     //                    );
     //                }
     //            }
     //        }
     if ($requirePk) {
         foreach ($object->getFields() as $field) {
             if (!$field->hasFieldType()) {
                 continue;
             }
             if ($field->isPrimaryKey()) {
                 $annotation->addRequirement(($isRelationRoute ? lcfirst($object->getId()) . '_' : '') . $field->getId(), ['requirement' => $field->getRequiredRegex(), 'dataType' => $field->getPhpDataType(), 'description' => $isRelationRoute ? '(' . $object->getId() . ') ' : '']);
             }
         }
     }
     //add all fields to some actions
     if (in_array($method, ['addItemAction', 'patchItemAction', 'updateItemAction'])) {
         foreach ($object->getFields() as $field) {
             if (!$field->hasFieldType()) {
                 continue;
             }
             if ($field->isRequired() && !$field->getDefault()) {
                 $annotation->addRequirement($field->getId(), array('requirement' => $field->getRequiredRegex(), 'dataType' => $field->getPhpDataType(), 'description' => ($isRelationRoute ? '(' . $object->getId() . ') ' : '') . $field->getLabel()));
             } else {
                 $annotation->addParameter($field->getId(), array('format' => $field->getRequiredRegex(), 'dataType' => $field->getPhpDataType(), 'default' => $field->getDefault(), 'description' => $field->getLabel() . ($field->isAutoIncrement() ? ' (autoIncremented)' : ''), 'readonly' => false, 'required' => false));
             }
         }
     }
 }