Fixed entity messages on delete. Fixes #21.

This commit is contained in:
Dan Brown
2015-08-23 14:20:34 +01:00
parent 40b629d35d
commit 0b222c7734
6 changed files with 27 additions and 11 deletions

View File

@ -21,9 +21,10 @@ class ActivityService
/**
* Add activity data to database.
* @para Entity $entity
* @param Entity $entity
* @param $activityKey
* @param int $bookId
* @param bool $extra
*/
public function add(Entity $entity, $activityKey, $bookId = 0, $extra = false)
{
@ -53,6 +54,25 @@ class ActivityService
$this->activity->save();
}
/**
* Removes the entity attachment from each of its activities
* and instead uses the 'extra' field with the entities name.
* Used when an entity is deleted.
* @param Entity $entity
* @return mixed
*/
public function removeEntity(Entity $entity)
{
$activities = $entity->activity;
foreach($activities as $activity) {
$activity->extra = $entity->name;
$activity->entity_id = 0;
$activity->entity_type = null;
$activity->save();
}
return $activities;
}
/**
* Gets the latest activity.
* @param int $count