getNested() public method

public getNested ( ) : boolean
return boolean
Esempio n. 1
0
 /**
  * @param bool $withoutObjectCheck
  *
  * @throws ObjectNotFoundException
  */
 public function initialize($withoutObjectCheck = false)
 {
     if ($this->objectDefinition) {
         return;
     }
     if (!$this->getObject()) {
         return;
     }
     $this->objectDefinition = $this->objects->getDefinition($this->getObject());
     if (!$this->objectDefinition && $this->getObject() && !$withoutObjectCheck) {
         throw new ObjectNotFoundException("Can not find object '" . $this->getObject() . "'");
     }
     if ($this->objectDefinition) {
         if ($apiControllerDefinition = $this->objectDefinition->getApiControllerDefinition()) {
             $path = $this->jarves->resolvePath($apiControllerDefinition);
             $definitionContent = file_get_contents($path);
             $yaml = new Parser();
             $parsedDefinition = $yaml->parse($definitionContent);
             if ($parsedDefinition) {
                 foreach ($parsedDefinition as $key => $val) {
                     $setter = 'set' . ucfirst($key);
                     if (method_exists($this, $setter)) {
                         $this->{$setter}($val);
                     }
                 }
             }
         }
         $this->asNested = $this->objectDefinition->getNested();
         if (!$this->table) {
             $this->table = $this->objectDefinition->getTable();
         }
         if (!$this->fields) {
             $this->fields = [];
             foreach ($this->objectDefinition->getFields() as $field) {
                 if (!$field->isAutoIncrement()) {
                     $this->fields[] = $field;
                 }
             }
         }
         if (!$this->columns) {
             foreach ($this->fields as $field) {
                 if ($field->isPrimaryKey() || $field->isAutoIncrement()) {
                     continue;
                 }
                 if ('object' !== $field->getType()) {
                     $this->columns[$field->getId()] = $field;
                 }
             }
             if ($labelField = $this->objectDefinition->getLabelField()) {
                 $field = $this->objectDefinition->getField($labelField);
                 $this->columns[$field->getId()] = $field;
             }
         }
         //we need to call it, no matter if it's already defined, because of multiLanguage field.
         $this->prepareFieldItem($this->fields);
         $this->translateFields($this->fields);
         $this->translateFields($this->columns);
         if (!isset($this->titleField)) {
             $this->titleField = $this->objectDefinition->getLabel();
         }
     } else {
         //resolve shortcuts
         if ($this->fields) {
             $this->prepareFieldDefinition($this->fields);
             $this->convertToFieldObjects($this->fields);
             $this->prepareFieldItem($this->fields);
             $this->translateFields($this->fields);
         }
         if ($this->columns) {
             $this->prepareFieldDefinition($this->columns);
             $this->convertToFieldObjects($this->columns);
             $this->translateFields($this->columns);
         }
     }
     $this->ensureLanguageField();
     $this->fields = $this->toIdIndex($this->fields);
     $this->columns = $this->toIdIndex($this->columns);
     if ($this->addMultipleFields) {
         $this->prepareFieldDefinition($this->addMultipleFields);
         $this->convertToFieldObjects($this->addMultipleFields);
         $this->translateFields($this->addMultipleFields);
     }
     if ($this->addMultipleFixedFields) {
         $this->prepareFieldDefinition($this->addMultipleFixedFields);
         $this->convertToFieldObjects($this->addMultipleFixedFields);
         $this->translateFields($this->addMultipleFixedFields);
     }
     if (is_string($this->primary)) {
         $this->primary = explode(',', str_replace(' ', '', $this->primary));
     }
     if (!$this->order || count($this->order) == 0) {
         /* compatibility */
         $this->orderByDirection = strtolower($this->orderByDirection) == 'asc' ? 'asc' : 'desc';
         if ($this->orderBy) {
             $this->order = array($this->orderBy => $this->orderByDirection);
         }
     }
     if ((!$this->order || count($this->order) == 0) && $this->columns) {
         reset($this->columns);
         $field = current($this->columns);
         if ($field instanceof Field) {
             $this->order[$field->getId()] = 'asc';
         }
     }
     //normalize order array
     if (count($this->order) > 0 && is_numeric(key($this->order))) {
         $newOrder = array();
         foreach ($this->order as $order) {
             $newOrder[$order['field']] = $order['direction'];
         }
         $this->order = $newOrder;
     }
     $this->filterFields = array();
     if ($this->filter) {
         foreach ($this->filter as $key => $val) {
             if (is_numeric($key)) {
                 //no special definition
                 $fieldKey = $val;
                 $field = $this->fields[$val];
             } else {
                 $field = $val;
                 $fieldKey = $key;
             }
             $this->prepareFieldItem($field);
             $this->filterFields[$fieldKey] = $field;
         }
     }
     if (!$this->primary) {
         $this->primary = array();
         if ($this->objectDefinition) {
             foreach ($this->objectDefinition->getPrimaryKeys() as $sfield) {
                 $this->primary[] = $sfield->getId();
             }
         }
     }
     $this->translate($this->nestedRootAddLabel);
     $this->translate($this->newLabel);
 }