add column unique numbering scheme, more efficient selects

This commit is contained in:
2018-08-04 19:57:59 +02:00
parent 69bda25bbb
commit fabc3ad24e
23 changed files with 452 additions and 173 deletions
+32 -15
View File
@@ -11,9 +11,10 @@ use MightyPork\Utils\Utils;
/**
* Helper class representing one column in a data table.
*
* @property-read string $id
* @property-read string $type
* @property-read string $name
* @property-read string $title
* @property-read string $type
*/
class Column implements JsonSerializable
{
@@ -21,9 +22,10 @@ class Column implements JsonSerializable
'int', 'bool', 'float', 'string'
];
private $id;
private $type;
private $name;
private $title;
private $type;
public static function columnsFromJson($columns)
{
@@ -36,13 +38,13 @@ class Column implements JsonSerializable
}, $columns);
}
public function __get($name)
/**
* Set column ID
* @param string $id - GCID
*/
public function setID($id)
{
if (property_exists($this, $name)) {
return $this->$name;
}
throw new NotApplicableException("No such column property");
$this->id = $id;
}
/**
@@ -52,18 +54,32 @@ class Column implements JsonSerializable
*/
public function __construct($obj)
{
$b = new \objBag($obj);
$b = objBag($obj);
if (!$b->has('name')) throw new NotApplicableException('Missing name in column');
if (!$b->has('type')) throw new NotApplicableException('Missing type in column');
if ($b->name[0] == '_') { // global row ID
throw new NotApplicableException("Column name can't start with underscore.");
}
if (!in_array($b->type, self::colTypes)) {
throw new NotApplicableException("\"$b->type\" is not a valid column type.");
}
$this->id = $b->get('id', null);
$this->name = $b->name;
$this->title = $b->title;
$this->type = $b->type;
$this->title = $b->title ?: $b->name;
}
if ($this->name == '_grid') { // global row ID
throw new NotApplicableException("_grid is a reserved column name.");
public function __get($name)
{
if (property_exists($this, $name)) {
return $this->$name;
}
if (!in_array($this->type, self::colTypes)) {
throw new NotApplicableException("\"$this->type\" is not a valid column type.");
}
throw new NotApplicableException("No such column property: $name");
}
/**
@@ -72,6 +88,7 @@ class Column implements JsonSerializable
public function toArray()
{
return [
'id' => $this->id,
'name' => $this->name,
'title' => $this->title,
'type' => $this->type,