update v1.0.5

This commit is contained in:
sujitprasad
2016-01-25 20:45:35 +05:30
parent 0b8ebb9c70
commit e7149e34e4
252 changed files with 9008 additions and 3152 deletions

View File

@@ -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>&nbsp;<a href=article/' . $model->id . '/edit class="btn btn-warning btn-flat">Edit</a>&nbsp;<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>&nbsp;<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>&nbsp;<a href=article/' . $model->id . '/edit class="btn btn-warning btn-xs">' . \Lang::get('lang.edit') . '</a>&nbsp;<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">&times;</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">&times;</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);
}
}

View File

@@ -1,33 +1,47 @@
<?php namespace App\Http\Controllers\Agent\kb;
// Controllers
use App\Http\Controllers\client\kb\UserController;
use App\Http\Controllers\admin\kb\ArticleController;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Agent\kb\SettingsController;
use App\Http\Controllers\Agent\helpdesk\TicketController;
// Requests
use App\Http\Requests\kb\CategoryRequest;
use App\Http\Requests\kb\CategoryUpdate;
use App\Http\Controllers\Agent\helpdesk\TicketController;
// Model
use App\Model\kb\Category;
use App\Model\kb\Relationship;
// Classes
use Datatable;
use Redirect;
use Exception;
/**
* CategoryController
* This controller is used to CRUD category
*
* @package Controllers
* @subpackage Controller
* @author Ladybird <info@ladybirdweb.com>
* @package Controllers
* @subpackage Controller
* @author Ladybird <info@ladybirdweb.com>
*/
class CategoryController 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();
}
@@ -38,48 +52,56 @@ class CategoryController extends Controller {
* @return Response
*/
public function index() {
/* get the view of index of the catogorys with all attributes
of category model */
return view('themes.default1.agent.kb.category.index');
try{
return view('themes.default1.agent.kb.category.index');
} catch (Exception $e) {
return redirect()->back()->with('fails', $e->errorInfo[2]);
}
}
/**
* fetching category list in chumper datatables
* @return type chumper datatable
*/
public function getData() {
//return 'kfjhje';
/* fetching chumper datatables */
return Datatable::collection(Category::All())
/* search 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 Actions */
/* there are action buttons and modal popup to delete a data column */
->addColumn('Actions', function ($model) {
//return '<a href=category/delete/' . $model->id . ' class="btn btn-danger btn-flat">Delete</a>&nbsp;<a href=category/' . $model->id . '/edit class="btn btn-warning btn-flat">Edit</a>&nbsp;<a href=article-list class="btn btn-warning btn-flat">View</a>';
return '<span data-toggle="modal" data-target="#deletecategory' . $model->slug . '"><a href="#" ><button class="btn btn-danger btn-xs"></a>'. \Lang::get("lang.delete") .'</button></span>&nbsp;<a href=category/' . $model->id . '/edit class="btn btn-warning btn-xs">'. \Lang::get("lang.edit") .'</a>&nbsp;<a href=article-list class="btn btn-primary btn-xs">'. \Lang::get("lang.view") .'</a>
<div class="modal fade" id="deletecategory' . $model->slug . '">
<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">&times;</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="category/delete/' . $model->id . '"><button class="btn btn-danger">delete</button></a>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div>';
<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">&times;</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="category/delete/' . $model->id . '"><button class="btn btn-danger">delete</button></a>
</div>
</div>
</div>
</div>';
})
->make();
@@ -88,71 +110,62 @@ class CategoryController extends Controller {
/**
* Create a Category
* @param type Category $category
* @return Response
* @return type view
*/
public function create(Category $category) {
/* Get the all attributes in the category model */
$category = $category->get();
/* get the view page to create new category with all attributes
of category model*/
return view('themes.default1.agent.kb.category.create', compact('category'));
}
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store(Category $category, CategoryRequest $request) {
/* Get the whole request from the form and insert into table via model */
$sl = $request->input('slug');
$slug = str_slug($sl, "-");
$category->slug = $slug;
//$category->save();
if ($category->fill($request->except('slug'))->save()) //True: send success message to index page
{
return Redirect::back()->with('success', 'Category Inserted Successfully');
} else //send fail to index page
{
return Redirect::back()->with('fails', 'Category Not Inserted');
try {
return view('themes.default1.agent.kb.category.create', compact('category'));
} catch(Exception $e) {
return redirect()->back()->with('fails',$e->errorInfo[2]);
}
}
/**
* Display the specified resource.
*
* @param int $id
* @return Response
* To store the selected category
* @param type Category $category
* @param type CategoryRequest $request
* @return type Redirect
*/
public function show($id) {
//
public function store(Category $category, CategoryRequest $request) {
/* Get the whole request from the form and insert into table via model */
$sl = $request->input('slug');
$slug = str_slug($sl, "-");
$category->slug = $slug;
// send success message to index page
try{
$category->fill($request->except('slug'))->save();
return Redirect::back()->with('success', 'Category Inserted Successfully');
} catch(Exception $e) {
return Redirect::back()->with('fails', 'Category Not Inserted'.'<li>'.$e->errorInfo[2].'</li>');
}
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return Response
* Show the form for editing the specified category.
* @param type $slug
* @param type Category $category
* @return type view
*/
public function edit($slug, Category $category) {
// fetch the category
$cid = $category->where('id', $slug)->first();
$id = $cid->id;
/* get the atributes of the category model whose id == $id */
$category = $category->whereId($id)->first();
/* get the Edit page the selected category via id */
return view('themes.default1.agent.kb.category.edit', compact('category'));
}
/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
* Update the specified Category in storage.
* @param type $slug
* @param type Category $category
* @param type CategoryUpdate $request
* @return type redirect
*/
public function update($slug, Category $category, CategoryUpdate $request) {
@@ -163,42 +176,41 @@ class CategoryController extends Controller {
// dd($slug);
$category->slug = $slug;
/* update the values at the table via model according with the request */
if ($category->fill($request->all())->save()) //True: redirct to index page with success message
{
//redirct to index page with success message
try{
$category->fill($request->all())->save();
$category->slug = $slug;
$category->save();
return redirect('category')->with('success', 'Category Updated Successfully');
} else //redirect to index with fails message
{
return redirect('category')->with('fails', 'Category Not Updated');
return redirect('category')->with('success', 'Category Updated Successfully');
} catch(Exception $e) {
//redirect to index with fails message
return redirect('category')->with('fails', 'Category Not Updated'.'<li>'.$e->errorInfo[2].'</li>');
}
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
* Remove the specified category from storage.
* @param type $id
* @param type Category $category
* @param type Relationship $relation
* @return type Redirect
*/
public function destroy($id, Category $category, Relationship $relation) {
$relation = $relation->where('category_id', $id)->first();
// dd($relation);
if($relation != null){
return Redirect::back()->with('fails', 'Category Not Deleted');
}
else {
/* delete the category selected, id == $id */
$category = $category->whereId($id)->first();
if ($category->delete()) //True: redirect to index with success message
{
// redirect to index with success message
try{
$category->delete();
return Redirect::back()->with('success', 'Category Deleted Successfully');
} else //redirect to index page fails message
{
return Redirect::back()->with('fails', 'Category Not Deleted');
}
} catch(Exception $e){
return Redirect::back()->with('fails', 'Category Not Deleted'.'<li>'.$e->errorInfo[2].'</li>');
}
}
}

View File

@@ -1,89 +1,113 @@
<?php namespace App\Http\Controllers\Agent\kb;
// controllers
use App\Http\Controllers\client\kb\UserController;
use App\Http\Controllers\Agent\kb\ArticleController;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Agent\kb\SettingsController;
use App\Http\Controllers\Agent\helpdesk\TicketController;
// request
use App\Http\Requests\kb\PageRequest;
use App\Http\Requests\kb\PageUpdate;
use App\Model\kb\Page;
use Datatable;
use Illuminate\Http\Request;
// Model
use App\Model\kb\Page;
// classes
use Datatable;
use Exception;
/**
* PageController
* This controller is used to CRUD Pages
*
* @package Controllers
* @subpackage Controller
* @author Ladybird <info@ladybirdweb.com>
*/
class PageController extends Controller {
/**
* Contructor for both Authentication and Model Injecting
* @param type Page $page
* @return type
* Create a new controller instance.
* constructor to check
* 1. authentication
* 2. user roles
* 3. roles must be agent
* @return void
*/
public function __construct(Page $page) {
// checking authentication
$this->middleware('auth');
// checking roles
$this->middleware('roles');
$this->page = $page;
SettingsController::language();
}
/**
* Display a listing of the resource.
*
* @return Response
* Display the list of pages
* @return type
*/
public function index() {
$pages = $this->page->paginate(3);
$pages->setPath('page');
return view('themes.default1.agent.kb.pages.index', compact('pages'));
try{
return view('themes.default1.agent.kb.pages.index', compact('pages'));
} catch(Exception $e) {
return redirect()->back()->with('fails',$e->errorInfo[2]);
}
}
/**
* fetching pages list in chumper datatables
* @return type
*/
public function getData() {
//return 'kfjhje';
/* fetching chumper datatables */
return Datatable::collection(Page::All())
/* search column name */
->searchColumns('name')
/* order column name, description and created */
->orderColumns('name', 'description', 'created')
/* 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 Actions */
/* there are action buttons and modal popup to delete a data column */
->addColumn('Actions', function ($model) {
//return '<a href=page/delete/' . $model->id . ' class="btn btn-danger btn-flat">Delete</a>&nbsp;<a href=page/' . $model->id . '/edit class="btn btn-warning btn-flat">Edit</a>&nbsp;<a href=article-list class="btn btn-warning btn-flat">View</a>';
return '<span data-toggle="modal" data-target="#deletepage' . $model->id . '"><a href="#" ><button class="btn btn-danger btn-xs"></a> '. \Lang::get('lang.delete') .'</button></span>&nbsp;<a href=page/' . $model->slug . '/edit class="btn btn-warning btn-xs">'. \Lang::get('lang.edit') .'</a>&nbsp;<a href=pages/' . $model->slug . ' class="btn btn-primary btn-xs">'. \Lang::get('lang.view') .'</a>
<div class="modal fade" id="deletepage' . $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">&times;</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="page/delete/' . $model->id . '"><button class="btn btn-danger">delete</button></a>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div>';
<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">&times;</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="page/delete/' . $model->id . '"><button class="btn btn-danger">delete</button></a>
</div>
</div>
</div>
</div>';
})
->make();
}
/**
* Show the form for creating a new resource.
*
* @return Response
* @return type view
*/
public function create() {
return view('themes.default1.agent.kb.pages.create');
@@ -97,61 +121,65 @@ class PageController extends Controller {
public function store(PageRequest $request) {
$sl = $request->input('slug');
$slug = str_slug($sl, "-");
$this->page->slug = $slug;
$this->page->fill($request->except('slug'))->save();
return redirect('page');
}
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function show($id) {
//
try{
$this->page->fill($request->except('slug'))->save();
return redirect('page')->with('success','Page created successfully');
} catch(Exception $e) {
return redirect('page')->with('fails',$e->errorInfo[2]);
}
}
/**
* To edit a page
* @param type $id
* @return type
* @param type $slug
* @return type view
*/
public function edit($slug) {
$page = $this->page->where('slug', $slug)->first();
return view('themes.default1.agent.kb.pages.edit', compact('page'));
try{
$page = $this->page->where('slug', $slug)->first();
return view('themes.default1.agent.kb.pages.edit', compact('page'));
} catch (Exception $e) {
return redirect('page')->with('fails',$e->errorInfo[2]);
}
}
/**
* To update a page
* @param type $id
* @param type Request $request
* @return type
* @param type $slug
* @param type PageUpdate $request
* @return type redirect
*/
public function update($slug, PageUpdate $request) {
// get pages with respect to slug
$pages = $this->page->where('slug', $slug)->first();
$sl = $request->input('slug');
$slug = str_slug($sl, "-");
$this->page->slug = $slug;
//$id = $page->id;
$pages->fill($request->all())->save();
$pages->slug = $slug;
$pages->save();
return redirect('page')->with('success', 'Your Page Updated Successfully');
$slug = str_slug($sl, "-");
$this->page->slug = $slug;
try{
$pages->fill($request->all())->save();
$pages->slug = $slug;
$pages->save();
return redirect('page')->with('success', 'Your Page Updated Successfully');
} catch(Exception $e) {
return redirect('page')->with('fails', $e->errorInfo[2]);
}
}
/**
* To Delete one Page
* @param type $id
* @return type
* To Delete a Page
* @param type $id
* @return type redirect
*/
public function destroy($id) {
$page = $this->page->whereId($id)->first();
$page->delete();
return redirect('page')->with('success', 'Page Deleted Successfully');
try{
// get the page to be deleted
$page = $this->page->whereId($id)->first();
$page->delete();
return redirect('page')->with('success', 'Page Deleted Successfully');
} catch (Exception $e) {
return redirect('page')->with('fails', $e->errorInfo[2]);
}
}
}

View File

@@ -1,38 +1,59 @@
<?php namespace App\Http\Controllers\Agent\kb;
// Controllers
use App\Http\Controllers\Agent\kb\ArticleController;
use App\Http\Controllers\Agent\helpdesk\TicketController;
use App\Http\Controllers\Controller;
// Request
use App\Http\Requests\kb\FooterRequest;
use App\Http\Requests\kb\ProfilePassword;
use App\Http\Requests\kb\ProfileRequest;
use App\Http\Requests\kb\SettingsRequests;
use App\Http\Requests\kb\SocialRequest;
use Illuminate\Http\Request;
// Model
use App\Model\kb\Comment;
use App\Model\kb\DateFormat;
use App\Model\kb\Faq;
use App\Model\kb\Settings;
use App\Model\kb\Side1;
use App\Model\kb\Side2;
use App\Model\kb\Social;
use App\Model\helpdesk\Utility\Timezones;
use App\Model\helpdesk\Utility\Date_format;
// Classes
use Auth;
use Config;
use Datatable;
use Hash;
use Illuminate\Http\Request;
use Image;
use Input;
use Exception;
/**
* SettingsController
* This controller is used to perform settings in the setting page of knowledgebase
*
* @package Controllers
* @subpackage Controller
* @author Ladybird <info@ladybirdweb.com>
*/
class SettingsController 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');
$this->language();
}
@@ -42,8 +63,7 @@ class SettingsController extends Controller {
* @return response
* @package default
*/
public function settings(Settings $settings, Timezones $time, DateFormat $date) {
public function settings(Settings $settings, Timezones $time, Date_format $date) {
/* get the setting where the id == 1 */
$settings = $settings->whereId('1')->first();
$time = $time->get();
@@ -62,19 +82,14 @@ class SettingsController extends Controller {
{
/* fetch the values of company request */
$settings = $settings->whereId('1')->first();
if (Input::file('logo')) {
$name = Input::file('logo')->getClientOriginalName();
$destinationPath = 'lb-faveo/dist/image';
$fileName = rand(0000, 9999) . '.' . $name;
//echo $fileName;
Input::file('logo')->move($destinationPath, $fileName);
$settings->logo = $fileName;
//$thDestinationPath = 'dist/th';
Image::make($destinationPath . '/' . $fileName, array(
'width' => 300,
'height' => 300,
@@ -83,28 +98,21 @@ class SettingsController extends Controller {
}
if (Input::file('background')) {
$name = Input::file('background')->getClientOriginalName();
$destinationPath = 'lb-faveo/dist/image';
$fileName = rand(0000, 9999) . '.' . $name;
echo $fileName;
Input::file('background')->move($destinationPath, $fileName);
$settings->background = $fileName;
//$thDestinationPath = 'dist/th';
Image::make($destinationPath . '/' . $fileName, array(
'width' => 300,
'height' => 300,
'grayscale' => false,
))->save('lb-faveo/dist/image/' . $fileName);
}
/* Check whether function success or not */
if ($settings->fill($request->except('logo', 'background'))->save() == true) {
/* redirect to Index page with Success Message */
return redirect('settings')->with('success', 'Settings Updated Successfully');
} else {
/* redirect to Index page with Fails Message */
@@ -117,49 +125,6 @@ class SettingsController extends Controller {
}
/**
* to get the faq view page
* @return response
*/
public function Faq(Faq $faq) {
/* fetch the values of faq */
$faq = $faq->whereId('1')->first();
return view('themes.default1.agent.settings.faq', compact('faq'));
}
public function postfaq($id, Faq $faq, Request $request) {
$faq = $faq->whereId('1')->first();
if ($faq->fill($request->input())->save()) {
return redirect('create-faq')->with('success', 'Faq updated Successfully');
} else {
return redirect('craete-faq')->with('fails', 'Faq not updated');
}
}
/**
* get the create page to insert the values to database
* @return type response
*/
public function CreateSocialLink(Social $social) {
$social = $social->whereId('1')->first();
return view('themes.default1.agent.kb.settings.social', compact('social'));
}
/**
*
* @param type Social $social
* @param type Request $request
* @return type resonse
*/
public function PostSocial(Social $social, SocialRequest $request) {
$social = $social->whereId('1')->first();
if ($social->fill($request->input())->save()) {
return redirect('social')->with('success', 'Your Social Links Stored');
} else {
return redirect('social')->with('fails', 'Sorry Can not Performe');
}
}
/**
* To Moderate the commenting
* @param type Comment $comment
@@ -237,56 +202,61 @@ class SettingsController extends Controller {
}
}
/**
* get profile page
* @return type view
*/
public function getProfile() {
$time = Timezone::all();
$user = Auth::user();
return view('themes.default1.agent.kb.settings.profile', compact('user', 'time'));
}
/**
* Post profile page
* @param type ProfileRequest $request
* @return type redirect
*/
public function postProfile(ProfileRequest $request) {
$user = Auth::user();
$user->gender = $request->input('gender');
$user->save();
if (is_null($user->profile_pic)) {
if ($request->input('gender') == 1) {
$name = 'avatar5.png';
$destinationPath = 'lb-faveo/dist/img';
$user->profile_pic = $name;
} elseif ($request->input('gender') == 0) {
$name = 'avatar2.png';
$destinationPath = 'lb-faveo/dist/img';
$user->profile_pic = $name;
}
}
if (Input::file('profile_pic')) {
//$extension = Input::file('profile_pic')->getClientOriginalExtension();
$name = Input::file('profile_pic')->getClientOriginalName();
$destinationPath = 'lb-faveo/dist/img';
$fileName = rand(0000, 9999) . '.' . $name;
//echo $fileName;
Input::file('profile_pic')->move($destinationPath, $fileName);
$user->profile_pic = $fileName;
} else {
$user->fill($request->except('profile_pic', 'gender'))->save();
return redirect()->back()->with('success1', 'Profile Updated sucessfully');
}
if ($user->fill($request->except('profile_pic'))->save()) {
return redirect('profile')->with('success1', 'Profile Updated sucessfully');
} else {
return redirect('profile')->with('fails1', 'Profile Not Updated sucessfully');
}
}
/**
* post profile password
* @param type $id
* @param type ProfilePassword $request
* @return type redirect
*/
public function postProfilePassword($id, ProfilePassword $request) {
$user = Auth::user();
//echo $user->password;
@@ -299,81 +269,12 @@ class SettingsController extends Controller {
return redirect('profile')->with('fails2', 'Old password Wrong');
}
}
/**
* To delete the logo
* @param type $id
* @param type Settings $setting
* @return type
*/
public function deleteLogo($id, Settings $setting) {
$setting = $setting->whereId($id)->first();
$setting->logo = '';
$setting->save();
return redirect('settings')->with('success', 'Settings Updated Successfully');
}
public function deleteBackground($id, Settings $setting) {
$setting = $setting->whereId($id)->first();
$setting->background = '';
$setting->save();
return redirect('settings')->with('success', 'Settings Updated Successfully');
}
/**
* Get the View of create Side widget page
* @param type Side1 $side
* @return View
* het locale for language
* @return type config set
*/
public function side1(Side1 $side) {
$side = $side->where('id', '1')->first();
return view('themes.default1.agent.kb.settings.side1', compact('side'));
}
/**
* Post function of Side1 Page
* @param type $id
* @param type Side1 $side
* @param type Request $request
* @return view
*/
public function postside1($id, Side1 $side, Request $request) {
$side = $side->whereId($id)->first();
if ($side->fill($request->input())->save()) {
return redirect('side1')->with('success', 'Side Widget 1 Created !');
} else {
return redirect('side1')->with('fails', 'Whoops ! Something went Wrong ! ');
}
}
/**
* Get the View for side widget creat
* @param type Side2 $side
* @return type
*/
public function side2(Side2 $side) {
$side = $side->where('id', '1')->first();
return view('themes.default1.agent.kb.settings.side2', compact('side'));
}
/**
* Post functio for side
* @param type $id
* @param type Side2 $side
* @param type Request $request
* @return response
*/
public function postside2($id, Side2 $side, Request $request) {
$side = $side->whereId($id)->first();
if ($side->fill($request->input())->save()) {
return redirect('side2')->with('success', 'Side Widget 2 Created !');
} else {
return redirect('side2')->with('fails', 'Whoops ! Something went Wrong ! ');
}
}
static function language() {
// $set = Settings::whereId(1)->first();
// $lang = $set->language;