Added 'user_id' (created by) and 'create_date' columns to 'project_group' table.
This commit is contained in:
parent
4ec6d854c2
commit
7382df7f6d
|
@ -526,6 +526,8 @@ class InstallCommand extends Command
|
|||
|
||||
$group = new ProjectGroup();
|
||||
$group->setTitle('Projects');
|
||||
$group->setCreateDate(new \DateTime());
|
||||
$group->setUserId(0);
|
||||
|
||||
Factory::getStore('ProjectGroup')->save($group);
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ use b8\Form;
|
|||
use PHPCensor\Controller;
|
||||
use PHPCensor\Model\ProjectGroup;
|
||||
use PHPCensor\Helper\Lang;
|
||||
use PHPCensor\Model\User;
|
||||
|
||||
/**
|
||||
* Project Controller - Allows users to create, edit and view projects.
|
||||
|
@ -71,10 +72,19 @@ class GroupController extends Controller
|
|||
|
||||
if ($this->request->getMethod() == 'POST') {
|
||||
$group->setTitle($this->getParam('title'));
|
||||
if (is_null($groupId)) {
|
||||
/** @var User $user */
|
||||
$user = $_SESSION['php-censor-user'];
|
||||
|
||||
$group->setCreateDate(new \DateTime());
|
||||
$group->setUserId($user->getId());
|
||||
}
|
||||
|
||||
$this->groupStore->save($group);
|
||||
|
||||
$response = new b8\Http\Response\RedirectResponse();
|
||||
$response->setHeader('Location', APP_URL.'group');
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,8 +14,6 @@ class AddedAdditionalColumns extends AbstractMigration
|
|||
->save();
|
||||
}
|
||||
|
||||
$table = $this->table('build');
|
||||
|
||||
if ($table->hasColumn('created')) {
|
||||
$table
|
||||
->renameColumn('created', 'create_date')
|
||||
|
@ -45,8 +43,6 @@ class AddedAdditionalColumns extends AbstractMigration
|
|||
->save();
|
||||
}
|
||||
|
||||
$table = $this->table('build');
|
||||
|
||||
if ($table->hasColumn('create_date')) {
|
||||
$table
|
||||
->renameColumn('create_date', 'created')
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
class AddedAdditionalColumns2 extends AbstractMigration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
$table = $this->table('project_group');
|
||||
|
||||
if (!$table->hasColumn('create_date')) {
|
||||
$table
|
||||
->addColumn('create_date', 'datetime', ['null' => true])
|
||||
->save();
|
||||
}
|
||||
|
||||
if (!$table->hasColumn('user_id')) {
|
||||
$table
|
||||
->addColumn('user_id', 'integer', ['default' => 0])
|
||||
->save();
|
||||
}
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
$table = $this->table('project_group');
|
||||
|
||||
if ($table->hasColumn('create_date')) {
|
||||
$table
|
||||
->removeColumn('create_date')
|
||||
->save();
|
||||
}
|
||||
|
||||
if ($table->hasColumn('user_id')) {
|
||||
$table
|
||||
->removeColumn('user_id')
|
||||
->save();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -26,24 +26,30 @@ class ProjectGroup extends Model
|
|||
* @var array
|
||||
*/
|
||||
protected $data = [
|
||||
'id' => null,
|
||||
'title' => null,
|
||||
'id' => null,
|
||||
'title' => null,
|
||||
'create_date' => null,
|
||||
'user_id' => 0,
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $getters = [
|
||||
'id' => 'getId',
|
||||
'title' => 'getTitle',
|
||||
'id' => 'getId',
|
||||
'title' => 'getTitle',
|
||||
'create_date' => 'getCreateDate',
|
||||
'user_id' => 'getUserId',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $setters = [
|
||||
'id' => 'setId',
|
||||
'title' => 'setTitle',
|
||||
'id' => 'setId',
|
||||
'title' => 'setTitle',
|
||||
'create_date' => 'setCreateDate',
|
||||
'user_id' => 'setUserId',
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -56,16 +62,6 @@ class ProjectGroup extends Model
|
|||
return $rtn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
$rtn = $this->data['title'];
|
||||
|
||||
return $rtn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value int
|
||||
*/
|
||||
|
@ -83,6 +79,16 @@ class ProjectGroup extends Model
|
|||
$this->setModified('id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
$rtn = $this->data['title'];
|
||||
|
||||
return $rtn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value string
|
||||
*/
|
||||
|
@ -100,6 +106,63 @@ class ProjectGroup extends Model
|
|||
$this->setModified('title');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getCreateDate()
|
||||
{
|
||||
$rtn = $this->data['create_date'];
|
||||
|
||||
if (!empty($rtn)) {
|
||||
$rtn = new \DateTime($rtn);
|
||||
}
|
||||
|
||||
return $rtn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value \DateTime
|
||||
*/
|
||||
public function setCreateDate($value)
|
||||
{
|
||||
$this->validateDate('create_date', $value);
|
||||
|
||||
if ($this->data['create_date'] === $value) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->data['create_date'] = $value;
|
||||
|
||||
$this->setModified('create_date');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getUserId()
|
||||
{
|
||||
$rtn = $this->data['user_id'];
|
||||
|
||||
return (integer)$rtn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value integer
|
||||
*/
|
||||
public function setUserId($value)
|
||||
{
|
||||
$this->validateNotNull('user_id', $value);
|
||||
$this->validateInt('user_id', $value);
|
||||
|
||||
if ($this->data['user_id'] === $value) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->data['user_id'] = $value;
|
||||
|
||||
$this->setModified('user_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Project models by GroupId for this ProjectGroup.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue