Upgrade to v26 (#172)
* A bunch of new updates from icehrm pro * Push changes to frontend
This commit is contained in:
29
core/src/Classes/Data/DataReader.php
Normal file
29
core/src/Classes/Data/DataReader.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
namespace Classes\Data;
|
||||
|
||||
use Classes\Data\Query\DataQuery;
|
||||
|
||||
class DataReader
|
||||
{
|
||||
public static function getData(DataQuery $query)
|
||||
{
|
||||
$table = $query->getTable();
|
||||
|
||||
$sLimit = " LIMIT " . intval($query->getStartPage()) . ", " . intval($query->getLength());
|
||||
|
||||
$sortData = $query->getSortingData();
|
||||
$data = \Classes\BaseService::getInstance()->getData(
|
||||
$table,
|
||||
$query->getFieldMapping(),
|
||||
json_encode($query->getFilters()),
|
||||
$query->getOrderBy(),
|
||||
$sLimit,
|
||||
json_encode($query->getColumns()),
|
||||
$query->getSearchTerm(),
|
||||
$query->isIsSubOrdinates(),
|
||||
$query->isSkipProfileRestriction(),
|
||||
$sortData
|
||||
);
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
262
core/src/Classes/Data/Query/DataQuery.php
Normal file
262
core/src/Classes/Data/Query/DataQuery.php
Normal file
@@ -0,0 +1,262 @@
|
||||
<?php
|
||||
namespace Classes\Data\Query;
|
||||
|
||||
class DataQuery
|
||||
{
|
||||
protected $table;
|
||||
protected $columns = [];
|
||||
protected $fieldMapping;
|
||||
protected $filters = null;
|
||||
protected $startPage = 0;
|
||||
protected $length = 15;
|
||||
protected $isSubOrdinates = false;
|
||||
protected $skipProfileRestriction = false;
|
||||
protected $sortingEnabled = false;
|
||||
protected $sortColumn;
|
||||
protected $sortOrder = '';
|
||||
protected $searchTerm = null;
|
||||
protected $isLengthSet = false;
|
||||
protected $orderBy = null;
|
||||
|
||||
/**
|
||||
* DataQuery constructor.
|
||||
* @param $table
|
||||
* @param bool $sortingEnabled
|
||||
* @param $sortColumn
|
||||
* @param string $sortOrder
|
||||
*/
|
||||
public function __construct($table, $sortingEnabled = false, $sortColumn = false, $sortOrder = '', $orderBy = null)
|
||||
{
|
||||
$this->table = $table;
|
||||
$this->sortingEnabled = $sortingEnabled;
|
||||
$this->sortColumn = $sortColumn;
|
||||
$this->sortOrder = $sortOrder;
|
||||
$this->orderBy = $orderBy;
|
||||
}
|
||||
|
||||
|
||||
public function addColumn($column)
|
||||
{
|
||||
$this->columns[] = $column;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addFilter($filter)
|
||||
{
|
||||
if ($this->filters === null) {
|
||||
$this->filters = new \stdClass();
|
||||
}
|
||||
$this->filters->{$filter->getName()} = $filter->getValue();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getColumns()
|
||||
{
|
||||
return $this->columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getFieldMapping()
|
||||
{
|
||||
return $this->fieldMapping;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getFilters()
|
||||
{
|
||||
return $this->filters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getStartPage()
|
||||
{
|
||||
return $this->startPage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getLength()
|
||||
{
|
||||
return $this->length;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getSearchTerm()
|
||||
{
|
||||
return $this->searchTerm;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $searchTerm
|
||||
*/
|
||||
public function setSearchTerm($searchTerm)
|
||||
{
|
||||
$this->searchTerm = $searchTerm;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function isIsSubOrdinates()
|
||||
{
|
||||
return $this->isSubOrdinates;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function isSkipProfileRestriction()
|
||||
{
|
||||
return $this->skipProfileRestriction;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getTable()
|
||||
{
|
||||
return $this->table;
|
||||
}
|
||||
|
||||
public function getSortingData()
|
||||
{
|
||||
$data = array();
|
||||
|
||||
$data['sorting'] = $this->sortingEnabled ? '1' : '0';
|
||||
if (!$this->sortingEnabled) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
$data['column'] = $this->sortColumn;
|
||||
$data['order'] = $this->sortOrder;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $length
|
||||
*/
|
||||
public function setLength($length)
|
||||
{
|
||||
$this->length = $length;
|
||||
if ($length > 0) {
|
||||
$this->isLengthSet = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $startPage
|
||||
*/
|
||||
public function setStartPage($startPage)
|
||||
{
|
||||
$this->startPage = $startPage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param boolean $isSubOrdinates
|
||||
*/
|
||||
public function setIsSubOrdinates($isSubOrdinates)
|
||||
{
|
||||
$this->isSubOrdinates = $isSubOrdinates;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isLengthSet(): bool
|
||||
{
|
||||
return $this->isLengthSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $table
|
||||
*/
|
||||
public function setTable($table)
|
||||
{
|
||||
$this->table = $table;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $columns
|
||||
*/
|
||||
public function setColumns(array $columns)
|
||||
{
|
||||
$this->columns = $columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $fieldMapping
|
||||
*/
|
||||
public function setFieldMapping($fieldMapping)
|
||||
{
|
||||
$this->fieldMapping = $fieldMapping;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $filters
|
||||
*/
|
||||
public function setFilters(array $filters)
|
||||
{
|
||||
$this->filters = $filters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $skipProfileRestriction
|
||||
*/
|
||||
public function setSkipProfileRestriction(bool $skipProfileRestriction)
|
||||
{
|
||||
$this->skipProfileRestriction = $skipProfileRestriction;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $sortingEnabled
|
||||
*/
|
||||
public function setSortingEnabled(bool $sortingEnabled)
|
||||
{
|
||||
$this->sortingEnabled = $sortingEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $sortColumn
|
||||
*/
|
||||
public function setSortColumn(bool $sortColumn)
|
||||
{
|
||||
$this->sortColumn = $sortColumn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sortOrder
|
||||
*/
|
||||
public function setSortOrder(string $sortOrder)
|
||||
{
|
||||
$this->sortOrder = $sortOrder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getOrderBy()
|
||||
{
|
||||
return $this->orderBy;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $orderBy
|
||||
*/
|
||||
public function setOrderBy($orderBy)
|
||||
{
|
||||
$this->orderBy = $orderBy;
|
||||
}
|
||||
}
|
||||
39
core/src/Classes/Data/Query/FieldMapping.php
Normal file
39
core/src/Classes/Data/Query/FieldMapping.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
namespace Classes\Data\Query;
|
||||
|
||||
class FieldMapping implements \JsonSerializable
|
||||
{
|
||||
protected $class;
|
||||
protected $idField;
|
||||
protected $nameField;
|
||||
|
||||
/**
|
||||
* FieldMapping constructor.
|
||||
* @param $class
|
||||
* @param $idField
|
||||
* @param $nameField
|
||||
*/
|
||||
public function __construct($class, $idField, $nameField)
|
||||
{
|
||||
$this->class = $class;
|
||||
$this->idField = $idField;
|
||||
$this->nameField = $nameField;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Specify data which should be serialized to JSON
|
||||
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php
|
||||
* @return mixed data which can be serialized by <b>json_encode</b>,
|
||||
* which is a value of any type other than a resource.
|
||||
* @since 5.4.0
|
||||
*/
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return [
|
||||
$this->class,
|
||||
$this->idField,
|
||||
$this->nameField,
|
||||
];
|
||||
}
|
||||
}
|
||||
51
core/src/Classes/Data/Query/Filter.php
Normal file
51
core/src/Classes/Data/Query/Filter.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
namespace Classes\Data\Query;
|
||||
|
||||
class Filter
|
||||
{
|
||||
private $name;
|
||||
private $value;
|
||||
|
||||
/**
|
||||
* Filter constructor.
|
||||
* @param $name
|
||||
* @param $value
|
||||
*/
|
||||
public function __construct($name, $value)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $name
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function setValue($value)
|
||||
{
|
||||
$this->value = $value;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user