diff --git a/docs/Criteria.md b/docs/Criteria.md new file mode 100644 index 0000000..d05e44c --- /dev/null +++ b/docs/Criteria.md @@ -0,0 +1,262 @@ +# Search Filter Criteria Documentation + +## Overview + +Search Filter Criteria allow you to build complex, flexible search queries in your CakePHP application. Each criterion type serves a specific purpose and can be combined to create powerful search functionality. + +## Index of Criteria + +1. [AndCriterion](#andcriterion) +2. [BoolCriterion](#boolcriterion) +3. [DateCriterion](#datecriterion) +4. [DateTimeCriterion](#datetimecriterion) +5. [InCriterion](#incriterion) +6. [LookupCriterion](#lookupcriterion) +7. [NumericCriterion](#numericcriterion) +8. [OrCriterion](#orcriterion) +9. [StringCriterion](#stringcriterion) + +## Criterion Types + +### AndCriterion + +**Purpose:** Combines multiple criteria with AND logic. + +**Configuration:** +```php +use CakeDC\SearchFilter\Model\Filter\Criterion\AndCriterion; + +$andCriterion = new AndCriterion($criteria); +``` + + +**Parameters:** +- `$criteria` (array): An array of BaseCriterion objects to be combined with AND logic. + +**Example:** +```php +$andCriterion = new AndCriterion([ + new DateCriterion('created'), + new BoolCriterion('is_active') +]); +``` + + +This will create a condition that matches both the creation date AND the active status. + +--- + +### BoolCriterion + +**Purpose:** Filters results based on a boolean field. + +**Configuration:** +```php +use CakeDC\SearchFilter\Model\Filter\Criterion\BoolCriterion; + +$boolCriterion = new BoolCriterion($field); +``` + + +**Parameters:** +- `$field` (string|\Cake\Database\ExpressionInterface): The boolean field to filter on. + +**Example:** +```php +$boolCriterion = new BoolCriterion('is_published'); +``` + + +This will filter results based on whether the 'is_published' field is true or false. + +--- + +### DateCriterion + +**Purpose:** Filters results based on date fields, supporting various comparison types. + +**Configuration:** +```php +use CakeDC\SearchFilter\Model\Filter\Criterion\DateCriterion; + +$dateCriterion = new DateCriterion($field, $format = 'Y-m-d'); +``` + + +**Parameters:** +- `$field` (string|\Cake\Database\ExpressionInterface): The date field to filter on. +- `$format` (string): The date format string (default: 'Y-m-d'). + +**Example:** +```php +$dateCriterion = new DateCriterion('created_date', 'Y-m-d'); +``` + + +This allows filtering on date fields with support for various conditions like 'between', 'greater than', etc. + +--- + +### DateTimeCriterion + +**Purpose:** Filters results based on datetime fields. + +**Configuration:** +```php +use CakeDC\SearchFilter\Model\Filter\Criterion\DateTimeCriterion; + +$dateTimeCriterion = new DateTimeCriterion($field, $format = 'Y-m-d\TH:i'); +``` + + +**Parameters:** +- `$field` (string|\Cake\Database\ExpressionInterface): The datetime field to filter on. +- `$format` (string): The datetime format string (default: 'Y-m-d\TH:i'). + +**Example:** +```php +$dateTimeCriterion = new DateTimeCriterion('created_at', 'Y-m-d H:i:s'); +``` + + +This allows filtering on datetime fields with support for various conditions, similar to DateCriterion but including time. + +--- + +### InCriterion + +**Purpose:** Filters results where a field's value is in a set of values determined by a subquery. + +**Configuration:** +```php +use CakeDC\SearchFilter\Model\Filter\Criterion\InCriterion; + +$inCriterion = new InCriterion($field, $table, $criterion); +``` + + +**Parameters:** +- `$field` (string|\Cake\Database\ExpressionInterface): The field to filter on. +- `$table` (\Cake\ORM\Table): The table used for the subquery. +- `$criterion` (BaseCriterion): The criterion used to build the subquery. + +**Example:** +```php +$authorTable = $this->getTableLocator()->get('Authors'); +$stringCriterion = new StringCriterion('name'); +$inCriterion = new InCriterion('author_id', $authorTable, $stringCriterion); +``` + + +This will create a subquery to find authors and then filter the main query based on the results. + +--- + +### LookupCriterion + +**Purpose:** Performs a lookup in a related table based on a search term. + +**Configuration:** +```php +use CakeDC\SearchFilter\Model\Filter\Criterion\LookupCriterion; + +$lookupCriterion = new LookupCriterion($field, $table, $criterion); +``` + + +**Parameters:** +- `$field` (string|\Cake\Database\ExpressionInterface): The field to filter on. +- `$table` (\Cake\ORM\Table): The related table to perform the lookup on. +- `$criterion` (BaseCriterion): The criterion used for the lookup. + +**Example:** +```php +$authorTable = $this->getTableLocator()->get('Authors'); +$stringCriterion = new StringCriterion('name'); +$lookupCriterion = new LookupCriterion('author_id', $authorTable, $stringCriterion); +``` + + +This allows searching in related tables and filtering the main query based on the results. + +--- + +### NumericCriterion + +**Purpose:** Filters results based on numeric fields. + +**Configuration:** +```php +use CakeDC\SearchFilter\Model\Filter\Criterion\NumericCriterion; + +$numericCriterion = new NumericCriterion($field); +``` + + +**Parameters:** +- `$field` (string|\Cake\Database\ExpressionInterface): The numeric field to filter on. + +**Example:** +```php +$numericCriterion = new NumericCriterion('price'); +``` + + +This allows filtering on numeric fields with support for various conditions like 'greater than', 'between', etc. + +--- + +### OrCriterion + +**Purpose:** Combines multiple criteria with OR logic. + +**Configuration:** +```php +use CakeDC\SearchFilter\Model\Filter\Criterion\OrCriterion; + +$orCriterion = new OrCriterion($criteria); +``` + + +**Parameters:** +- `$criteria` (array): An array of CriterionInterface objects to be combined with OR logic. + +**Example:** +```php +$orCriterion = new OrCriterion([ + new StringCriterion('title'), + new StringCriterion('content') +]); +``` + + +This will create a condition that matches either the title OR the content. + +--- + +### StringCriterion + +**Purpose:** Filters results based on string matching. + +**Configuration:** +```php +use CakeDC\SearchFilter\Model\Filter\Criterion\StringCriterion; + +$stringCriterion = new StringCriterion($field); +``` + + +**Parameters:** +- `$field` (string|\Cake\Database\ExpressionInterface): The string field to filter on. + +**Example:** +```php +$stringCriterion = new StringCriterion('title'); +``` + + +This allows filtering on string fields with support for various conditions like 'contains', 'starts with', etc. + +--- + +These criteria can be combined to create complex search queries. For example, you can use AndCriterion or OrCriterion to group multiple criteria together. \ No newline at end of file diff --git a/docs/Filters.md b/docs/Filters.md new file mode 100644 index 0000000..fd34990 --- /dev/null +++ b/docs/Filters.md @@ -0,0 +1,223 @@ +Certainly! I'll update the examples to use object chaining calls for a more concise and fluent syntax. Here's the revised documentation with chained method calls: + +# Search Filter Documentation + +## Overview + +Search Filters in this library provide a flexible way to define and configure various types of filters for your search functionality. Each filter type is designed for specific data types or search scenarios and is associated with a specific Vue widget for rendering. + +## Index of Filters + +1. [BooleanFilter](#booleanfilter) +2. [DateFilter](#datefilter) +3. [DateTimeFilter](#datetimefilter) +4. [LookupFilter](#lookupfilter) +5. [MultipleFilter](#multiplefilter) +6. [NumericFilter](#numericfilter) +7. [SelectFilter](#selectfilter) +8. [StringFilter](#stringfilter) + +## Filter Types + +### BooleanFilter + +**Purpose:** Used for boolean-based filtering, typically for Yes/No selections. + +**Vue Widget:** `SearchSelect` + +**Configuration:** +```php +use CakeDC\SearchFilter\Filter\BooleanFilter; +use CakeDC\SearchFilter\Model\Filter\Criterion\BoolCriterion; + +$booleanFilter = (new BooleanFilter()) + ->setCriterion(new BoolCriterion('is_active')) + ->setLabel('Active Status') + ->setOptions([1 => 'Active', 0 => 'Inactive']); +``` + + +**Key Features:** +- Provides Yes/No options by default. +- Can customize options using `setOptions()` method. +- Renders as a select input. + +--- + +### DateFilter + +**Purpose:** Used for date-based filtering, supporting various date formats and conditions. + +**Vue Widget:** `SearchInputDate`, `SearchInputDateRange`, or `SearchInputDateFixed` (depending on the condition) + +**Configuration:** +```php +use CakeDC\SearchFilter\Filter\DateFilter; +use CakeDC\SearchFilter\Model\Filter\Criterion\DateCriterion; + +$dateFilter = (new DateFilter()) + ->setCriterion(new DateCriterion('created_date')) + ->setLabel('Creation Date') + ->setDateFormat('YYYY-MM-DD'); +``` + + +**Key Features:** +- Default date format is 'DD/MM/YYYY'. +- Supports conditions like equals, greater than, less than, between, etc. +- Includes special conditions like 'Today', 'Yesterday', 'This week', 'Last week'. + +--- + +### DateTimeFilter + +**Purpose:** Used for datetime-based filtering, supporting both date and time components. + +**Vue Widget:** `SearchInputDateTime`, `SearchInputDateTimeRange`, or `SearchInputDateTimeFixed` (depending on the condition) + +**Configuration:** +```php +use CakeDC\SearchFilter\Filter\DateTimeFilter; +use CakeDC\SearchFilter\Model\Filter\Criterion\DateTimeCriterion; + +$dateTimeFilter = (new DateTimeFilter()) + ->setCriterion(new DateTimeCriterion('created_at')) + ->setLabel('Creation Date and Time') + ->setProperty('dateFormat', 'YYYY-MM-DD HH:mm:ss'); +``` + + +**Key Features:** +- Default datetime format is 'DD/MM/YYYY hh:mm A'. +- Supports the same conditions as DateFilter, but includes time in comparisons. + +--- + +### LookupFilter + +**Purpose:** Used for autocomplete-based filtering, allowing lookup of values based on a query string. + +**Vue Widget:** `SearchLookupInput` or `SearchMultiple` (for 'in' condition) + +**Configuration:** +```php +use CakeDC\SearchFilter\Filter\LookupFilter; +use CakeDC\SearchFilter\Model\Filter\Criterion\LookupCriterion; +use CakeDC\SearchFilter\Model\Filter\Criterion\StringCriterion; + +$lookupFilter = (new LookupFilter()) + ->setCriterion(new LookupCriterion('user_id', $usersTable, new StringCriterion('name'))) + ->setLabel('User') + ->setLookupFields(['name', 'email']) + ->setAutocompleteRoute(['controller' => 'Users', 'action' => 'autocomplete']); +``` + + +**Key Features:** +- Supports autocomplete functionality. +- Configurable lookup fields and autocomplete route. +- Generates autocomplete URL automatically. + +--- + +### MultipleFilter + +**Purpose:** Used for filtering based on multiple selected values. + +**Vue Widget:** `SearchMultiple` + +**Configuration:** +```php +use CakeDC\SearchFilter\Filter\MultipleFilter; +use CakeDC\SearchFilter\Model\Filter\Criterion\InCriterion; +use CakeDC\SearchFilter\Model\Filter\Criterion\StringCriterion; + +$multipleFilter = (new MultipleFilter()) + ->setCriterion(new InCriterion('category_id', $categoriesTable, new StringCriterion('name'))) + ->setLabel('Categories') + ->setProperty('placeholder', 'Select multiple options'); +``` + + +**Key Features:** +- Supports 'In' and 'Not In' conditions. +- Designed for multiple selections. + +--- + +### NumericFilter + +**Purpose:** Used for numeric-based filtering, supporting various numeric comparisons. + +**Vue Widget:** `SearchInput` or `SearchInputNumericRange` (for 'between' condition) + +**Configuration:** +```php +use CakeDC\SearchFilter\Filter\NumericFilter; +use CakeDC\SearchFilter\Model\Filter\Criterion\NumericCriterion; + +$numericFilter = (new NumericFilter()) + ->setCriterion(new NumericCriterion('price')) + ->setLabel('Price') + ->setProperty('step', '0.01'); // For decimal numbers +``` + + +**Key Features:** +- Supports conditions like equals, not equals, greater than, less than, between, etc. +- Specifically designed for numeric values. + +--- + +### SelectFilter + +**Purpose:** Used for select-based filtering, allowing selection from predefined options. + +**Vue Widget:** `SearchSelect` or `SearchMultiple` (for 'in' condition) + +**Configuration:** +```php +use CakeDC\SearchFilter\Filter\SelectFilter; +use CakeDC\SearchFilter\Model\Filter\Criterion\InCriterion; +use CakeDC\SearchFilter\Model\Filter\Criterion\StringCriterion; + +$selectFilter = (new SelectFilter()) + ->setCriterion(new InCriterion('status', $statusesTable, new StringCriterion('name'))) + ->setLabel('Status') + ->setOptions(['active' => 'Active', 'inactive' => 'Inactive']) + ->setEmpty('All Statuses'); +``` + + +**Key Features:** +- Supports custom options. +- Can set an empty option. +- Supports conditions like equals, not equals, in, like. + +--- + +### StringFilter + +**Purpose:** Used for string-based filtering, supporting various string comparison conditions. + +**Vue Widget:** `SearchInput` or `SearchMultiple` (for 'in' condition) + +**Configuration:** +```php +use CakeDC\SearchFilter\Filter\StringFilter; +use CakeDC\SearchFilter\Model\Filter\Criterion\StringCriterion; + +$stringFilter = (new StringFilter()) + ->setCriterion(new StringCriterion('title')) + ->setLabel('Title') + ->setType('email'); +``` + + +**Key Features:** +- Supports conditions like like, equals, not equals, in. +- Can be configured for different input types (e.g., text, email). + +--- + +These filters can be used to create a comprehensive search functionality in your application. They provide a range of options for different data types and search requirements, allowing for flexible and powerful search implementations. The associated Vue widgets ensure that the appropriate input type is rendered based on the filter type and condition. \ No newline at end of file