Пример #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);
     }
 }
Пример #2
0
 /**
  * Filters the params down to just the instance parents
  *
  * @param \stdClass $params
  * @param ApiInterface $entity
  *
  * @return \stdClass[]
  * @throws Exception
  */
 private function filterParents(\stdClass $params, ApiInterface $entity)
 {
     $parents = array();
     foreach ($params as $key => $value) {
         if (is_object($value) && get_class($value) == 'stdClass') {
             $alias = ucfirst($key);
             if (in_array($alias, $entity->getParentRelationships())) {
                 $parents[$alias] = $value;
             } else {
                 throw new Exception('Could not find the parent field: ' . $key, 400);
             }
         }
     }
     return $parents;
 }
Пример #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;
     }
 }