-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
27887f8
commit 6ed585f
Showing
56 changed files
with
5,420 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
<?php | ||
|
||
namespace IanRothmann\RocketDataLaravel\Display; | ||
|
||
class DisplayDefinition implements \JsonSerializable | ||
{ | ||
|
||
protected $query, $queryObjectType, $valueModifierClosure; | ||
|
||
public $pageSizeOptions=[20,50,100], $defaultPageSize=20, $recordId; | ||
|
||
/** | ||
* @var QueryableDisplayField[] | ||
*/ | ||
public $fields=[]; | ||
|
||
public function __construct($query=null) | ||
{ | ||
$this->setQuery($query); | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getQuery() | ||
{ | ||
return $this->query; | ||
} | ||
|
||
/** | ||
* @param mixed $query | ||
* @return DisplayDefinition | ||
*/ | ||
public function setQuery($query) | ||
{ | ||
$this->query = $query; | ||
$this->queryObjectType=get_class($query); | ||
return $this; | ||
} | ||
|
||
public function validateFieldAgainstQueryType($field){ | ||
if($this->isModelDisplayField($field)&&$this->queryObjectType=='Illuminate\Database\Query\Builder'){ | ||
throw new \Exception("Cannot use ModelDisplayField with a Illuminate\Database\Query\Builder based query. The base model instance would not be inferred during query and the relationship queries would fail. Use QueryableDisplayField instead."); | ||
} | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getRecordId() | ||
{ | ||
return $this->recordId; | ||
} | ||
|
||
/** | ||
* @param mixed $recordId | ||
* @return DisplayDefinition | ||
*/ | ||
public function setRecordId($recordId) | ||
{ | ||
$this->recordId = $recordId; | ||
return $this; | ||
} | ||
|
||
|
||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getPageSizeOptions() | ||
{ | ||
return $this->pageSizeOptions; | ||
} | ||
|
||
/** | ||
* @param array $pageSizeOptions | ||
* @param int $defaultPageSize | ||
* @return DisplayDefinition | ||
*/ | ||
public function setPageSizeOptions($pageSizeOptions,$defaultPageSize) | ||
{ | ||
$this->pageSizeOptions = $pageSizeOptions; | ||
$this->defaultPageSize = $defaultPageSize; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getDefaultPageSize() | ||
{ | ||
return $this->defaultPageSize; | ||
} | ||
|
||
|
||
/** | ||
* @param QueryableDisplayField $field | ||
* @return $this | ||
*/ | ||
public function addField(QueryableDisplayField $field){ | ||
$this->validateFieldAgainstQueryType($field); | ||
$this->fields[$field->getFieldId()]=$field; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @param \Closure $valueModifierClosure | ||
*/ | ||
public function setValueModifierClosure($valueModifierClosure) | ||
{ | ||
$this->valueModifierClosure = $valueModifierClosure; | ||
} | ||
|
||
/** | ||
* @return \Closure | ||
*/ | ||
public function getValueModifierClosure() | ||
{ | ||
return $this->valueModifierClosure; | ||
} | ||
|
||
|
||
/** | ||
* @param string $fieldId | ||
* @return QueryableDisplayField | ||
*/ | ||
public function getField($fieldId){ | ||
return $this->fields[$fieldId]; | ||
} | ||
|
||
/** | ||
* @return QueryableDisplayField[] | ||
*/ | ||
public function getFields(){ | ||
return array_values($this->fields); | ||
} | ||
|
||
private function isModelDisplayField($field){ | ||
return $field instanceof ModelDisplayField; | ||
} | ||
|
||
public function getDefinedRelationships(){ | ||
$relationships=[]; | ||
/** | ||
* @var ModelDisplayField $field | ||
*/ | ||
foreach ($this->fields as $field) { | ||
if($this->isModelDisplayField($field)){ | ||
$relationships=array_merge($relationships,$field->getAllRelationshipPaths()); | ||
} | ||
} | ||
|
||
return $relationships; | ||
} | ||
|
||
public function jsonSerialize(){ | ||
return $this; | ||
} | ||
|
||
|
||
public function __toString(){ | ||
return json_encode($this); | ||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
|
||
namespace IanRothmann\RocketDataLaravel\Display; | ||
|
||
use IanRothmann\RocketDataLaravel\Generic\Field; | ||
|
||
class DisplayField extends Field | ||
{ | ||
protected $fieldId, $fieldAccessPath=[], $levelOfDetail=1, $width=50; | ||
|
||
/** | ||
* DisplayField constructor. | ||
*/ | ||
public function __construct($fieldName, $dataType, $label) | ||
{ | ||
parent::__construct($fieldName, $dataType, $label); | ||
$this->fieldId=$fieldName; | ||
$this->fieldAccessPath=[$fieldName]; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getWidth() | ||
{ | ||
return $this->width; | ||
} | ||
|
||
/** | ||
* @param int $width | ||
* @return DisplayField | ||
*/ | ||
public function setWidth($width) | ||
{ | ||
$this->width = $width; | ||
return $this; | ||
} | ||
|
||
|
||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getFieldId() | ||
{ | ||
return $this->fieldId; | ||
} | ||
|
||
/** | ||
* @param string $fieldId | ||
* @return DisplayField | ||
*/ | ||
public function setFieldId($fieldId) | ||
{ | ||
$this->fieldId = $fieldId; | ||
return $this; | ||
} | ||
|
||
public function updateFieldIdFromAccessPath(){ | ||
$this->setFieldId(implode('.',$this->fieldAccessPath)); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getFieldAccessPath() | ||
{ | ||
return $this->fieldAccessPath; | ||
} | ||
|
||
/** | ||
* @param array $fieldAccessPath | ||
* @return DisplayField | ||
*/ | ||
public function setFieldAccessPath($fieldAccessPath) | ||
{ | ||
$this->fieldAccessPath = $fieldAccessPath; | ||
$this->updateFieldIdFromAccessPath(); | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getLevelOfDetail() | ||
{ | ||
return $this->levelOfDetail; | ||
} | ||
|
||
/** | ||
* @param int $levelOfDetail | ||
* @return DisplayField | ||
*/ | ||
public function setLevelOfDetail($levelOfDetail) | ||
{ | ||
$this->levelOfDetail = $levelOfDetail; | ||
return $this; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: ian | ||
* Date: 2017/06/24 | ||
* Time: 5:35 AM | ||
*/ | ||
|
||
namespace IanRothmann\RocketDataLaravel\Display; | ||
|
||
|
||
class ModelDisplayField extends QueryableDisplayField | ||
{ | ||
|
||
protected $relationalQuery=false, $relationshipNames=[],$isAccessorField=false; | ||
|
||
/** | ||
* ModelDisplayField constructor. | ||
*/ | ||
public function __construct($fieldName, $dataType, $label) | ||
{ | ||
parent::__construct($fieldName, $dataType, $label); | ||
} | ||
|
||
protected function updateFieldPath(){ | ||
$this->setFieldAccessPath(array_merge($this->relationshipNames,[$this->fieldName])); | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function isRelationalQuery() | ||
{ | ||
return $this->relationalQuery; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getRelationshipNames() | ||
{ | ||
return $this->relationshipNames; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getAllRelationshipPaths(){ | ||
$path=''; | ||
$pathArr=[]; | ||
foreach ($this->relationshipNames as $relationshipName){ | ||
$path==''?$path=$relationshipName:$path.='.'.$relationshipName; | ||
$pathArr[]=$path; | ||
} | ||
return $pathArr; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getRelationshipPath(){ | ||
return implode('.',$this->relationshipNames); | ||
} | ||
|
||
/** | ||
* @param $relationshipName | ||
* @return $this | ||
*/ | ||
public function addRelationship($relationshipName){ | ||
$this->relationshipNames[]=$relationshipName; | ||
$this->relationalQuery=true; | ||
$this->canOrder=false; | ||
$this->updateFieldPath(); | ||
return $this; | ||
} | ||
|
||
/** | ||
* @param array $relationshipNames | ||
* @return QueryableDisplayField | ||
*/ | ||
public function setRelationshipNames($relationshipNames) | ||
{ | ||
$this->relationshipNames = $relationshipNames; | ||
$this->relationalQuery=true; | ||
$this->canOrder=false; | ||
$this->updateFieldPath(); | ||
return $this; | ||
} | ||
|
||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function isAccessorField() | ||
{ | ||
return $this->isAccessorField; | ||
} | ||
|
||
/** | ||
* @param bool $isAccessorField | ||
* @return QueryableDisplayField | ||
*/ | ||
public function setIsAccessorField($isAccessorField) | ||
{ | ||
$this->isAccessorField = $isAccessorField; | ||
return $this; | ||
} | ||
} |
Oops, something went wrong.