update v1.0.5
This commit is contained in:
@@ -1,159 +1,171 @@
|
||||
<?php 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;
|
||||
|
||||
// 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\Relationship;
|
||||
use App\Model\kb\Settings;
|
||||
use App\Model\kb\Comment;
|
||||
|
||||
// Classes
|
||||
use Auth;
|
||||
use Chumper\Datatable\Table;
|
||||
use Datatable;
|
||||
use DB;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Model\kb\Comment;
|
||||
|
||||
/* include the article model to access the article table */
|
||||
use Redirect;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* ArticleController
|
||||
* This controller is used to CRUD Articles
|
||||
*
|
||||
* @package Controllers
|
||||
* @subpackage Controller
|
||||
* @author Ladybird <info@ladybirdweb.com>
|
||||
* @package Controllers
|
||||
* @subpackage Controller
|
||||
* @author Ladybird <info@ladybirdweb.com>
|
||||
*/
|
||||
|
||||
class ArticleController extends Controller {
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return Response
|
||||
* Create a new controller instance.
|
||||
* constructor to check
|
||||
* 1. authentication
|
||||
* 2. user roles
|
||||
* 3. roles must be agent
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
// checking authentication
|
||||
$this->middleware('auth');
|
||||
// checking roles
|
||||
$this->middleware('roles');
|
||||
SettingsController::language();
|
||||
}
|
||||
|
||||
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
|
||||
* @return type void
|
||||
*/
|
||||
public function getData() {
|
||||
|
||||
//return 'kfjhje';
|
||||
|
||||
// returns chumper datatable
|
||||
return Datatable::collection(Article::All())
|
||||
/* searcable column name */
|
||||
->searchColumns('name')
|
||||
/* order column name and description */
|
||||
->orderColumns('name', 'description')
|
||||
/* add column name */
|
||||
->addColumn('name', function ($model) {
|
||||
return $model->name;
|
||||
})
|
||||
/* add column Created */
|
||||
->addColumn('Created', function ($model) {
|
||||
$t = $model->created_at;
|
||||
return TicketController::usertimezone($t);
|
||||
})
|
||||
/* add column action */
|
||||
->addColumn('Actions', function ($model) {
|
||||
//return '<a href=article/delete/ ' . $model->id . ' class="btn btn-danger btn-flat" onclick="myFunction()">Delete</a> <a href=article/' . $model->id . '/edit class="btn btn-warning btn-flat">Edit</a> <a href=show/' . $model->id . ' class="btn btn-warning btn-flat">View</a>';
|
||||
//return '<form action="article/delete/ ' . $model->id . '" method="post" onclick="alert()"><button type="sumbit" value="Delete"></button></form><a href=article/' . $model->id . '/edit class="btn btn-warning btn-flat">Edit</a> <a href=show/' . $model->id . ' class="btn btn-warning btn-flat">View</a>';
|
||||
/* 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 .'">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||
<h4 class="modal-title">Are You Sure ?</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
'.$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>
|
||||
</div>
|
||||
</div><!-- /.modal-content -->
|
||||
</div><!-- /.modal-dialog -->
|
||||
</div>';
|
||||
})
|
||||
->make();
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||
<h4 class="modal-title">Are You Sure ?</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
'.$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>
|
||||
</div>
|
||||
</div><!-- /.modal-content -->
|
||||
</div><!-- /.modal-dialog -->
|
||||
</div>';
|
||||
})
|
||||
->make();
|
||||
}
|
||||
|
||||
/**
|
||||
* Index for Articles
|
||||
* @param type Article $article
|
||||
* @return type Response
|
||||
* List of Articles
|
||||
* @return type view
|
||||
*/
|
||||
public function index() {
|
||||
/* show the index page with article list */
|
||||
return view('themes.default1.agent.kb.article.index');
|
||||
/* show article list */
|
||||
try{
|
||||
return view('themes.default1.agent.kb.article.index');
|
||||
} catch(Exception $e) {
|
||||
return redirect()->back()->with('fails',$e->errorInfo[2]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creating a Article
|
||||
* @param type Category $category
|
||||
* @return type Response
|
||||
* @return type view
|
||||
*/
|
||||
public function create(Category $category) {
|
||||
//$cat = $category->whereId(33)->first();
|
||||
//$tm = $cat->created_at;
|
||||
//$this->usertimezone($tm);
|
||||
// // /* get the attributes of the category */
|
||||
/* get the attributes of the category */
|
||||
$category = $category->lists('id', 'name');
|
||||
/* get the create page */
|
||||
return view('themes.default1.agent.kb.article.create', compact('category'));
|
||||
try{
|
||||
return view('themes.default1.agent.kb.article.create', compact('category'));
|
||||
} catch(Exception $e) {
|
||||
return redirect()->back()->with('fails',$e->errorInfo[2]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert the values to the article table
|
||||
* Insert the values to the article
|
||||
* @param type Article $article
|
||||
* @param type ArticleRequest $request
|
||||
* @return type
|
||||
* @return type redirect
|
||||
*/
|
||||
public function store(Article $article, ArticleRequest $request) {
|
||||
|
||||
$sl = $request->input('slug');
|
||||
$slug = str_slug($sl, "-");
|
||||
$article->slug = $slug;
|
||||
// requesting the values to store article data
|
||||
$sl = $request->input('slug');
|
||||
$slug = str_slug($sl, "-");
|
||||
$article->slug = $slug;
|
||||
$article->fill($request->except('created_at','slug'))->save();
|
||||
// creating article category relationship
|
||||
$requests = $request->input('category_id');
|
||||
$id = $article->id;
|
||||
foreach ($requests as $req) {
|
||||
DB::insert('insert into article_relationship (category_id, article_id) values (?,?)', [$req, $id]);
|
||||
DB::insert('insert into kb_article_relationship (category_id, article_id) values (?,?)', [$req, $id]);
|
||||
}
|
||||
/* insert the values to the article table */
|
||||
if ($article->fill($request->except('slug'))->save()) //true: redirect to index page with success message
|
||||
{
|
||||
try{
|
||||
$article->fill($request->except('slug'))->save();
|
||||
return redirect('article')->with('success', 'Article Inserted Successfully');
|
||||
} else //redirect to index page with fail message
|
||||
{
|
||||
return redirect('article')->with('fails', 'Article Not Inserted');
|
||||
} catch (Exception $e) {
|
||||
return redirect('article')->with('fails', 'Article Not Inserted'. '<li>'.$e->errorInfo[2].'</li>');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return Response
|
||||
*/
|
||||
public function show($id) {
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit an Article by id
|
||||
* @param type Integer $id
|
||||
* @param type Article $article
|
||||
* @param type Relationship $relation
|
||||
* @param type Category $category
|
||||
* @return Response
|
||||
* @return view
|
||||
*/
|
||||
public function edit($slug, Article $article, Relationship $relation, Category $category) {
|
||||
|
||||
@@ -168,7 +180,12 @@ class ArticleController extends Controller {
|
||||
/* Get the selected article with id */
|
||||
$article = $article->whereId($id)->first();
|
||||
/* send to the edit page */
|
||||
return view('themes.default1.agent.kb.article.edit', compact('assign', 'article', 'category'));
|
||||
try {
|
||||
return view('themes.default1.agent.kb.article.edit', compact('assign', 'article', 'category'));
|
||||
} catch(Exception $e){
|
||||
return redirect()->back()->with('fails',$e->errorInfo[2]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -197,14 +214,13 @@ class ArticleController extends Controller {
|
||||
DB::insert('insert into article_relationship (category_id, article_id) values (?,?)', [$req, $id]);
|
||||
}
|
||||
/* update the value to the table */
|
||||
if ($article->fill($request->all())->save()) //true: redirect to index page with success message
|
||||
{
|
||||
try{
|
||||
$article->fill($request->all())->save();
|
||||
$article->slug = $slug;
|
||||
$article->save();
|
||||
return redirect('article')->with('success', 'Article Updated Successfully');
|
||||
} else // redirect to index page with fails message
|
||||
{
|
||||
return redirect('article')->with('fails', 'Article Not Updated');
|
||||
} catch(Exception $e){
|
||||
return redirect('article')->with('fails', 'Article Not Updated'.'<li>'.$e->errorInfo[2].'</li>');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,59 +231,46 @@ class ArticleController extends Controller {
|
||||
* @return Response
|
||||
*/
|
||||
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
|
||||
//dd($article);
|
||||
$id = $article->id;
|
||||
$comments = $comment->where('article_id',$id)->get();
|
||||
|
||||
if($comments)
|
||||
{
|
||||
if($comments) {
|
||||
foreach($comments as $comment)
|
||||
$comment->delete();
|
||||
}
|
||||
|
||||
// deleting relationship
|
||||
$relation = $relation->where('article_id', $id)->first();
|
||||
if($relation)
|
||||
{
|
||||
if($relation) {
|
||||
$relation->delete();
|
||||
}
|
||||
if($article)
|
||||
{
|
||||
if ($article->delete()) //true:redirect to index page with success message
|
||||
{
|
||||
if($article) {
|
||||
if ($article->delete()) {//true:redirect to index page with success message
|
||||
return Redirect::back()->with('success', 'Article Deleted Successfully');
|
||||
} else //redirect to index page with fails message
|
||||
{
|
||||
} else { //redirect to index page with fails message
|
||||
return Redirect::back()->with('fails', 'Article Not Deleted');
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
} else {
|
||||
return Redirect::back()->with('fails', 'Article can Not Deleted');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* user time zone
|
||||
* fetching timezone
|
||||
* @param type $utc
|
||||
* @return type
|
||||
*/
|
||||
static function usertimezone($utc) {
|
||||
$user = Auth::user();
|
||||
$tz = $user->timezone;
|
||||
$set = Settings::whereId('1')->first();
|
||||
$format = $set->dateformat;
|
||||
//$utc = date('M d Y h:i:s A');
|
||||
//echo 'UTC : ' . $utc;
|
||||
date_default_timezone_set($tz);
|
||||
|
||||
$offset = date('Z', strtotime($utc));
|
||||
//print "offset: $offset \n";
|
||||
$date = date($format, strtotime($utc) + $offset);
|
||||
echo $date;
|
||||
//return substr($date, 0, -6);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user