Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
kamshory committed Aug 3, 2024
1 parent f833384 commit 5c242f5
Show file tree
Hide file tree
Showing 4 changed files with 210 additions and 8 deletions.
75 changes: 73 additions & 2 deletions manual/includes/_pagable.md
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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();
Expand Down Expand Up @@ -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'));`
Expand Down
59 changes: 57 additions & 2 deletions manual/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5870,13 +5870,57 @@ <h3>Pageable and Sortable</h3>
<li>getLimit</li>
<li>setLimit</li>
</ul>
<p><strong>PicoSortable</strong></p>
<p>Constructor:</p>
<p>Parameters:</p>
<p>Users can enter an even number of parameters where odd numbered parameters are columns while even numbered parameters are methods.</p>
<p>Example:</p>
<p><strong>With Page</strong></p>
<pre><code class="language-php">$sortable = new PicoSortable("name", "asc", "phone", "desc");</code></pre>
<p>Method:</p>
<ul>
<li>add</li>
<li>addSortable</li>
<li>createSortable</li>
<li>createOrderBy</li>
<li>isEmpty</li>
<li>getSortable</li>
</ul>
<p>Static methods:</p>
<ul>
<li>getInstance</li>
</ul>
<p>addSortable</p>
<p>Parameters:</p>
<ul>
<li>PicoSort|array</li>
</ul>
<p><strong>PicoSort</strong></p>
<p>Constructor:</p>
<p>Parameters:</p>
<ul>
<li>string $sortBy</li>
<li>string $sortType</li>
</ul>
<p>Metods:</p>
<ul>
<li>getSortBy</li>
<li>setSortBy</li>
<li>getSortType</li>
<li>setSortType</li>
<li>__call</li>
</ul>
<p>Static methods:</p>
<ul>
<li>getInstance</li>
<li>fixSortType</li>
</ul>
<p>Example:</p>
<p><strong>Pageable without Sortable</strong></p>
<pre><code class="language-php">$pageable = new PicoPageable(new Page(1, 100));
// page number = 1
// page size = 100
// no sortable</code></pre>
<p><strong>With Page and Sortable</strong></p>
<p><strong>Pageable with Page and Sortable</strong></p>
<pre><code class="language-php">$sortable = new PicoSortable();

$sort1 = new PicoSort('userName', 'asc');
Expand Down Expand Up @@ -5936,6 +5980,17 @@ <h3>Pageable and Sortable</h3>
-&gt;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</code></pre>
<p>or</p>
<pre><code class="language-php">$sortable = PicoSortable::getInstance()
-&gt;add(PicoSort::getInstance()-&gt;sortByUserName(PicoSort::ORDER_TYPE_ASC))
-&gt;add(PicoSort::getInstance()-&gt;sortByEmail(PicoSort::ORDER_TYPE_DESC))
-&gt;add(PicoSort::getInstance()-&gt;sortByPhone(PicoSort::ORDER_TYPE_ASC))
;

$pageable = new PicoPageable(new PicoLimit(0, 100), $sortable);
// offset = 0
/// limit = 100
Expand Down
9 changes: 7 additions & 2 deletions src/Database/PicoSort.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -40,7 +45,7 @@ public function getSortBy()
/**
* Set sort by
*
* @param string $sortBy Sort by
* @param string $sortBy Sort by
*
* @return self
*/
Expand All @@ -64,7 +69,7 @@ public function getSortType()
/**
* Set sort type
*
* @param string $sortType Sort type
* @param string $sortType Sort type
*
* @return self
*/
Expand Down
75 changes: 73 additions & 2 deletions tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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();
Expand Down Expand Up @@ -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'));`
Expand Down

0 comments on commit 5c242f5

Please sign in to comment.