Get data from an entity using getter methods

@param $entity
@param array $formParameters
@param null $limitFields
@return array
559558
public function getFromEntity($entity, array $formParameters, $limitFields = null)
    {
        $extracted_data = array();

        foreach($formParameters as $field) {
            $getter_name = "get".$this->dashesToCamelCase($field);

            if (($limitFields === null || in_array($field, $limitFields)) && method_exists($entity, $getter_name) && ($value = $entity->$getter_name()) !== null) {
                $extracted_data[$field] = $value;
            }
        }

        return $extracted_data;
    }
64057
public static function getTree($entity, $entityId, $maxLevel = null)
    {
        $query = static::find()
            ->alias('c')
            ->approved()
            ->andWhere([
                'c.entityId' => $entityId,
                'c.entity' => $entity,
            ])
            ->orderBy(['c.parentId' => SORT_ASC, 'c.createdAt' => SORT_ASC])
            ->with(['author']);

        if ($maxLevel > 0) {
            $query->andWhere(['<=', 'c.level', $maxLevel]);
        }

        $models = $query->all();

        if (!empty($models)) {
            $models = static::buildTree($models);
        }

        return $models;
    }
989527
private function getPropertiesByType($entity, $type)
    {
        $properties = $this->readClassProperties($entity);

        $fields = [];
        foreach ($properties as $property) {
            $annotation = $this->reader->getPropertyAnnotation($property, $type);

            if (null === $annotation) {
                continue;
            }

            $property->setAccessible(true);
            $annotation->value = $property->getValue($entity);
            $annotation->name = $property->getName();

            $fields[] = $annotation;
        }

        return $fields;
    }
957402
public function toArray(Entity $entity, $depth=0) {
		$res = [];

		foreach($entity->getDefinition()->properties() as $name=>$property) {
			if($entity->getDefinition()->property($name) instanceof Property\EntityProperty) {
				if($depth < 1)
					continue;
				if($entity->getDefinition()->property($name)->get('many')) {
					foreach($entity->get($name, null, false) as $subentity)
						$res[$name][] = $subentity->toArray($depth-1);
				}
				else {
					if($subentity = $entity->get($name, null, false))
						$res[$name] = $subentity->toArray($depth-1);
					else
						$res[$name] = null;
				}
			}
			elseif($property->get('many')) {
				$res[$name] = [];
				foreach($entity->get($name) as $k=>$v)
					$res[$name][$k] = $this->propertyToArray($v, $property);
			}
			else
				$res[$name] = $this->propertyToArray($entity->get($name), $property);
		}

		return $res;
	}
1140216
protected function getExistingFields($entity)
    {
        /** @var FieldValueRepository $repo */
        $repo = $this->em->getRepository(Entity\FieldValue::class);

        return $repo->getExistingFields($entity->getId(), $entity->getContenttype(), $this->mapping['fieldname']);
    }
1113235
public function getQueryArgs($formValue)
    {
        // TODO: Implement getQueryArgs() method.
        $arr = [];
        if (is_array($formValue) && !empty($formValue)) {
            $arr = $formValue;
        }

        if (is_string($formValue) && !empty($formValue)) {
            $arr = array_filter(explode(',', $formValue));
        }

        return [$this->field, $arr];
    }
1362252
public function extract($entity)
    {
        $metadata = $this->getMetadata();
        $collection = [];
        
        foreach ($metadata->getSQLNames() as $sqlName) {
            $propertyName = $metadata->getName($sqlName, Metadata::CAMILIZED);
            $propertyValue = $this->getReflection()->getProperty($propertyName)->getValue($entity);
            $propertyValue = $propertyValue !== null
                ? $metadata->toPlatform($metadata->getName($sqlName), $propertyValue) : null;
            $collection[$sqlName] = $propertyValue;
        }
        
        return $collection;
    }
451967
public function createForm($entity, $options = [])
    {
        $options = array_merge($this->type()['formFields']['_create'], $options);

        return $this->Form->create($entity, $options);
    }
248861
public function getFields($offset = 0, $limit = 100)
	{
		$fields = [];
		foreach ($this->client->get("fields?offset={$offset}&limit={$limit}") as $field) {
			$fields[] = new Resources\Field($this, $field);
		}
		return $fields;
	}
242139
public function all($fields = null, $limit = null)
    {
        $result = $this->storage;

        if (isset($limit)) {
            $result = array_slice($this->storage, $limit);
        }

        if (empty($fields)) {
            return $this->result = new ArrayIterator($result);
        } else {
            $this->result = new ArrayIterator();

            foreach ($result as $row) {
                $item = new SplArrayObject();
                foreach ($fields as $field) {
                    if ($row->offsetExists($field)) {
                        $item[ $field ] = $row->offsetGet($field);
                    }
                }

                $this->result[] = $item;
            }

            return $this->result;
        }

        return false;
    }
899535
public function get($field)
    {
        if (!is_null($this->filtered) && ! is_null($this->filtered[0])) {
            return isset($this->filtered[0][0][$field]) ? $this->filtered[0][0][$field] : null;
        }

        // Todo: Get values of entities
    }
