forked from johndavedecano/laragym
-
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.
- Loading branch information
1 parent
bee86d8
commit 0136b17
Showing
13 changed files
with
248 additions
and
80 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
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
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,81 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: Dave | ||
* Date: 9/14/2018 | ||
* Time: 9:13 PM | ||
*/ | ||
|
||
namespace App\Services\Activity; | ||
|
||
use App\Models\Activity; | ||
|
||
/** | ||
* Class ActivityCollection | ||
* @package App\Services\Activity | ||
*/ | ||
class ActivityCollection | ||
{ | ||
|
||
public $meta = []; | ||
|
||
/** | ||
* @var Activity | ||
*/ | ||
public $activity; | ||
|
||
/** | ||
* ActivityCollection constructor. | ||
* @param Activity $activity | ||
*/ | ||
public function __construct(Activity $activity) | ||
{ | ||
$this->activity = $activity; | ||
} | ||
|
||
/** | ||
* @param $builder | ||
* @param array $request | ||
* @return mixed | ||
*/ | ||
public function order($builder, $request = []) | ||
{ | ||
$or = isset($request['order']) ? $request['order'] : 'DESC'; | ||
|
||
$by = isset($request['order_by']) ? $request['order_by'] : 'created_at'; | ||
|
||
if (!in_array(strtoupper($or), ['ASC', 'DESC'])) { | ||
$or = 'DESC'; | ||
} | ||
|
||
$this->meta['order'] = $or; | ||
$this->meta['order_by'] = $by; | ||
|
||
return $builder->orderBy($by, $or); | ||
} | ||
|
||
/** | ||
* @param array $request | ||
* @return mixed | ||
*/ | ||
public function list($request = []) | ||
{ | ||
$builder = $this->activity->select('*'); | ||
|
||
$builder = $this->order($builder, $request); | ||
|
||
if (isset($request['entity_id'])) { | ||
$builder = $builder->where('entity_id', $request['entity_id']); | ||
$this->meta['entity_id'] = $request['entity_id']; | ||
} | ||
|
||
if (isset($request['type'])) { | ||
$builder = $builder->where('type', $request['type']); | ||
$this->meta['type'] = $request['type']; | ||
} | ||
|
||
$limit = isset($request['limit']) ? (int)$request['limit'] : 25; | ||
|
||
return $builder->paginate($limit); | ||
} | ||
} |
Oops, something went wrong.