diff --git a/manual/includes/_pagable.md b/manual/includes/_pagable.md index b05dd6c..c01b226 100644 --- a/manual/includes/_pagable.md +++ b/manual/includes/_pagable.md @@ -116,10 +116,66 @@ Metods: - getLimit - setLimit +**PicoSortable** + +Constructor: + +Parameters: + +Users can enter an even number of parameters where odd numbered parameters are columns while even numbered parameters are methods. + Example: +```php +$sortable = new PicoSortable("name", "asc", "phone", "desc"); +``` + +Method: + +- add +- addSortable +- createSortable +- createOrderBy +- isEmpty +- getSortable + +Static methods: + +- getInstance + +addSortable + +Parameters: + +- PicoSort|array + +**PicoSort** -**With Page** +Constructor: + +Parameters: + +- string $sortBy +- string $sortType + +Metods: + +- getSortBy +- setSortBy +- getSortType +- setSortType +- __call + +Static methods: + +- getInstance +- fixSortType + + +Example: + + +**Pageable without Sortable** ```php $pageable = new PicoPageable(new Page(1, 100)); @@ -128,7 +184,7 @@ $pageable = new PicoPageable(new Page(1, 100)); // no sortable ``` -**With Page and Sortable** +**Pageable with Page and Sortable** ```php $sortable = new PicoSortable(); @@ -216,6 +272,21 @@ $pageable = new PicoPageable(new PicoLimit(0, 100), $sortable); // ORDER BY user_name ASC, email DESC, phone ASC ``` +or + +```php +$sortable = PicoSortable::getInstance() + ->add(PicoSort::getInstance()->sortByUserName(PicoSort::ORDER_TYPE_ASC)) + ->add(PicoSort::getInstance()->sortByEmail(PicoSort::ORDER_TYPE_DESC)) + ->add(PicoSort::getInstance()->sortByPhone(PicoSort::ORDER_TYPE_ASC)) +; + +$pageable = new PicoPageable(new PicoLimit(0, 100), $sortable); +// offset = 0 +/// limit = 100 +// ORDER BY user_name ASC, email DESC, phone ASC +``` + 1. Construtor with page as PicoPageable and sortable as PicoSortable `$pageable = new PicoPageable(new PicoPage(1, 100), new PicoSortable('userName', 'asc', 'email', 'desc', 'phone', 'asc'));` diff --git a/manual/index.html b/manual/index.html index 8a4e547..2cedf70 100644 --- a/manual/index.html +++ b/manual/index.html @@ -5870,13 +5870,57 @@
PicoSortable
+Constructor:
+Parameters:
+Users can enter an even number of parameters where odd numbered parameters are columns while even numbered parameters are methods.
Example:
-With Page
+$sortable = new PicoSortable("name", "asc", "phone", "desc");
+Method:
+Static methods:
+addSortable
+Parameters:
+PicoSort
+Constructor:
+Parameters:
+Metods:
+Static methods:
+Example:
+Pageable without Sortable
$pageable = new PicoPageable(new Page(1, 100));
// page number = 1
// page size = 100
// no sortable
-With Page and Sortable
+Pageable with Page and Sortable
$sortable = new PicoSortable();
$sort1 = new PicoSort('userName', 'asc');
@@ -5936,6 +5980,17 @@ Pageable and Sortable
->add(new PicoSort('phone', PicoSort::ORDER_TYPE_ASC))
;
+$pageable = new PicoPageable(new PicoLimit(0, 100), $sortable);
+// offset = 0
+/// limit = 100
+// ORDER BY user_name ASC, email DESC, phone ASC
+or
+$sortable = PicoSortable::getInstance()
+ ->add(PicoSort::getInstance()->sortByUserName(PicoSort::ORDER_TYPE_ASC))
+ ->add(PicoSort::getInstance()->sortByEmail(PicoSort::ORDER_TYPE_DESC))
+ ->add(PicoSort::getInstance()->sortByPhone(PicoSort::ORDER_TYPE_ASC))
+;
+
$pageable = new PicoPageable(new PicoLimit(0, 100), $sortable);
// offset = 0
/// limit = 100
diff --git a/src/Database/PicoSort.php b/src/Database/PicoSort.php
index dbf9e34..19bf9d1 100644
--- a/src/Database/PicoSort.php
+++ b/src/Database/PicoSort.php
@@ -21,6 +21,11 @@ class PicoSort
*/
private $sortType = "";
+ /**
+ * Constructor
+ * @param string $sortBy
+ * @param string $sortType
+ */
public function __construct($sortBy = null, $sortType = null)
{
$this->setSortBy($sortBy);
@@ -40,7 +45,7 @@ public function getSortBy()
/**
* Set sort by
*
- * @param string $sortBy Sort by
+ * @param string $sortBy Sort by
*
* @return self
*/
@@ -64,7 +69,7 @@ public function getSortType()
/**
* Set sort type
*
- * @param string $sortType Sort type
+ * @param string $sortType Sort type
*
* @return self
*/
diff --git a/tutorial.md b/tutorial.md
index b9b2f3f..ce9fecd 100644
--- a/tutorial.md
+++ b/tutorial.md
@@ -6480,10 +6480,66 @@ Metods:
- getLimit
- setLimit
+**PicoSortable**
+
+Constructor:
+
+Parameters:
+
+Users can enter an even number of parameters where odd numbered parameters are columns while even numbered parameters are methods.
+
Example:
+```php
+$sortable = new PicoSortable("name", "asc", "phone", "desc");
+```
+
+Method:
-**With Page**
+- add
+- addSortable
+- createSortable
+- createOrderBy
+- isEmpty
+- getSortable
+
+Static methods:
+
+- getInstance
+
+addSortable
+
+Parameters:
+
+- PicoSort|array
+
+**PicoSort**
+
+Constructor:
+
+Parameters:
+
+- string $sortBy
+- string $sortType
+
+Metods:
+
+- getSortBy
+- setSortBy
+- getSortType
+- setSortType
+- __call
+
+Static methods:
+
+- getInstance
+- fixSortType
+
+
+Example:
+
+
+**Pageable without Sortable**
```php
$pageable = new PicoPageable(new Page(1, 100));
@@ -6492,7 +6548,7 @@ $pageable = new PicoPageable(new Page(1, 100));
// no sortable
```
-**With Page and Sortable**
+**Pageable with Page and Sortable**
```php
$sortable = new PicoSortable();
@@ -6580,6 +6636,21 @@ $pageable = new PicoPageable(new PicoLimit(0, 100), $sortable);
// ORDER BY user_name ASC, email DESC, phone ASC
```
+or
+
+```php
+$sortable = PicoSortable::getInstance()
+ ->add(PicoSort::getInstance()->sortByUserName(PicoSort::ORDER_TYPE_ASC))
+ ->add(PicoSort::getInstance()->sortByEmail(PicoSort::ORDER_TYPE_DESC))
+ ->add(PicoSort::getInstance()->sortByPhone(PicoSort::ORDER_TYPE_ASC))
+;
+
+$pageable = new PicoPageable(new PicoLimit(0, 100), $sortable);
+// offset = 0
+/// limit = 100
+// ORDER BY user_name ASC, email DESC, phone ASC
+```
+
1. Construtor with page as PicoPageable and sortable as PicoSortable
`$pageable = new PicoPageable(new PicoPage(1, 100), new PicoSortable('userName', 'asc', 'email', 'desc', 'phone', 'asc'));`