296404
public function getEntityAttributeView($type = false, $offset = 0, $limit = 1000, $details = true) {
        $Entities = array();
        $Columns = array();

        if ($type) {
            $url = $this->url . "contextEntityTypes/" . $type;
        } else {
            $url = $this->url . "contextEntities";
        }
        
        $_details = ($details)? "on" : "off";
        
        //Need improvments sinse paging was implemented
        $ret = $this->restRequest($url . "?offset=$offset&limit=$limit&details=$_details", 'GET')->getResponseBody();

        $Context = new Context\Context($ret);

        $keysindex = array();


        $ContextOBject = $Context->__toObject();

        if (is_object($ContextOBject) && isset($ContextOBject->contextResponses)) {
            foreach ($ContextOBject->contextResponses as $entity) {
                $t = $entity->contextElement->type;
                $id = $entity->contextElement->id;

                if (!array_key_exists($t, $keysindex)) {
                    $keysindex[$t] = 0;
                }

                if (!array_key_exists($t, $Columns)) {
                    $Columns[$t] = array("id", "__original");
                }
                $i = $keysindex[$t];

                $Entities[$t][$i]['id'] = $id;

                foreach ($entity->contextElement->attributes as $value) {
                    $Entities[$t][$i][$value->name] = $value->value;
                    array_push($Columns[$t], $value->name);
                }

                $Entities[$t][$i]['__original'] = $entity->contextElement;

                $keysindex[$t] ++;
            }


            if ($this->checkVersion("0.15.0", ">=")) {
                if (!isset($this->_entityTypes)) {
                    $this->getEntityTypes();
                }
                
                foreach ($this->_entityTypes as $t => $attr) {
                    $Columns[$t] = array("id", "__original");
                    foreach ($attr as $a) {
//                        var_dump($a);
                        array_push($Columns[$t], $a);
                    }
                }
            } else {
                //Slow
                foreach ($Columns as $c => $column) {
                    $Columns[$c] = array_unique($column);
                }
            }

            //Magic: Create Empy columns for different entities attribute of the same type
            foreach ($Entities as $EntityType => $EntityGroup) {
                foreach ($EntityGroup as $key => $EntityRow) {
                    $diff = array_diff($Columns[$EntityType], array_keys($EntityRow));
                    if (count($diff) > 0) {
                        foreach ($diff as $column) {
                            $Entities[$EntityType][$key][$column] = null; //Empty value
                        }
                    }
                }
            }
        }
//        }

        return array("entities" => $Entities, "columns" => $Columns);
    }
361710
public function getEntityArrayValues($entity)
    {
        $values = [];
        $properties = $this->getEntityProperties($entity);
        $metadata = $this->em->getClassMetadata(get_class($entity));
        foreach ($properties as $property) {
            $values[$property] = $metadata->getFieldValue($entity, $property);
        }
        return $values;
    }
869734
protected function generateFields(Entity $entity)
    {
        $fields     = [];
        $descriptor = $entity->getDescriptor();
        $extensions = $descriptor->getExtensionList() ?: [];

        foreach ($extensions as $field) {
            $fields[] = $this->generateExtensionField($entity, $field);
        }

        return $fields;
    }
1341637
public function getRouteParams(AbstractEntity $entity, array $routeParams = [])
    {
        if (count($routeParams) === 0) {

            return [];
        }

        $params = [];
        foreach ($routeParams as $param) {
            if ( ! method_exists($entity, 'get' . ucfirst($param))) {

                trigger_error(
                    'Function "get' . ucfirst($param) . '" does not exist on "' . get_class($entity) . '". Skipping.'
                );
                continue;
            }

            $params[$param] = $entity->{'get' . ucfirst($param)}();
        }

        return $params;
    }
112081
public function getUserNames($entity)
    {
        $users = $this->getDoctrine()->getRepository($entity)->findBy(
            [
                'enabled' => true,
            ],
            [
                'id' => 'asc',
            ]
        );

        return CollectionUtility::get('username', $users);
    }
327474
public function getEntities($type = false, $offset = 0, $limit = 1000, $details = "on") {
        if ($type) {
            $url = $this->url . "contextTypes/" . $type;
        } else {
            $url = $this->url . "contextEntities/";
        }

        $ret = $this->restRequest($url . "?offset=$offset&limit=$limit&details=$details", 'GET')->getResponseBody();
        $Context = (new Context\Context($ret))->get();
        $Entities = [];
        
        if($Context instanceof \stdClass && isset($Context->errorCode)){
            switch ((int) $Context->errorCode->code) {
                case 404:
                case 500:
                    throw new Exception\GeneralException($Context->errorCode->reasonPhrase,(int)$Context->errorCode->code, null, $ret);
                default:
                case 200:
                    break;
            }
        }else{
            throw new Exception\GeneralException("Malformed Orion Response",500, null, $ret);
        }
        
        if(isset($Context->contextResponses) && count($Context->contextResponses) > 0){
            foreach ($Context->contextResponses as $entity) {
                $t = $entity->contextElement->type;
                $id = $entity->contextElement->id;
                
                if(!array_key_exists($t, $Entities)){
                    $Entities[$t] = [];
                }
                $Entities[$t][$id] = $entity->contextElement->attributes;
            }
        }




        return new Context\Context($Entities);
    }