php-censor/src/PHPCensor/Model/Base/BuildMetaBase.php

410 lines
8.9 KiB
PHP
Raw Normal View History

<?php
/**
* BuildMeta base model for table: build_meta
*/
2016-07-19 20:28:11 +02:00
namespace PHPCensor\Model\Base;
2016-07-19 20:28:11 +02:00
use PHPCensor\Model;
2013-10-10 02:01:06 +02:00
use b8\Store\Factory;
2016-07-19 20:28:11 +02:00
use PHPCensor\Model\Project;
use PHPCensor\Model\Build;
/**
* BuildMeta Base Model
*/
class BuildMetaBase extends Model
{
/**
* @var array
*/
2016-04-21 06:58:09 +02:00
public static $sleepable = [];
/**
* @var string
*/
protected $tableName = 'build_meta';
/**
* @var string
*/
protected $modelName = 'BuildMeta';
/**
* @var array
*/
2016-04-21 06:58:09 +02:00
protected $data = [
'id' => null,
2013-10-08 08:45:20 +02:00
'project_id' => null,
2016-04-21 06:58:09 +02:00
'build_id' => null,
'meta_key' => null,
'meta_value' => null,
2016-04-21 06:58:09 +02:00
];
/**
* @var array
*/
2016-04-21 06:58:09 +02:00
protected $getters = [
2013-10-10 02:01:06 +02:00
// Direct property getters:
2016-04-21 06:58:09 +02:00
'id' => 'getId',
2013-10-08 08:45:20 +02:00
'project_id' => 'getProjectId',
2016-04-21 06:58:09 +02:00
'build_id' => 'getBuildId',
'meta_key' => 'getMetaKey',
'meta_value' => 'getMetaValue',
2013-10-10 02:01:06 +02:00
// Foreign key getters:
2016-04-21 06:58:09 +02:00
'Project' => 'getProject',
'Build' => 'getBuild',
];
/**
* @var array
*/
2016-04-21 06:58:09 +02:00
protected $setters = [
2013-10-10 02:01:06 +02:00
// Direct property setters:
2016-04-21 06:58:09 +02:00
'id' => 'setId',
2013-10-08 08:45:20 +02:00
'project_id' => 'setProjectId',
2016-04-21 06:58:09 +02:00
'build_id' => 'setBuildId',
'meta_key' => 'setMetaKey',
'meta_value' => 'setMetaValue',
2013-10-10 02:01:06 +02:00
// Foreign key setters:
2016-04-21 06:58:09 +02:00
'Project' => 'setProject',
'Build' => 'setBuild',
];
/**
* @var array
*/
2016-04-21 06:58:09 +02:00
public $columns = [
'id' => [
'type' => 'int',
'length' => 10,
'primary_key' => true,
'auto_increment' => true,
2016-04-21 06:58:09 +02:00
'default' => null,
],
'project_id' => [
'type' => 'int',
'length' => 11,
'default' => null,
2016-04-21 06:58:09 +02:00
],
'build_id' => [
'type' => 'int',
'length' => 11,
'default' => null,
2016-04-21 06:58:09 +02:00
],
'meta_key' => [
'type' => 'varchar',
'length' => 250,
2014-02-25 17:43:06 +01:00
'default' => null,
2016-04-21 06:58:09 +02:00
],
'meta_value' => [
'type' => 'mediumtext',
'default' => null,
2016-04-21 06:58:09 +02:00
],
];
/**
* @var array
*/
2016-04-21 06:58:09 +02:00
public $indexes = [
'PRIMARY' => ['unique' => true, 'columns' => 'id'],
'idx_meta_id' => ['unique' => true, 'columns' => 'build_id, meta_key'],
'project_id' => ['columns' => 'project_id'],
];
/**
* @var array
*/
2016-04-21 06:58:09 +02:00
public $foreignKeys = [
'build_meta_ibfk_1' => [
'local_col' => 'project_id',
'update' => 'CASCADE',
'delete' => 'CASCADE',
'table' => 'project',
'col' => 'id'
],
'fk_meta_build_id' => [
'local_col' => 'build_id',
'update' => 'CASCADE',
'delete' => 'CASCADE',
'table' => 'build',
'col' => 'id'
],
];
/**
* Get the value of Id / id.
*
* @return int
*/
public function getId()
{
$rtn = $this->data['id'];
return $rtn;
}
2013-10-08 08:45:20 +02:00
/**
* Get the value of ProjectId / project_id.
*
* @return int
*/
2013-10-08 08:45:20 +02:00
public function getProjectId()
{
$rtn = $this->data['project_id'];
2013-10-08 08:45:20 +02:00
return $rtn;
}
/**
* Get the value of BuildId / build_id.
*
* @return int
*/
public function getBuildId()
{
$rtn = $this->data['build_id'];
return $rtn;
}
/**
* Get the value of MetaKey / meta_key.
*
* @return string
*/
public function getMetaKey()
{
$rtn = $this->data['meta_key'];
return $rtn;
}
/**
* Get the value of MetaValue / meta_value.
*
* @return string
*/
public function getMetaValue()
{
$rtn = $this->data['meta_value'];
return $rtn;
}
/**
* Set the value of Id / id.
*
* Must not be null.
* @param $value int
*/
public function setId($value)
{
$this->_validateNotNull('Id', $value);
$this->_validateInt('Id', $value);
2013-10-10 02:01:06 +02:00
2013-10-08 08:45:20 +02:00
if ($this->data['id'] === $value) {
return;
}
$this->data['id'] = $value;
$this->_setModified('id');
}
/**
* Set the value of ProjectId / project_id.
*
* Must not be null.
* @param $value int
*/
2013-10-08 08:45:20 +02:00
public function setProjectId($value)
{
$this->_validateNotNull('ProjectId', $value);
$this->_validateInt('ProjectId', $value);
2013-10-10 02:01:06 +02:00
2013-10-08 08:45:20 +02:00
if ($this->data['project_id'] === $value) {
return;
}
2013-10-08 08:45:20 +02:00
$this->data['project_id'] = $value;
2013-10-08 08:45:20 +02:00
$this->_setModified('project_id');
}
/**
* Set the value of BuildId / build_id.
*
* Must not be null.
* @param $value int
*/
public function setBuildId($value)
{
$this->_validateNotNull('BuildId', $value);
$this->_validateInt('BuildId', $value);
2013-10-10 02:01:06 +02:00
2013-10-08 08:45:20 +02:00
if ($this->data['build_id'] === $value) {
return;
}
$this->data['build_id'] = $value;
$this->_setModified('build_id');
}
/**
* Set the value of MetaKey / meta_key.
*
* Must not be null.
* @param $value string
*/
public function setMetaKey($value)
{
$this->_validateNotNull('MetaKey', $value);
$this->_validateString('MetaKey', $value);
2013-10-10 02:01:06 +02:00
if ($this->data['meta_key'] === $value) {
return;
}
$this->data['meta_key'] = $value;
$this->_setModified('meta_key');
}
/**
* Set the value of MetaValue / meta_value.
*
* Must not be null.
* @param $value string
*/
public function setMetaValue($value)
{
$this->_validateNotNull('MetaValue', $value);
$this->_validateString('MetaValue', $value);
2013-10-10 02:01:06 +02:00
if ($this->data['meta_value'] === $value) {
return;
}
$this->data['meta_value'] = $value;
$this->_setModified('meta_value');
}
/**
* Get the Project model for this BuildMeta by Id.
*
* @uses \PHPCensor\Store\ProjectStore::getById()
* @uses \PHPCensor\Model\Project
* @return \PHPCensor\Model\Project
*/
public function getProject()
{
$key = $this->getProjectId();
if (empty($key)) {
return null;
}
$cacheKey = 'Cache.Project.' . $key;
$rtn = $this->cache->get($cacheKey, null);
if (empty($rtn)) {
2016-07-19 20:28:11 +02:00
$rtn = Factory::getStore('Project', 'PHPCensor')->getById($key);
$this->cache->set($cacheKey, $rtn);
}
return $rtn;
}
/**
* Set Project - Accepts an ID, an array representing a Project or a Project model.
*
* @param $value mixed
*/
public function setProject($value)
{
// Is this an instance of Project?
2016-05-09 08:20:26 +02:00
if ($value instanceof Project) {
return $this->setProjectObject($value);
}
// Is this an array representing a Project item?
if (is_array($value) && !empty($value['id'])) {
return $this->setProjectId($value['id']);
}
// Is this a scalar value representing the ID of this foreign key?
return $this->setProjectId($value);
}
/**
* Set Project - Accepts a Project model.
*
2016-05-09 08:20:26 +02:00
* @param $value Project
*/
2016-05-09 08:20:26 +02:00
public function setProjectObject(Project $value)
{
return $this->setProjectId($value->getId());
}
/**
* Get the Build model for this BuildMeta by Id.
*
* @uses \PHPCensor\Store\BuildStore::getById()
* @uses \PHPCensor\Model\Build
* @return \PHPCensor\Model\Build
*/
public function getBuild()
{
$key = $this->getBuildId();
if (empty($key)) {
return null;
}
$cacheKey = 'Cache.Build.' . $key;
$rtn = $this->cache->get($cacheKey, null);
if (empty($rtn)) {
2016-07-19 20:28:11 +02:00
$rtn = Factory::getStore('Build', 'PHPCensor')->getById($key);
$this->cache->set($cacheKey, $rtn);
}
return $rtn;
}
/**
* Set Build - Accepts an ID, an array representing a Build or a Build model.
*
* @param $value mixed
*/
public function setBuild($value)
{
// Is this an instance of Build?
2016-05-09 08:20:26 +02:00
if ($value instanceof Build) {
return $this->setBuildObject($value);
}
// Is this an array representing a Build item?
if (is_array($value) && !empty($value['id'])) {
return $this->setBuildId($value['id']);
}
// Is this a scalar value representing the ID of this foreign key?
return $this->setBuildId($value);
}
/**
* Set Build - Accepts a Build model.
*
2016-05-09 08:20:26 +02:00
* @param $value Build
*/
2016-05-09 08:20:26 +02:00
public function setBuildObject(Build $value)
{
return $this->setBuildId($value->getId());
}
}