2017 © Pedro Peláez
 

library repository-helper

Symfony Repository Helper

image

tangoman/repository-helper

Symfony Repository Helper

  • Sunday, April 8, 2018
  • by Tangoman
  • Repository
  • 0 Watchers
  • 2 Stars
  • 138 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 11 Versions
  • 1 % Grown

The README.md

TangoMan Repository Helper

TangoMan Repository Helper provides trait with useful functions for your repositories., (*1)

Installation

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:, (*2)

$ composer require tangoman/repository-helper

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation., (*3)

Usage

Inside your repository

Add "use" statement just like when you're using a trait., (*4)

<?php

namespace FoobarBundle\Repository;

use Doctrine\ORM\EntityRepository;
use TangoMan\RepositoryHelper\RepositoryHelper;

/**
 * Class FoobarRepository
 */
class FoobarRepository extends EntityRepository
{
    use RepositoryHelper;
}

Inside your controller

use Symfony\Component\HttpFoundation\Request;

class FoobarController extends Controller
{
    /**
     * @Route("/")
     */
    public function indexAction(Request $request)
    {
        // Show searchable, sortable, paginated user list
        $em = $this->get('doctrine')->getManager();
        $foobars = $em->getRepository('AppBundle:Foobar')->findByQuery($request);

        return $this->render(
            'admin/foobar/index.html.twig',
            [
                'foobars' => $foobars,
            ]
        );
    }

Inside your views

Search Form

<label for="inputUser">User</label>
<input type="text" name="user-username" id="inputUser" class="form-control"
    value="{{ app.request.get('user-username')|join(', ') }}"/>

Will generate this: .../admin/posts/?user-username=admin, (*5)

<th class="{{ app.request.query.get('order') == 'user-username' ? app.request.query.get('way', 'ASC') }}">
    <a href="{{ path('app_admin_post_index', app.request.query.all|merge({
        'page'  : 1,
        'order' : 'user-username',
        'way'   : app.request.query.get('order') == 'user-username'
        and app.request.query.get('way', 'ASC') == 'ASC' ? 'DESC' : 'ASC'})) }}">
        User
    </a>
</th>

Will generate this: .../admin/posts/?page=1&order=user-username&way=ASC, (*6)

Helper Public Methods

function description parameters return
getTableName() Returns current table name n/a string
countBy($criteria = []) Returns element count, filtered by given criteria array integer
distinct($property, $criteria = []) Lists distinct items from desired column, filtered by given criteria string, array array
findAllPaged($page = 1, $limit = 10, $criteria = []) Returns X results with pagination, starting from given page, filtered by given criteria integer, integer, array (object)Paginator
findByQuery(Request $request, $criteria = []) Returns query result with pagination, filtered by given criteria (object)Request, array (object)Paginator
findByQueryScalar(Request $request, $criteria = []) Return query as scalar result with pagination, filtered by given criteria (object)Request, array (object)Paginator
export(Request $request, $criteria = []) Return all objects as scalar result, filtered by given criteria (object)Request, array array

Query Parameters

parameter type value
order string switch-entity-property
way string (ASC/DESC)
limit integer [1-9]+\d?
page integer [1-9]+\d?
join string switch-entity-property

Switches

Switch values for mode/operator/action, (*7)

switch mode description
a andWhere andWhere
b search boolean
c order count
e search exactMatch
l search like
n search notNull
o orWhere orWhere
p order property
r order orderBy
s search simpleArray

Error

When symfony raises following QueryException exception:, (*8)

&lsqb;Semantical Error&rsqb; line X, col XX near 'foo LIKE': Error: Invalid PathExpression. Must be a StateFieldPathExpression., (*9)

It means that you have an error inside your form: <input name="foo-bar">, attribute doesn't target appropriate joined entity., (*10)

Try <input name="foo-bar-title">, or <input name="bar-title">, TangoMan Repository Helper will automatically handle the join., (*11)

Note

If you find any bug please report here : Issues, (*12)

License

Copyright (c) 2018 Matthias Morin, (*13)

License Distributed under the MIT license., (*14)

If you like TangoMan Repository Helper please star! And follow me on GitHub: TangoMan75 ... And check my other cool projects., (*15)

Matthias Morin | LinkedIn, (*16)

The Versions

08/04 2018

dev-master

9999999-dev

Symfony Repository Helper

  Sources   Download

MIT GPL-3.0

The Requires

  • php >=5.3.0

 

by Matthias Morin

repository helper trait symfony tangoman

08/04 2018

3.0.2

3.0.2.0

Symfony Repository Helper

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Matthias Morin

repository helper trait symfony tangoman

21/02 2018

3.0.1

3.0.1.0

Symfony Repository Helper

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Matthias Morin

repository helper trait symfony tangoman

18/02 2018

3.0.0

3.0.0.0

Symfony Repository Helper

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Matthias Morin

repository helper trait symfony tangoman

24/11 2017

2.0.1

2.0.1.0

Symfony Repository Helper

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Matthias Morin

repository helper trait symfony tangoman

25/10 2017

dev-dev

dev-dev

Symfony Repository Helper

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Matthias Morin

repository helper trait symfony tangoman

24/10 2017

2.0.0

2.0.0.0

Symfony Repository Helper

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Matthias Morin

repository helper trait symfony tangoman

12/09 2017

1.1.2

1.1.2.0

Symfony Repository Helper

  Sources   Download

GPL-3.0

The Requires

  • php >=5.3.0

 

by Matthias Morin

repository helper trait symfony tangoman

08/09 2017

1.1.1

1.1.1.0

Symfony Repository Helper

  Sources   Download

GPL-3.0

The Requires

  • php >=5.3.0

 

by Matthias Morin

repository helper trait symfony tangoman

06/09 2017

1.1.0

1.1.0.0

Symfony Repository Helper

  Sources   Download

GPL-3.0

The Requires

  • php >=5.3.0

 

by Matthias Morin

repository helper trait symfony tangoman

18/08 2017

1.0.0

1.0.0.0

Symfony Repository Helper

  Sources   Download

GPL-3.0

The Requires

  • php >=5.3.0

 

by Matthias Morin

repository helper trait symfony tangoman