Example #1
0
 /**
  * showParentsAndChildren
  *
  * @param \stdClass $output
  * @param ApiInterface $entity
  * @param Field $field
  *
  * @return void
  * @throws Exception
  */
 private function showParentsAndChildren(\stdClass $output, ApiInterface $entity, Field $field)
 {
     if (in_array($field->getAlias(), $entity->getParentRelationships())) {
         /** @var ApiInterface $parentEntity */
         $parentEntity = $entity->getRelated($field->getAlias());
         if ($parentEntity === false) {
             //AKA, a nullable vendor
             $output->{$field->getAlias()} = null;
         } else {
             $output->{$field->getAlias()} = new \stdClass();
             $this->showRecursive($output->{$field->getAlias()}, $field, $parentEntity);
         }
     } elseif (in_array($field->getAlias(), $entity->getChildrenRelationships())) {
         $output->{$field->getAlias()} = array();
         $resultSet = $entity->getRelated($field->getAlias());
         foreach ($resultSet as $key => $currentEntity) {
             $subOutput = new \stdClass();
             $output->{$field->getAlias()}[] = $subOutput;
             $this->showRecursive($subOutput, $field, $currentEntity);
         }
     } else {
         throw new Exception('Invalid Field, not on the current object, no child or parent found: ' . $entity->getEntityName() . ' with ' . $field->getAlias(), 400);
     }
 }
Example #2
0
 /**
  * Writes the custom parent fields
  *
  * @param string[] $fields
  * @param ApiInterface $entity
  *
  * @return void
  */
 private function writeCustomParents($fields, ApiInterface $entity)
 {
     foreach ($entity->getCustomParentRelationships() as $customRelationship) {
         $name = $customRelationship->getReferencedFields();
         if (array_key_exists($name, $fields)) {
             $entity->writeAttribute($name, $fields[$name]);
         }
     }
 }
Example #3
0
 /**
  * Adds a join
  *
  * @param ApiInterface $entity
  * @param string $alias
  * @param bool $forceFind
  *
  * @return ApiInterface|false False if sub part was not found
  * @throws Exception
  */
 private function addJoin(ApiInterface $entity, $alias, $forceFind)
 {
     if (in_array($alias, $entity->getParentRelationships())) {
         $referencedModel = $entity->addJoin($this->getCriteriaHelper(), $alias);
         return new $referencedModel();
     } else {
         if ($forceFind) {
             throw new Exception('Could Not Find Part in current entity: ' . $alias, 400);
         }
         return false;
     }
 }