Skip to content

Commit

Permalink
Added changes from review
Browse files Browse the repository at this point in the history
  • Loading branch information
Taliesin Millhouse committed Aug 20, 2019
1 parent 882ea2d commit 092f123
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 118 deletions.
241 changes: 125 additions & 116 deletions system/classes/AspectModifiable.php
Original file line number Diff line number Diff line change
@@ -1,85 +1,93 @@
<?php

/**
* Use this aspect to store creation
* and modification data for any object
* @author carsten
*
*/
class AspectModifiable {
private $object;
private $_mo;

function __construct(DbObject &$obj) {
$this->object = $obj;
}

private function getMo() {
if ($this->object && $this->object->id && !$this->_mo) {
$this->_mo = $this->object->getObject("ObjectModification", array("table_name"=>$this->object->getDbTableName(), "object_id"=>$this->object->id));
}
return $this->_mo;
}

/////////////////////////////////////////////////
// Methods to be used by DbObject
/////////////////////////////////////////////////

/**
* Store creation data
*/
function insert() {
if (!$this->getMo()) {
$mo = new ObjectModification($this->object->w);
$mo->table_name = $this->object->getDbTableName();
$mo->object_id = $this->object->id;
$mo->dt_created = time();
$user = $mo->w->Auth->user();
$mo->creator_id = (!empty($user->id) ? $user->id : 0);
$mo->insert();
}
}

/**
* Store modification data
*/
function update() {
if ($this->getMo()) {
$this->_mo->dt_modified = time();
$user = $this->_mo->w->Auth->user();
$this->_mo->modifier_id = (!empty($user->id) ? $user->id : 0);
$this->_mo->update();
}
}

/////////////////////////////////////////////////
// Methods to be used by client object
/////////////////////////////////////////////////

function getCreator() {
if ($this->getMo()) {
return $this->_mo->getCreator();
}
}

function getModifier() {
if ($this->getMo()) {
return $this->_mo->getModifier();
}
}

function getCreatedDate() {
if ($this->getMo()) {
return $this->_mo->dt_created;
}
}

function getModifiedDate() {
if ($this->getMo()) {
return $this->_mo->dt_modified;
}
}


class AspectModifiable
{
private $object;
private $_mo;

public function __construct(DbObject &$obj)
{
$this->object = $obj;
}

private function getMo()
{
if ($this->object && $this->object->id && !$this->_mo) {
$this->_mo = $this->object->getObject("ObjectModification", array("table_name" => $this->object->getDbTableName(), "object_id" => $this->object->id));
}
return $this->_mo;
}

/////////////////////////////////////////////////
// Methods to be used by DbObject
/////////////////////////////////////////////////

/**
* Store creation data
*/
public function insert()
{
if (!$this->getMo()) {
$mo = new ObjectModification($this->object->w);
$mo->table_name = $this->object->getDbTableName();
$mo->object_id = $this->object->id;
$mo->dt_created = time();
$user = $mo->w->Auth->user();
$mo->creator_id = (!empty($user->id) ? $user->id : 0);
$mo->insert();
}
}

/**
* Store modification data
*/
public function update()
{
if ($this->getMo()) {
$this->_mo->dt_modified = time();
$user = $this->_mo->w->Auth->user();
$this->_mo->modifier_id = (!empty($user->id) ? $user->id : 0);
$this->_mo->update();
}
}

/////////////////////////////////////////////////
// Methods to be used by client object
/////////////////////////////////////////////////

public function getCreator()
{
if ($this->getMo()) {
return $this->_mo->getCreator();
}
}

public function getModifier()
{
if ($this->getMo()) {
return $this->_mo->getModifier();
}
}

public function getCreatedDate()
{
if ($this->getMo()) {
return $this->_mo->dt_created;
}
}

public function getModifiedDate()
{
if ($this->getMo()) {
return $this->_mo->dt_modified;
}
}
}

//////////////////////////////////////////////////////////////////////////////
Expand All @@ -89,45 +97,46 @@ function getModifiedDate() {
/**
* Store creation and modification data of any object
*/
class ObjectModification extends DbObject {
public $table_name;
public $object_id;

public $dt_created;
public $dt_modified;
public $creator_id;
public $modifier_id;

// do not audit this table!
public $__use_auditing = false;

public static $_db_table = "object_modification";

/**
* returns the creator of the
* object which is attached to this
* aspect.
*
* @return User
*/
function getCreator() {
if ($this->creator_id) {
return $this->w->Auth->getUser($this->creator_id);
}
}

/**
* returns the modifier user
* of the object which is attached
* to this aspect.
*
* @return User
*/
function getModifier() {
if ($this->modifier_id) {
return $this->w->Auth->getUser($this->modifier_id);
}
}

class ObjectModification extends DbObject
{
public $table_name;
public $object_id;

public $dt_created;
public $dt_modified;
public $creator_id;
public $modifier_id;

// do not audit this table!
public $__use_auditing = false;

public static $_db_table = "object_modification";

/**
* returns the creator of the
* object which is attached to this
* aspect.
*
* @return User
*/
public function getCreator()
{
if ($this->creator_id) {
return $this->w->Auth->getUser($this->creator_id);
}
}

/**
* returns the modifier user
* of the object which is attached
* to this aspect.
*
* @return User
*/
public function getModifier()
{
if ($this->modifier_id) {
return $this->w->Auth->getUser($this->modifier_id);
}
}
}

2 changes: 0 additions & 2 deletions system/modules/task/models/TaskGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ class TaskGroup extends DbObject


public static $_validation = [
"name" => ["required"],
"type" => ["required"],
"title" => ["required"],
"can_assign" => ["required"],
"can_view" => ["required"],
Expand Down

0 comments on commit 092f123

Please sign in to comment.