Skip to content

Commit

Permalink
Revert "Merge pull request #23 from joomlatools/feature/22-resource"
Browse files Browse the repository at this point in the history
This reverts commit feb0103, reversing
changes made to 4ad206a.
  • Loading branch information
amazeika committed Jul 5, 2018
1 parent feb0103 commit c024dcc
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 179 deletions.
7 changes: 0 additions & 7 deletions activity/interface.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,4 @@ public function setLocale($locale);
* @return string The activity locale.
*/
public function getLocale();

/**
* Resource getter.
*
* @return ComActivitiesActivityResourceInterface|null
*/
public function getResource();
}
46 changes: 0 additions & 46 deletions activity/resource/interface.php

This file was deleted.

65 changes: 58 additions & 7 deletions controller/behavior/resourceable.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ public function __construct(KObjectConfig $config)
{
parent::__construct($config);

$this->_actions = KObjectConfig::unbox($config->actions);
$this->_actions = KObjectConfig::unbox($config->actions);
}

protected function _initialize(KObjectConfig $config)
{
$config->append(array(
'actions' => array('delete')
'actions' => array('delete')
));

parent::_initialize($config);
Expand All @@ -50,19 +50,70 @@ protected function _afterAdd(KControllerContextInterface $context)

if ($entity instanceof ComActivitiesActivityInterface && $entity->getActivityObject())
{
if ($resource = $entity->getResource())
$resource = $this->_getResource($entity);

$controller = $this->_getController();

if (!in_array($entity->action, $this->_actions))
{
if (!in_array($entity->action, $this->_actions))
$data = $this->_getData($entity);

if (!$resource->isNew())
{
if ($resource->isNew() || $resource->isModified()) {
$resource->save();
// Update resource if title changed.
if ($resource->title != $entity->title) {
$controller->id($resource->id)->edit($data);
}
}
else if (!$resource->isNew()) $resource->delete();
else $controller->add($data);
}
else if (!$resource->isNew()) $controller->id($resource->id)->delete();
}
}

/**
* Resource getter.
*
* @param KModelEntityInterface $entity The entity to get the resource from
*
* @return KModelEntityInterface|null The resource
*/
protected function _getResource($entity)
{
$model = $this->_getController()->getModel();

$model->reset()->getState()->setValues(array(
'package' => $entity->package,
'name' => $entity->name,
'resource_id' => $entity->row
));

return $model->fetch();
}

/**
* Entity data getter
*
* @param KModelEntityInterface $entity The entity to get data from
*
* @return array The entity data
*/
protected function _getData(KModelEntityInterface $entity)
{
$data = array(
'package' => $entity->package,
'name' => $entity->name,
'resource_id' => $entity->row,
'title' => $entity->title
);

if ($uuid = $entity->getActivityObject()->getUuid()) {
$data['uuid'] = $uuid;
}

return $data;
}

/**
* Resource controller getter.
*
Expand Down
89 changes: 10 additions & 79 deletions model/entity/activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,6 @@ class ComActivitiesModelEntityActivity extends KModelEntityRow implements ComAct
*/
protected $_locale;

/**
* Resources model
*
* @var string|KObjectIdentifierInterface|KModelInterface
*/
protected $_resources_model;

/**
* Constructor.
*
Expand All @@ -87,12 +80,11 @@ public function __construct(KObjectConfig $config)
{
parent::__construct($config);

$this->_format = $config->format;
$this->_objects = KObjectConfig::unbox($config->objects);
$this->_object_table = $config->object_table;
$this->_object_column = $config->object_column;
$this->_translator = $config->translator;
$this->_resources_model = $config->resources_model;
$this->_format = $config->format;
$this->_objects = KObjectConfig::unbox($config->objects);
$this->_object_table = $config->object_table;
$this->_object_column = $config->object_column;
$this->_translator = $config->translator;
}

/**
Expand All @@ -107,12 +99,11 @@ protected function _initialize(KObjectConfig $config)
$data = $config->data;

$config->append(array(
'format' => '{actor} {action} {object.type} title {object}',
'object_table' => $data->package . '_' . KStringInflector::pluralize($data->name),
'object_column' => $data->package . '_' . $data->name . '_id',
'translator' => 'com:activities.activity.translator',
'objects' => array('actor', 'action', 'object', 'target', 'generator', 'provider'),
'resources_model' => 'com:activities.model.resources'
'format' => '{actor} {action} {object.type} title {object}',
'object_table' => $data->package . '_' . KStringInflector::pluralize($data->name),
'object_column' => $data->package . '_' . $data->name . '_id',
'translator' => 'com:activities.activity.translator',
'objects' => array('actor', 'action', 'object', 'target', 'generator', 'provider')
));

parent::_initialize($config);
Expand Down Expand Up @@ -154,7 +145,6 @@ public function save()
{
$this->setStatus(KDatabase::STATUS_FAILED);
$this->setStatusMessage($this->getObject('translator')->translate('Missing required data'));

return false;
}
}
Expand Down Expand Up @@ -334,7 +324,6 @@ public function getPropertyFormat()
public function setLocale($locale)
{
$this->_locale = $locale;

return $this;
}

Expand All @@ -360,7 +349,6 @@ public function getLocale()
public function setTranslator(ComActivitiesActivityTranslatorInterface $translator)
{
$this->_translator = $translator;

return $this;
}

Expand Down Expand Up @@ -801,61 +789,4 @@ protected function _getRoute($url)

return $this->getObject('lib:dispatcher.router.route', array('url' => array('query' => $url)));
}

/**
* Resource getter.
*
* @return ComActivitiesModelEntityResource
*/
public function getResource()
{
$model = $this->_getResourcesModel();

$resource = $model->package($this->package)->name($this->name)->resource_id($this->row)->fetch();

if ($resource->isNew())
{
$data = array(
'package' => $this->package,
'name' => $this->name,
'resource_id' => $this->row,
'title' => $this->title
);

if ($uuid = $this->getActivityObject()->getUuid()) {
$data['uuid'] = $uuid;
}

$resource = $model->create($data);
}
else
{
if ($this->title != $resource->title) {
$resource->title = $this->title;
}
}

return $resource;
}

/**
* Resource model getter.
*
* @return KModelInterface
*/
protected function _getResourcesModel()
{
if (!$this->_resources_model instanceof KModelInterface)
{
$model = $this->getObject($this->_resources_model);

if (!$model instanceof KModelInterface) {
throw new RuntimeException(sprintf('%s is not a valid model identifier', (string) $this->_resources_model));
} else {
$this->_resources_model = $model;
}
}

return $this->_resources_model;
}
}
41 changes: 1 addition & 40 deletions model/entity/resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,45 +13,6 @@
* @author Arunas Mazeika <https://github.com/amazeika>
* @package Koowa\Component\Activities
*/
class ComActivitiesModelEntityResource extends KModelEntityRow implements ComActivitiesActivityResourceInterface
class ComActivitiesModelEntityResource extends KModelEntityRow
{
/**
* Resource package getter.
*
* @return string
*/
public function getPackage()
{
return $this->package;
}

/**
* Resource name getter.
*
* @return string
*/
public function getName()
{
return $this->name;
}

/**
* Resource ID getter.
*
* @return mixed
*/
public function getId()
{
return $this->id;
}

/**
* Resource UUID getter.
*
* @return string
*/
public function getUuid()
{
return $this->uuid;
}
}

0 comments on commit c024dcc

Please sign in to comment.