getQueryPaginator example


    protected function getTemplates($offset = null, $limit = null, $id = null)
    {
        try {
            $query = $this->getTemplatesQuery($offset$limit$id);
            $paginator = $this->getQueryPaginator($query->getQuery());

            $result = [
                'success' => true,
                'total' => $paginator->count(),
                'data' => iterator_to_array($paginator),
            ];
        } catch (Exception $e) {
            return ['success' => false, 'error' => $e->getMessage()];
        }

        return $result;
    }

    public function getDetail($id)
    {
        $builder = $this->getDetailQuery($id);

        $data = iterator_to_array($this->getQueryPaginator($builder))[0] ?? [];
        if (!\is_array($data)) {
            $data = [];
        }
        $data = $this->getAdditionalDetailData($data);

        return ['success' => true, 'data' => $data];
    }

    /** * Contains the logic to create or update an existing record. * If the passed $data parameter contains a filled "id" property, * the function executes an entity manager find query for the configured * model and the passed id. If the $data parameter contains no id property, * this function creates a new instance of the configured model. * * If you have some doctrine association in your model, or you want * to modify the passed data object, you can use the {@link #resolveExtJsData} function * to modify the data property. * * You can implement \Symfony\Component\Validator\Constraints asserts in your model * which will be validate in the save process. * If the asserts throws an exception or some fields are invalid, the function returns * an array like this: * * array( * 'success' => false, * 'violations' => array( * array( * 'message' => 'Property can not be null', * 'property' => 'article.name' * ), * ... * ) * ) * * If the save process was successfully, the function returns a success array with the * updated model data. * * @param array<string, mixed> $data * * @return array<string, mixed> */
Home | Imprint | This part of the site doesn't use cookies.