all models into model folder
This commit is contained in:
parent
98f50a2b6f
commit
6990469c67
46 changed files with 325 additions and 203 deletions
|
@ -1,8 +1,7 @@
|
|||
<?php
|
||||
namespace App\Library\Xml;
|
||||
|
||||
use App\Library\Util\Searchtypes;
|
||||
use App\Dataset;
|
||||
use App\Models\Dataset;
|
||||
|
||||
/**
|
||||
* Conf short summary.
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
namespace App\Library\Xml;
|
||||
|
||||
use App\Models\Title;
|
||||
use App\Models\License;
|
||||
use App\Models\Person;
|
||||
use App\Models\File;
|
||||
|
||||
/**
|
||||
* DatasetExtension short summary.
|
||||
|
@ -13,7 +16,7 @@ use App\Models\Title;
|
|||
*/
|
||||
trait DatasetExtension
|
||||
{
|
||||
protected $_externalFields = array(
|
||||
protected $externalFields = array(
|
||||
'TitleMain' => array(
|
||||
'model' => Title::class,
|
||||
'options' => array('type' => 'main'),
|
||||
|
@ -25,13 +28,13 @@ trait DatasetExtension
|
|||
'fetch' => 'eager'
|
||||
),
|
||||
'Licence' => array(
|
||||
'model' => 'App\License',
|
||||
'model' => License::class,
|
||||
'through' => 'link_documents_licences',
|
||||
'relation' => 'licenses',
|
||||
'fetch' => 'eager'
|
||||
),
|
||||
'PersonAuthor' => array(
|
||||
'model' => 'App\Person',
|
||||
'model' => Person::class,
|
||||
'through' => 'link_documents_persons',
|
||||
'pivot' => array('role' => 'author'),
|
||||
//'sort_order' => array('sort_order' => 'ASC'), // <-- We need a sorted authors list.
|
||||
|
@ -40,7 +43,7 @@ trait DatasetExtension
|
|||
'fetch' => 'eager'
|
||||
),
|
||||
'PersonContributor' => array(
|
||||
'model' => 'App\Person',
|
||||
'model' => Person::class,
|
||||
'through' => 'link_documents_persons',
|
||||
'pivot' => array('role' => 'contributor'),
|
||||
// 'sort_order' => array('sort_order' => 'ASC'), // <-- We need a sorted authors list.
|
||||
|
@ -49,15 +52,15 @@ trait DatasetExtension
|
|||
'fetch' => 'eager'
|
||||
),
|
||||
'File' => array(
|
||||
'model' => 'App\Models\File',
|
||||
'model' => File::class,
|
||||
'relation' => 'files',
|
||||
'fetch' => 'eager'
|
||||
),
|
||||
);
|
||||
|
||||
protected $_internalFields = array();
|
||||
protected $internalFields = array();
|
||||
|
||||
protected $_fields = array();
|
||||
protected $fields = array();
|
||||
|
||||
protected function _initFields()
|
||||
{
|
||||
|
@ -90,7 +93,7 @@ trait DatasetExtension
|
|||
$this->addField($field);
|
||||
}
|
||||
|
||||
foreach (array_keys($this->_externalFields) as $fieldname) {
|
||||
foreach (array_keys($this->externalFields) as $fieldname) {
|
||||
$field = new Field($fieldname);
|
||||
$field->setMultiplicity('*');
|
||||
$this->addField($field);
|
||||
|
@ -112,21 +115,21 @@ trait DatasetExtension
|
|||
|
||||
/**
|
||||
* Get a list of all fields attached to the model. Filters all fieldnames
|
||||
* that are defined to be inetrnal in $_internalFields.
|
||||
* that are defined to be inetrnal in $internalFields.
|
||||
*
|
||||
* @see Opus_Model_Abstract::_internalFields
|
||||
* @see Opus_Model_Abstract::internalFields
|
||||
* @return array List of fields
|
||||
*/
|
||||
public function describe()
|
||||
{
|
||||
return array_diff(array_keys($this->_fields), $this->_internalFields);
|
||||
return array_diff(array_keys($this->fields), $this->internalFields);
|
||||
}
|
||||
|
||||
public function addField(Field $field)
|
||||
{
|
||||
$fieldname = $field->getName();
|
||||
if (isset($fieldname, $this->_externalFields[$fieldname])) {
|
||||
$options = $this->_externalFields[$fieldname];
|
||||
if (isset($fieldname, $this->externalFields[$fieldname])) {
|
||||
$options = $this->externalFields[$fieldname];
|
||||
|
||||
// set ValueModelClass if a through option is given
|
||||
if (isset($options['model'])) {
|
||||
|
@ -139,7 +142,7 @@ trait DatasetExtension
|
|||
//}
|
||||
}
|
||||
|
||||
$this->_fields[$field->getName()] = $field;
|
||||
$this->fields[$field->getName()] = $field;
|
||||
$field->setOwningModelClass(get_class($this));
|
||||
return $this;
|
||||
}
|
||||
|
@ -157,8 +160,8 @@ trait DatasetExtension
|
|||
*/
|
||||
protected function _getField($name)
|
||||
{
|
||||
if (isset($this->_fields[$name])) {
|
||||
return $this->_fields[$name];
|
||||
if (isset($this->fields[$name])) {
|
||||
return $this->fields[$name];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
@ -167,11 +170,11 @@ trait DatasetExtension
|
|||
public function fetchValues()
|
||||
{
|
||||
$this->_initFields();
|
||||
foreach ($this->_fields as $fieldname => $field) {
|
||||
if (isset($this->_externalFields[$fieldname]) === true) {
|
||||
foreach ($this->fields as $fieldname => $field) {
|
||||
if (isset($this->externalFields[$fieldname]) === true) {
|
||||
$fetchmode = 'lazy';
|
||||
if (isset($this->_externalFields[$fieldname]['fetch']) === true) {
|
||||
$fetchmode = $this->_externalFields[$fieldname]['fetch'];
|
||||
if (isset($this->externalFields[$fieldname]['fetch']) === true) {
|
||||
$fetchmode = $this->externalFields[$fieldname]['fetch'];
|
||||
}
|
||||
|
||||
if ($fetchmode === 'lazy') {
|
||||
|
@ -210,7 +213,7 @@ trait DatasetExtension
|
|||
|
||||
protected function _loadExternal($fieldname)
|
||||
{
|
||||
$field = $this->_fields[$fieldname];
|
||||
$field = $this->fields[$fieldname];
|
||||
|
||||
$modelclass = $field->getLinkModelClass();
|
||||
if (!isset($modelclass)) {
|
||||
|
@ -223,8 +226,8 @@ trait DatasetExtension
|
|||
$select = $tableclass->query();//->where("document_id", $this->id);;
|
||||
|
||||
// If any declared constraints, add them to query
|
||||
if (isset($this->_externalFields[$fieldname]['options'])) {
|
||||
$options = $this->_externalFields[$fieldname]['options'];
|
||||
if (isset($this->externalFields[$fieldname]['options'])) {
|
||||
$options = $this->externalFields[$fieldname]['options'];
|
||||
foreach ($options as $column => $value) {
|
||||
$select = $select->where($column, $value);
|
||||
}
|
||||
|
@ -236,17 +239,17 @@ trait DatasetExtension
|
|||
$datasetId = $this->id;
|
||||
|
||||
$rows = array();
|
||||
if (isset($this->_externalFields[$fieldname]['through'])) {
|
||||
$relation = $this->_externalFields[$fieldname]['relation'];
|
||||
if (isset($this->externalFields[$fieldname]['through'])) {
|
||||
$relation = $this->externalFields[$fieldname]['relation'];
|
||||
//$rows = $select->datasets
|
||||
////->orderBy('name')
|
||||
//->get();
|
||||
//$licenses = $select->with('datasets')->get();
|
||||
//$rows = $supplier->datasets;
|
||||
$rows = $this->{$relation};
|
||||
//if (isset($this->_externalFields[$fieldname]['pivot']))
|
||||
//if (isset($this->externalFields[$fieldname]['pivot']))
|
||||
//{
|
||||
// $pivArray = $this->_externalFields[$fieldname]['pivot'];
|
||||
// $pivArray = $this->externalFields[$fieldname]['pivot'];
|
||||
// $rows = $rows->wherePivot('role', $pivArray['role']);
|
||||
//}
|
||||
} else {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
namespace App\Library\Xml;
|
||||
|
||||
use App\Dataset;
|
||||
use App\Models\Dataset;
|
||||
use DOMDocument;
|
||||
|
||||
/**
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
*/
|
||||
namespace App\Library\Xml;
|
||||
|
||||
use App\XmlCache;
|
||||
use App\Models\XmlCache;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class XmlModel
|
||||
|
@ -24,19 +24,19 @@ class XmlModel
|
|||
* Holds current configuration.
|
||||
* @var Conf
|
||||
*/
|
||||
private $_config = null;
|
||||
private $config = null;
|
||||
|
||||
/**
|
||||
* Holds current xml strategy object.
|
||||
* @var Strategy
|
||||
*/
|
||||
private $_strategy = null;
|
||||
private $strategy = null;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* @var XmlCache
|
||||
*/
|
||||
private $_cache = null;
|
||||
private $cache = null;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -45,9 +45,9 @@ class XmlModel
|
|||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->_strategy = new Strategy();// Opus_Model_Xml_Version1;
|
||||
$this->_config = new Conf();
|
||||
$this->_strategy->setup($this->_config);
|
||||
$this->strategy = new Strategy();// Opus_Model_Xml_Version1;
|
||||
$this->config = new Conf();
|
||||
$this->strategy->setup($this->config);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -59,8 +59,8 @@ class XmlModel
|
|||
*/
|
||||
public function setStrategy(Strategy $strategy)
|
||||
{
|
||||
$this->_strategy = $strategy;
|
||||
$this->_strategy->setup($this->_config);
|
||||
$this->strategy = $strategy;
|
||||
$this->strategy->setup($this->config);
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -73,7 +73,7 @@ class XmlModel
|
|||
*/
|
||||
public function setXmlCache(XmlCache $cache)
|
||||
{
|
||||
$this->_cache = $cache;
|
||||
$this->cache = $cache;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -84,19 +84,19 @@ class XmlModel
|
|||
*/
|
||||
public function getXmlCache()
|
||||
{
|
||||
return $this->_cache;
|
||||
return $this->cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Model for XML generation.
|
||||
*
|
||||
* @param \App\Dataset $model Model to serialize.
|
||||
* @param \App\Models\Dataset $model Model to serialize.
|
||||
*
|
||||
* @return XmlModel Fluent interface.
|
||||
*/
|
||||
public function setModel($model)
|
||||
{
|
||||
$this->_config->model = $model;
|
||||
$this->config->model = $model;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -107,7 +107,7 @@ class XmlModel
|
|||
*/
|
||||
public function excludeEmptyFields()
|
||||
{
|
||||
$this->_config->excludeEmpty = true;
|
||||
$this->config->excludeEmpty = true;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -119,7 +119,7 @@ class XmlModel
|
|||
*/
|
||||
public function getDomDocument()
|
||||
{
|
||||
$dataset = $this->_config->model;
|
||||
$dataset = $this->config->model;
|
||||
|
||||
$domDocument = $this->getDomDocumentFromXmlCache();
|
||||
if (!is_null($domDocument)) {
|
||||
|
@ -127,19 +127,19 @@ class XmlModel
|
|||
}
|
||||
|
||||
//create xml:
|
||||
$domDocument = $this->_strategy->getDomDocument();
|
||||
$domDocument = $this->strategy->getDomDocument();
|
||||
//if caching is not desired, return domDocument
|
||||
if (is_null($this->_cache)) {
|
||||
if (is_null($this->cache)) {
|
||||
return $domDocument;
|
||||
} else {
|
||||
//create cache relation
|
||||
$this->_cache->fill(array(
|
||||
$this->cache->fill(array(
|
||||
'document_id' => $dataset->id,
|
||||
'xml_version' => (int)$this->_strategy->getVersion(),
|
||||
'xml_version' => (int)$this->strategy->getVersion(),
|
||||
'server_date_modified' => $dataset->server_date_modified,
|
||||
'xml_data' => $domDocument->saveXML()
|
||||
));
|
||||
$this->_cache->save();
|
||||
$this->cache->save();
|
||||
|
||||
Log::debug(__METHOD__ . ' cache refreshed for ' . get_class($dataset) . '#' . $dataset->id);
|
||||
return $domDocument;
|
||||
|
@ -155,15 +155,15 @@ class XmlModel
|
|||
*/
|
||||
private function getDomDocumentFromXmlCache()
|
||||
{
|
||||
$dataset = $this->_config->model;
|
||||
if (null === $this->_cache) {
|
||||
$dataset = $this->config->model;
|
||||
if (null === $this->cache) {
|
||||
//$logger->debug(__METHOD__ . ' skipping cache for ' . get_class($model));
|
||||
Log::debug(__METHOD__ . ' skipping cache for ' . get_class($dataset));
|
||||
return null;
|
||||
}
|
||||
//$cached = $this->_cache->hasValidEntry(
|
||||
//$cached = $this->cache->hasValidEntry(
|
||||
// $dataset->id,
|
||||
// (int) $this->_strategy->getVersion(),
|
||||
// (int) $this->strategy->getVersion(),
|
||||
// $dataset->server_date_modified
|
||||
//);
|
||||
|
||||
|
|
Loading…
Add table
editor.link_modal.header
Reference in a new issue