FEATURE: add overview to all static pages

This commit is contained in:
Michal Kváček
2016-01-27 20:13:57 +01:00
parent 8210eafad5
commit d9b678036a
4 changed files with 107 additions and 3 deletions
+35
View File
@@ -3,6 +3,7 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
/**
* Class Content
@@ -29,4 +30,38 @@ class Content extends Model
const STATUS_DRAFT = 'draft';
const STATUS_PROTECTED = 'protected';
const STATUS_PUBLIC = 'public';
/**
* Getter for overview of all content pages of given handler (module type)
*
* @param $handler
* @param bool $joinAuthor
*
*/
public function getByType($handler, $joinAuthor = false)
{
$query = DB::table('contents')
->select('contents.*')
->where('contents.status', '<>', self::STATUS_DELETED)
->where('module_handler', $handler)
->orderBy('created_at');
// join user email and user name to results when needed
if ($joinAuthor) {
$query = $query->join('users', 'users.id', '=', 'contents.user_id')
->select('contents.*', 'users.name AS author_name', 'users.email AS author_email');
}
return $query;
}
/**
* Mark relationship with users table
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function author()
{
return $this->belongsTo('App\Models\User', 'user_id');
}
}