-
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
Showing
24 changed files
with
738 additions
and
17 deletions.
There are no files selected for viewing
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
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,77 @@ | ||
<?php namespace jlourenco\blog; | ||
|
||
use jlourenco\blog\Repositories\BlogPostRepositoryInterface; | ||
use jlourenco\blog\Repositories\BlogCategoryRepositoryInterface; | ||
|
||
class Blog | ||
{ | ||
|
||
/** | ||
* The Post repository. | ||
* | ||
* @var \jlourenco\blog\Repositories\BlogPostRepositoryInterface | ||
*/ | ||
protected $posts; | ||
|
||
/** | ||
* The Category repository. | ||
* | ||
* @var \jlourenco\blog\Repositories\BlogCategoryRepositoryInterface | ||
*/ | ||
protected $categories; | ||
|
||
/** | ||
* Create a new Blog instance. | ||
* | ||
* @param \jlourenco\blog\Repositories\BlogPostRepositoryInterface $posts | ||
* @param \jlourenco\blog\Repositories\BlogCategoryRepositoryInterface $categories | ||
*/ | ||
public function __construct(BlogPostRepositoryInterface $posts, BlogCategoryRepositoryInterface $categories) | ||
{ | ||
$this->categories = $categories; | ||
$this->posts = $posts; | ||
} | ||
|
||
/** | ||
* Returns the posts repository. | ||
*c | ||
* @return \jlourenco\blog\Repositories\BlogPostRepositoryInterface | ||
*/ | ||
public function getPostsRepository() | ||
{ | ||
return $this->posts; | ||
} | ||
|
||
/** | ||
* Sets the posts repository. | ||
* | ||
* @param \jlourenco\blog\Repositories\BlogPostRepositoryInterface $posts | ||
* @return void | ||
*/ | ||
public function setPostsRepository(BlogPostRepositoryInterface $posts) | ||
{ | ||
$this->posts = $posts; | ||
} | ||
|
||
/** | ||
* Returns the categories repository. | ||
*c | ||
* @return \jlourenco\blog\Repositories\BlogCategoryRepositoryInterface | ||
*/ | ||
public function getCategoriesRepository() | ||
{ | ||
return $this->categories; | ||
} | ||
|
||
/** | ||
* Sets the categories repository. | ||
* | ||
* @param \jlourenco\blog\Repositories\BlogCategoryRepositoryInterface $categories | ||
* @return void | ||
*/ | ||
public function setCategoriesRepository(BlogCategoryRepositoryInterface $categories) | ||
{ | ||
$this->categories = $categories; | ||
} | ||
|
||
} |
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,126 @@ | ||
<?php namespace jlourenco\blog\Controllers; | ||
|
||
use Illuminate\Http\Request; | ||
use App\Http\Requests; | ||
use App\Http\Controllers\Controller; | ||
use Blog; | ||
use Sentinel; | ||
use DB; | ||
use Searchy; | ||
|
||
class BlogController extends Controller | ||
{ | ||
|
||
/** | ||
* Show the posts. | ||
* | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function index() | ||
{ | ||
$posts = Blog::getPostsRepository()->all(); | ||
$categories = Blog::getCategoriesRepository()->all(); | ||
|
||
return view('public.blog.list', compact('posts', 'categories')); | ||
} | ||
|
||
public function edit($id) | ||
{ | ||
$post = Blog::getPostsRepository()->findOrFail($id); | ||
|
||
return view('public.blog.edit', compact('post')); | ||
} | ||
|
||
public function update($id, Request $request) | ||
{ | ||
$this->validate($request, [ 'value' => 'required' ]); | ||
|
||
$move = Blog::getPostsRepository()->findOrFail($id); | ||
|
||
$move->update($request->all()); | ||
|
||
return redirect('blog'); | ||
} | ||
|
||
public function show($id) | ||
{ | ||
$post = Blog::getPostsRepository()->findOrFail($id); | ||
$categories = Blog::getCategoriesRepository()->all(); | ||
|
||
// Show the page | ||
return View('public.blog.post', compact('post', 'categories')); | ||
} | ||
|
||
public function showByCategory($id) | ||
{ | ||
$category = Blog::getCategoriesRepository()->findOrFail($id); | ||
$posts = $category->posts; | ||
$categories = Blog::getCategoriesRepository()->all(); | ||
|
||
// Show the page | ||
return view('public.blog.list', compact('posts', 'categories')); | ||
} | ||
|
||
public function search($in) | ||
{ | ||
// Setting up vars | ||
$search = $in; | ||
$terms = explode(' ', $search); | ||
array_push($terms, $search); | ||
|
||
// Checking the users | ||
/* | ||
$users = $this->applySearch(Sentinel::createModel(), $terms, ['first_name', 'last_name'])->join('BlogPost', 'User.id', '=', 'BlogPost.author') | ||
->select(DB::raw('CONCAT(User.first_name, " ", User.last_name) AS a'), DB::raw('\'User\' AS type'))->distinct()->get()->toArray(); | ||
$users = $this->evaluate($users, $terms, ['first_name', 'last_name']);*/ | ||
|
||
$users = Sentinel::createModel()->search($in) | ||
/*->distinct()*/->select(DB::raw('CONCAT(User.first_name, " ", User.last_name) AS a'), DB::raw('\'User\' AS type'))->get()->toArray(); | ||
|
||
dd($users); | ||
|
||
// Checking the posts | ||
$posts = $this->applySearch(Blog::getPostsRepository(), $terms, ['title', 'contents', 'keywords'])->select('title as a', DB::raw('\'Post\' AS type'))->distinct()->get()->toArray(); | ||
|
||
// Checking the Categories | ||
$categories = $this->applySearch(Blog::getCategoriesRepository(), $terms, ['name', 'description'])->select('name as a', DB::raw('\'Category\' AS type'))->distinct()->get()->toArray(); | ||
|
||
// Returning the results | ||
return response()->json( [ 'data' => array_merge($users, $categories, $posts) ] ); | ||
} | ||
|
||
public function applySearch($repo, $terms, $fields) | ||
{ | ||
foreach($terms as $term) | ||
foreach($fields as $field) | ||
$repo = $repo->orWhere($field, 'LIKE', '%' . $term . '%'); | ||
|
||
foreach($repo as $data) | ||
{ | ||
dd($repo); | ||
} | ||
dd($repo); | ||
|
||
return $repo; | ||
} | ||
|
||
public function evaluate($repo, $terms, $fields) | ||
{ | ||
|
||
return $repo; | ||
} | ||
|
||
/* | ||
* Admin section | ||
*/ | ||
public function getAdminIndex() | ||
{ | ||
// Grab all the users | ||
$posts = Blog::getPostsRepository()->all(); | ||
|
||
// Show the page | ||
return View('admin.blog.list', compact('posts')); | ||
} | ||
|
||
} |
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,16 @@ | ||
<?php namespace jlourenco\blog\Facades; | ||
|
||
use Illuminate\Support\Facades\Facade; | ||
|
||
class Blog extends Facade | ||
{ | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
protected static function getFacadeAccessor() | ||
{ | ||
return 'blog'; | ||
} | ||
|
||
} |
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,60 @@ | ||
<?php namespace jlourenco\blog\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use jlourenco\support\Traits\Creation; | ||
|
||
class BlogCategory extends Model | ||
{ | ||
|
||
/** | ||
* To allow user actions identity (Created_by, Updated_by, Deleted_by) | ||
*/ | ||
use Creation; | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
protected $table = 'BlogCategory'; | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
protected $fillable = [ | ||
'name', | ||
'description' | ||
]; | ||
|
||
/** | ||
* The Blog post model name. | ||
* | ||
* @var string | ||
*/ | ||
protected static $postsModel = 'jlourenco\blog\Models\BlogPost'; | ||
|
||
/** | ||
* Returns the post model. | ||
* | ||
* @return string | ||
*/ | ||
public static function getPostsModel() | ||
{ | ||
return static::$postsModel; | ||
} | ||
|
||
/** | ||
* Sets the post model. | ||
* | ||
* @param string $postsModel | ||
* @return void | ||
*/ | ||
public static function setPostsModel($postsModel) | ||
{ | ||
static::$postsModel = $postsModel; | ||
} | ||
|
||
public function posts() | ||
{ | ||
return $this->hasMany(static::$postsModel, 'category'); | ||
} | ||
|
||
} |
Oops, something went wrong.