-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added activity history to to all entities. Fixes #12
- Loading branch information
1 parent
41eb2fb
commit 5d9d096
Showing
19 changed files
with
672 additions
and
250 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,5 @@ Homestead.yaml | |
/public/js | ||
/public/uploads | ||
/public/bower | ||
/storage/images | ||
/storage/images | ||
_ide_helper.php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Oxbow; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
/** | ||
* @property string key | ||
* @property \User user | ||
* @property \Entity entity | ||
* @property string extra | ||
*/ | ||
class Activity extends Model | ||
{ | ||
public function entity() | ||
{ | ||
if($this->entity_id) { | ||
return $this->morphTo('entity')->first(); | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
public function user() | ||
{ | ||
return $this->belongsTo('Oxbow\User'); | ||
} | ||
|
||
/** | ||
* Returns text from the language files, Looks up by using the | ||
* activity key. | ||
*/ | ||
public function getText() | ||
{ | ||
return trans('activities.' . $this->key); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Oxbow\Providers; | ||
|
||
use Illuminate\Support\ServiceProvider; | ||
use Oxbow\Services\ActivityService; | ||
|
||
class CustomFacadeProvider extends ServiceProvider | ||
{ | ||
/** | ||
* Bootstrap the application services. | ||
* | ||
* @return void | ||
*/ | ||
public function boot() | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Register the application services. | ||
* | ||
* @return void | ||
*/ | ||
public function register() | ||
{ | ||
$this->app->bind('activity', function() { | ||
return new ActivityService($this->app->make('Oxbow\Activity')); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php namespace Oxbow\Services; | ||
|
||
use Illuminate\Support\Facades\Auth; | ||
use Oxbow\Activity; | ||
use Oxbow\Entity; | ||
|
||
class ActivityService | ||
{ | ||
protected $activity; | ||
protected $user; | ||
|
||
/** | ||
* ActivityService constructor. | ||
* @param $activity | ||
*/ | ||
public function __construct(Activity $activity) | ||
{ | ||
$this->activity = $activity; | ||
$this->user = Auth::user(); | ||
} | ||
|
||
|
||
/** | ||
* Add activity data to database. | ||
* @para Entity $entity | ||
* @param $activityKey | ||
* @param int $bookId | ||
*/ | ||
public function add(Entity $entity, $activityKey, $bookId = 0, $extra = false) | ||
{ | ||
$this->activity->user_id = $this->user->id; | ||
$this->activity->book_id = $bookId; | ||
$this->activity->key = strtolower($activityKey); | ||
if($extra !== false) { | ||
$this->activity->extra = $extra; | ||
} | ||
$entity->activity()->save($this->activity); | ||
} | ||
|
||
/** | ||
* Adds a activity history with a message & without binding to a entitiy. | ||
* @param $activityKey | ||
* @param int $bookId | ||
* @param bool|false $extra | ||
*/ | ||
public function addMessage($activityKey, $bookId = 0, $extra = false) | ||
{ | ||
$this->activity->user_id = $this->user->id; | ||
$this->activity->book_id = $bookId; | ||
$this->activity->key = strtolower($activityKey); | ||
if($extra !== false) { | ||
$this->activity->extra = $extra; | ||
} | ||
$this->activity->save(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php namespace Oxbow\Services\Facades; | ||
|
||
|
||
use Illuminate\Support\Facades\Facade; | ||
|
||
class Activity extends Facade | ||
{ | ||
/** | ||
* Get the registered name of the component. | ||
* | ||
* @return string | ||
*/ | ||
protected static function getFacadeAccessor() { return 'activity'; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.