Applied fixes from StyleCI
This commit is contained in:

committed by
StyleCI Bot

parent
be5df5334f
commit
d637c2b23f
@@ -3,47 +3,46 @@
|
||||
namespace App\Http\Controllers\Agent\kb;
|
||||
|
||||
// Controllers
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Controllers\Agent\kb\SettingsController;
|
||||
use App\Http\Controllers\Client\kb\UserController;
|
||||
use App\Http\Controllers\Agent\helpdesk\TicketController;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
// Requests
|
||||
use App\Http\Requests\kb\ArticleRequest;
|
||||
use App\Http\Requests\kb\ArticleUpdate;
|
||||
// Models
|
||||
use App\Model\kb\Article;
|
||||
use App\Model\kb\Category;
|
||||
use App\Model\kb\Comment;
|
||||
use App\Model\kb\Relationship;
|
||||
use App\Model\kb\Settings;
|
||||
use App\Model\kb\Comment;
|
||||
// Classes
|
||||
use Auth;
|
||||
use Chumper\Datatable\Table;
|
||||
use Datatable;
|
||||
use DB;
|
||||
use Exception;
|
||||
use Illuminate\Http\Request;
|
||||
use Redirect;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* ArticleController
|
||||
* This controller is used to CRUD Articles
|
||||
* This controller is used to CRUD Articles.
|
||||
*
|
||||
* @package Controllers
|
||||
* @subpackage Controller
|
||||
* @author Ladybird <info@ladybirdweb.com>
|
||||
*/
|
||||
class ArticleController extends Controller {
|
||||
|
||||
class ArticleController extends Controller
|
||||
{
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
* constructor to check
|
||||
* 1. authentication
|
||||
* 2. user roles
|
||||
* 3. roles must be agent
|
||||
* 3. roles must be agent.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
public function __construct()
|
||||
{
|
||||
// checking authentication
|
||||
$this->middleware('auth');
|
||||
// checking roles
|
||||
@@ -51,16 +50,19 @@ class ArticleController extends Controller {
|
||||
SettingsController::language();
|
||||
}
|
||||
|
||||
public function test() {
|
||||
public function test()
|
||||
{
|
||||
//$table = $this->setDatatable();
|
||||
return view('themes.default1.agent.kb.article.test');
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetching all the list of articles in a chumper datatable format
|
||||
* Fetching all the list of articles in a chumper datatable format.
|
||||
*
|
||||
* @return type void
|
||||
*/
|
||||
public function getData() {
|
||||
public function getData()
|
||||
{
|
||||
// returns chumper datatable
|
||||
return Datatable::collection(Article::All())
|
||||
/* searcable column name */
|
||||
@@ -74,13 +76,14 @@ class ArticleController extends Controller {
|
||||
/* add column Created */
|
||||
->addColumn('Created', function ($model) {
|
||||
$t = $model->created_at;
|
||||
|
||||
return TicketController::usertimezone($t);
|
||||
})
|
||||
/* add column action */
|
||||
->addColumn('Actions', function ($model) {
|
||||
/* here are all the action buttons and modal popup to delete articles with confirmations */
|
||||
return '<span data-toggle="modal" data-target="#deletearticle' . $model->id . '"><a href="#" ><button class="btn btn-danger btn-xs"></a> ' . \Lang::get('lang.delete') . ' </button></span> <a href=article/' . $model->id . '/edit class="btn btn-warning btn-xs">' . \Lang::get('lang.edit') . '</a> <a href=show/' . $model->slug . ' class="btn btn-primary btn-xs">' . \Lang::get('lang.view') . '</a>
|
||||
<div class="modal fade" id="deletearticle' . $model->id . '">
|
||||
return '<span data-toggle="modal" data-target="#deletearticle'.$model->id.'"><a href="#" ><button class="btn btn-danger btn-xs"></a> '.\Lang::get('lang.delete').' </button></span> <a href=article/'.$model->id.'/edit class="btn btn-warning btn-xs">'.\Lang::get('lang.edit').'</a> <a href=show/'.$model->slug.' class="btn btn-primary btn-xs">'.\Lang::get('lang.view').'</a>
|
||||
<div class="modal fade" id="deletearticle'.$model->id.'">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
@@ -88,11 +91,11 @@ class ArticleController extends Controller {
|
||||
<h4 class="modal-title">Are You Sure ?</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
' . $model->name . '
|
||||
'.$model->name.'
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default pull-left" data-dismiss="modal" id="dismis2">Close</button>
|
||||
<a href="article/delete/' . $model->slug . '"><button class="btn btn-danger">delete</button></a>
|
||||
<a href="article/delete/'.$model->slug.'"><button class="btn btn-danger">delete</button></a>
|
||||
</div>
|
||||
</div><!-- /.modal-content -->
|
||||
</div><!-- /.modal-dialog -->
|
||||
@@ -102,10 +105,12 @@ class ArticleController extends Controller {
|
||||
}
|
||||
|
||||
/**
|
||||
* List of Articles
|
||||
* List of Articles.
|
||||
*
|
||||
* @return type view
|
||||
*/
|
||||
public function index() {
|
||||
public function index()
|
||||
{
|
||||
/* show article list */
|
||||
try {
|
||||
return view('themes.default1.agent.kb.article.index');
|
||||
@@ -115,11 +120,14 @@ class ArticleController extends Controller {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creating a Article
|
||||
* Creating a Article.
|
||||
*
|
||||
* @param type Category $category
|
||||
*
|
||||
* @return type view
|
||||
*/
|
||||
public function create(Category $category) {
|
||||
public function create(Category $category)
|
||||
{
|
||||
/* get the attributes of the category */
|
||||
$category = $category->lists('id', 'name');
|
||||
/* get the create page */
|
||||
@@ -131,17 +139,20 @@ class ArticleController extends Controller {
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert the values to the article
|
||||
* @param type Article $article
|
||||
* Insert the values to the article.
|
||||
*
|
||||
* @param type Article $article
|
||||
* @param type ArticleRequest $request
|
||||
*
|
||||
* @return type redirect
|
||||
*/
|
||||
public function store(Article $article, ArticleRequest $request) {
|
||||
public function store(Article $article, ArticleRequest $request)
|
||||
{
|
||||
// requesting the values to store article data
|
||||
$publishTime = $request->input('year') . '-' . $request->input('month') . '-' . $request->input('day') . ' ' . $request->input('hour') . ':' . $request->input('minute') . ':00';
|
||||
$publishTime = $request->input('year').'-'.$request->input('month').'-'.$request->input('day').' '.$request->input('hour').':'.$request->input('minute').':00';
|
||||
|
||||
$sl = $request->input('slug');
|
||||
$slug = str_slug($sl, "-");
|
||||
$slug = str_slug($sl, '-');
|
||||
$article->slug = $slug;
|
||||
$article->publish_time = $publishTime;
|
||||
$article->fill($request->except('created_at', 'slug'))->save();
|
||||
@@ -155,21 +166,25 @@ class ArticleController extends Controller {
|
||||
/* insert the values to the article table */
|
||||
try {
|
||||
$article->fill($request->except('slug'))->save();
|
||||
|
||||
return redirect('article')->with('success', 'Article Inserted Successfully');
|
||||
} catch (Exception $e) {
|
||||
return redirect('article')->with('fails', 'Article Not Inserted' . '<li>' . $e->errorInfo[2] . '</li>');
|
||||
return redirect('article')->with('fails', 'Article Not Inserted'.'<li>'.$e->errorInfo[2].'</li>');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit an Article by id
|
||||
* @param type Integer $id
|
||||
* @param type Article $article
|
||||
* Edit an Article by id.
|
||||
*
|
||||
* @param type Integer $id
|
||||
* @param type Article $article
|
||||
* @param type Relationship $relation
|
||||
* @param type Category $category
|
||||
* @param type Category $category
|
||||
*
|
||||
* @return view
|
||||
*/
|
||||
public function edit($slug, Article $article, Relationship $relation, Category $category) {
|
||||
public function edit($slug, Article $article, Relationship $relation, Category $category)
|
||||
{
|
||||
$aid = $article->where('id', $slug)->first();
|
||||
$id = $aid->id;
|
||||
/* define the selected fields */
|
||||
@@ -188,20 +203,23 @@ class ArticleController extends Controller {
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an Artile by id
|
||||
* @param type Integer $id
|
||||
* @param type Article $article
|
||||
* @param type Relationship $relation
|
||||
* Update an Artile by id.
|
||||
*
|
||||
* @param type Integer $id
|
||||
* @param type Article $article
|
||||
* @param type Relationship $relation
|
||||
* @param type ArticleRequest $request
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function update($slug, Article $article, Relationship $relation, ArticleUpdate $request) {
|
||||
public function update($slug, Article $article, Relationship $relation, ArticleUpdate $request)
|
||||
{
|
||||
$aid = $article->where('id', $slug)->first();
|
||||
$publishTime = $request->input('year') . '-' . $request->input('month') . '-' . $request->input('day') . ' ' . $request->input('hour') . ':' . $request->input('minute') . ':00';
|
||||
$publishTime = $request->input('year').'-'.$request->input('month').'-'.$request->input('day').' '.$request->input('hour').':'.$request->input('minute').':00';
|
||||
|
||||
$id = $aid->id;
|
||||
$sl = $request->input('slug');
|
||||
$slug = str_slug($sl, "-");
|
||||
$slug = str_slug($sl, '-');
|
||||
// dd($slug);
|
||||
|
||||
$article->slug = $slug;
|
||||
@@ -221,26 +239,31 @@ class ArticleController extends Controller {
|
||||
$article->slug = $slug;
|
||||
$article->publish_time = $publishTime;
|
||||
$article->save();
|
||||
|
||||
return redirect('article')->with('success', 'Article Updated Successfully');
|
||||
} catch (Exception $e) {
|
||||
return redirect('article')->with('fails', 'Article Not Updated' . '<li>' . $e->errorInfo[2] . '</li>');
|
||||
return redirect('article')->with('fails', 'Article Not Updated'.'<li>'.$e->errorInfo[2].'</li>');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an Agent by id
|
||||
* @param type $id
|
||||
* Delete an Agent by id.
|
||||
*
|
||||
* @param type $id
|
||||
* @param type Article $article
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function destroy($slug, Article $article, Relationship $relation, Comment $comment) {
|
||||
public function destroy($slug, Article $article, Relationship $relation, Comment $comment)
|
||||
{
|
||||
/* delete the selected article from the table */
|
||||
$article = $article->where('slug', $slug)->first(); //get the selected article via id
|
||||
$id = $article->id;
|
||||
$comments = $comment->where('article_id', $id)->get();
|
||||
if ($comments) {
|
||||
foreach ($comments as $comment)
|
||||
foreach ($comments as $comment) {
|
||||
$comment->delete();
|
||||
}
|
||||
}
|
||||
// deleting relationship
|
||||
$relation = $relation->where('article_id', $id)->first();
|
||||
@@ -260,11 +283,14 @@ class ArticleController extends Controller {
|
||||
|
||||
/**
|
||||
* user time zone
|
||||
* fetching timezone
|
||||
* fetching timezone.
|
||||
*
|
||||
* @param type $utc
|
||||
*
|
||||
* @return type
|
||||
*/
|
||||
static function usertimezone($utc) {
|
||||
public static function usertimezone($utc)
|
||||
{
|
||||
$user = Auth::user();
|
||||
$tz = $user->timezone;
|
||||
$set = Settings::whereId('1')->first();
|
||||
@@ -275,5 +301,4 @@ class ArticleController extends Controller {
|
||||
$date = date($format, strtotime($utc) + $offset);
|
||||
echo $date;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user