mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-10 05:58:42 +00:00
Preparing for relation types
This commit is contained in:
parent
b9c9b9ed1c
commit
7801e34d82
|
|
@ -722,11 +722,24 @@ abstract class DataMapperAbstract implements DataMapperInterface
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
@todo: Implement RelationType::NEWEST!!!
|
||||||
|
Get newest hasMany only (if object doesn't have date use id!)
|
||||||
|
|
||||||
|
SELECT c.*, p1.*
|
||||||
|
FROM customer c
|
||||||
|
JOIN purchase p1 ON (c.id = p1.customer_id)
|
||||||
|
LEFT OUTER JOIN purchase p2 ON (c.id = p2.customer_id AND
|
||||||
|
(p1.date < p2.date OR p1.date = p2.date AND p1.id < p2.id))
|
||||||
|
WHERE p2.id IS NULL;
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get object.
|
* Get object.
|
||||||
*
|
*
|
||||||
* @param mixed $primaryKey Key
|
* @param mixed $primaryKey Key
|
||||||
* @param bool $relations Load relations
|
* @param int $relations Load relations
|
||||||
* @param mixed $fill Object to fill
|
* @param mixed $fill Object to fill
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
|
|
@ -734,7 +747,7 @@ abstract class DataMapperAbstract implements DataMapperInterface
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
*/
|
*/
|
||||||
public function get($primaryKey, bool $relations = true, $fill = null)
|
public function get($primaryKey, int $relations = RelationType::ALL, $fill = null)
|
||||||
{
|
{
|
||||||
$primaryKey = (array) $primaryKey;
|
$primaryKey = (array) $primaryKey;
|
||||||
$fill = (array) $fill;
|
$fill = (array) $fill;
|
||||||
|
|
@ -755,14 +768,14 @@ abstract class DataMapperAbstract implements DataMapperInterface
|
||||||
$hasOne = count(static::$hasOne) > 0;
|
$hasOne = count(static::$hasOne) > 0;
|
||||||
$isExtending = count(static::$isExtending) > 0;
|
$isExtending = count(static::$isExtending) > 0;
|
||||||
|
|
||||||
if (($relations && ($hasMany || $hasOne)) || $isExtending) {
|
if (($relations !== RelationType::NONE && ($hasMany || $hasOne)) || $isExtending) {
|
||||||
foreach ($primaryKey as $key) {
|
foreach ($primaryKey as $key) {
|
||||||
if ($isExtending) {
|
if ($isExtending) {
|
||||||
$this->populateExtending($obj[$key], $relations);
|
$this->populateExtending($obj[$key], $relations);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* loading relations from relations table and populating them and then adding them to the object */
|
/* loading relations from relations table and populating them and then adding them to the object */
|
||||||
if ($relations) {
|
if ($relations > 0) {
|
||||||
if ($hasMany) {
|
if ($hasMany) {
|
||||||
$this->populateManyToMany($this->getManyRaw($key), $obj[$key]);
|
$this->populateManyToMany($this->getManyRaw($key), $obj[$key]);
|
||||||
}
|
}
|
||||||
|
|
@ -777,7 +790,7 @@ abstract class DataMapperAbstract implements DataMapperInterface
|
||||||
return count($obj) === 1 ? reset($obj) : $obj;
|
return count($obj) === 1 ? reset($obj) : $obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function populateExtending($obj, bool $relations = true)
|
public function populateExtending($obj, int $relations = RelationType::ALL)
|
||||||
{
|
{
|
||||||
$reflectionClass = new \ReflectionClass(get_class($obj));
|
$reflectionClass = new \ReflectionClass(get_class($obj));
|
||||||
|
|
||||||
|
|
|
||||||
38
DataStorage/Database/RelationType.php
Normal file
38
DataStorage/Database/RelationType.php
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Orange Management
|
||||||
|
*
|
||||||
|
* PHP Version 7.0
|
||||||
|
*
|
||||||
|
* @category TBD
|
||||||
|
* @package TBD
|
||||||
|
* @author OMS Development Team <dev@oms.com>
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
* @copyright 2013 Dennis Eichhorn
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @version 1.0.0
|
||||||
|
* @link http://orange-management.com
|
||||||
|
*/
|
||||||
|
namespace phpOMS\DataStorage\Database;
|
||||||
|
|
||||||
|
use phpOMS\Datatypes\Enum;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Database type enum.
|
||||||
|
*
|
||||||
|
* Database types that are supported by the application
|
||||||
|
*
|
||||||
|
* @category Framework
|
||||||
|
* @package phpOMS\DataStorage\Database
|
||||||
|
* @author OMS Development Team <dev@oms.com>
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @link http://orange-management.com
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
abstract class RelationType extends Enum
|
||||||
|
{
|
||||||
|
const NONE = 0;
|
||||||
|
const NEWEST = 1;
|
||||||
|
const ALL = 2;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user