https://github.com/tangoman75/repositoryhelper
TangoMan Repository Helper provides trait with useful methods for your repositories
https://github.com/tangoman75/repositoryhelper
Last synced: 10 months ago
JSON representation
TangoMan Repository Helper provides trait with useful methods for your repositories
- Host: GitHub
- URL: https://github.com/tangoman75/repositoryhelper
- Owner: TangoMan75
- License: mit
- Created: 2017-08-18T16:11:47.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2018-04-08T21:32:03.000Z (over 8 years ago)
- Last Synced: 2024-12-01T08:23:13.689Z (over 1 year ago)
- Language: PHP
- Homepage:
- Size: 128 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
TangoMan Repository Helper
==========================
**TangoMan Repository Helper** provides trait with useful functions for your repositories.
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:
```bash
$ composer require tangoman/repository-helper
```
This command requires you to have Composer installed globally, as explained
in the [installation chapter](https://getcomposer.org/doc/00-intro.md)
of the Composer documentation.
Usage
=====
Inside your repository
----------------------
Add "use" statement just like when you're using a trait.
```php
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
```twig
User
```
Will generate this:
.../admin/posts/?user-username=admin
### Order Link
```twig
```
Will generate this:
.../admin/posts/?page=1&order=user-username&way=ASC
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
| 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:
> [Semantical Error] line X, col XX near 'foo LIKE': Error: Invalid PathExpression. Must be a StateFieldPathExpression.
It means that you have an error inside your form: ``, attribute doesn't target appropriate joined entity.
Try ``, or ``, **TangoMan Repository Helper** will automatically handle the join.
Note
====
If you find any bug please report here : [Issues](https://github.com/TangoMan75/RepositoryHelper/issues/new)
License
=======
Copyright (c) 2018 Matthias Morin
[![License][license-MIT]][license-url]
Distributed under the MIT license.
If you like **TangoMan Repository Helper** please star!
And follow me on GitHub: [TangoMan75](https://github.com/TangoMan75)
... And check my other cool projects.
[Matthias Morin | LinkedIn](https://www.linkedin.com/in/morinmatthias)
[license-MIT]: https://img.shields.io/badge/Licence-MIT-green.svg
[license-url]: LICENSE