init
This commit is contained in:
66
mysyde/common/traits/genericDBModelTrait.php
Normal file
66
mysyde/common/traits/genericDBModelTrait.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
namespace DynCom\mysyde\common\traits;
|
||||
use DynCom\mysyde\common\interfaces\Entity;
|
||||
use DynCom\mysyde\common\interfaces\ModelDBConfigInterface;
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Micha
|
||||
* Date: 19.01.2015
|
||||
* Time: 00:17
|
||||
*/
|
||||
|
||||
trait genericDBModelTrait {
|
||||
|
||||
use arrayMappableTrait;
|
||||
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* @param ModelDBConfigInterface $config
|
||||
*/
|
||||
public function __construct( ModelDBConfigInterface $config ) {
|
||||
$this->config = $config;#TEST2
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Entity
|
||||
*/
|
||||
public function getNullObject() {
|
||||
return new static($this->config);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|null
|
||||
*/
|
||||
public function getID() {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \DynCom\mysyde\common\interfaces\ModelDBConfigInterface
|
||||
*/
|
||||
public function getConfig() {
|
||||
return $this->config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getAltPrimaryFieldNames() {
|
||||
return $this->config->getAltPrimary();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getAltPrimaryFieldValues() {
|
||||
$arr = [];
|
||||
$names = $this->getAltPrimaryFieldNames();
|
||||
foreach($names as $name) {
|
||||
$arr[$name] = $this->$name;
|
||||
}
|
||||
return $arr;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user