mirror of
https://github.com/parsecsv/parsecsv-for-php.git
synced 2026-02-19 08:36:39 +00:00
added enum for sort
This commit is contained in:
12
src/Csv.php
12
src/Csv.php
@@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace ParseCsv;
|
namespace ParseCsv;
|
||||||
|
|
||||||
|
use ParseCsv\enums\SortEnum;
|
||||||
use ParseCsv\extensions\DatatypeTrait;
|
use ParseCsv\extensions\DatatypeTrait;
|
||||||
|
|
||||||
class Csv {
|
class Csv {
|
||||||
@@ -124,7 +125,7 @@ class Csv {
|
|||||||
*
|
*
|
||||||
* @var string|null
|
* @var string|null
|
||||||
*/
|
*/
|
||||||
public $sort_type = null;
|
public $sort_type = SortEnum::SORT_TYPE_REGULAR;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delimiter
|
* Delimiter
|
||||||
@@ -726,14 +727,7 @@ class Csv {
|
|||||||
|
|
||||||
$this->titles = $head;
|
$this->titles = $head;
|
||||||
if (!empty($this->sort_by)) {
|
if (!empty($this->sort_by)) {
|
||||||
$sort_type = SORT_REGULAR;
|
$this->sort_reverse ? krsort($rows, $this->sort_type) : ksort($rows, $this->sort_type);
|
||||||
if ($this->sort_type == 'numeric') {
|
|
||||||
$sort_type = SORT_NUMERIC;
|
|
||||||
} elseif ($this->sort_type == 'string') {
|
|
||||||
$sort_type = SORT_STRING;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->sort_reverse ? krsort($rows, $sort_type) : ksort($rows, $sort_type);
|
|
||||||
|
|
||||||
if ($this->offset !== null || $this->limit !== null) {
|
if ($this->offset !== null || $this->limit !== null) {
|
||||||
$rows = array_slice($rows, ($this->offset === null ? 0 : $this->offset), $this->limit, true);
|
$rows = array_slice($rows, ($this->offset === null ? 0 : $this->offset), $this->limit, true);
|
||||||
|
|||||||
18
src/enums/SortEnum.php
Normal file
18
src/enums/SortEnum.php
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: sgorzaly
|
||||||
|
* Date: 22.02.18
|
||||||
|
* Time: 20:24
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace ParseCsv\enums;
|
||||||
|
|
||||||
|
|
||||||
|
class SortEnum {
|
||||||
|
const SORT_TYPE_REGULAR = SORT_REGULAR;
|
||||||
|
|
||||||
|
const SORT_TYPE_NUMERIC = SORT_NUMERIC;
|
||||||
|
|
||||||
|
const SORT_TYPE_STRING = SORT_STRING;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user