first commit
This commit is contained in:
222
app/Modules/Service/Permission/PermissionService.php
Normal file
222
app/Modules/Service/Permission/PermissionService.php
Normal file
@@ -0,0 +1,222 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Service\Permission;
|
||||
|
||||
use App\Modules\Models\Permission\Permission;
|
||||
use App\Modules\Service\Service;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Yajra\DataTables\Facades\DataTables;
|
||||
use Spatie\Permission\Models\Permission as SepPermission;
|
||||
|
||||
|
||||
|
||||
class PermissionService extends Service
|
||||
{
|
||||
protected $Permission;
|
||||
|
||||
public function __construct(Permission $Permission)
|
||||
{
|
||||
$this->Permission = $Permission;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*For DataTable*/
|
||||
public function getAllData()
|
||||
|
||||
{
|
||||
$query = $this->Permission->whereIsDeleted('no');
|
||||
return DataTables::of($query)
|
||||
->addIndexColumn()
|
||||
// ->editColumn('brand',function(Permission $Permission) {
|
||||
// if($Permission->brand->name) {
|
||||
// return $Permission->brand->name;
|
||||
// }
|
||||
// })
|
||||
// ->editColumn('category',function(Permission $Permission) {
|
||||
// if($Permission->category->name) {
|
||||
// return $Permission->category->name;
|
||||
// }
|
||||
// })
|
||||
->editColumn('visibility',function(Permission $Permission) {
|
||||
if($Permission->visibility == 'visible'){
|
||||
return '<span class="badge text-bg-info">Visible</span>';
|
||||
} else {
|
||||
return '<span class="badge text-bg-danger">In-Visible</span>';
|
||||
}
|
||||
})
|
||||
->editColumn('availability',function(Permission $Permission) {
|
||||
if($Permission->availability == 'available'){
|
||||
return '<span class="badge text-bg-info">Available</span>';
|
||||
} else {
|
||||
return '<span class="badge text-bg-danger">Un-Available</span>';
|
||||
}
|
||||
})
|
||||
->editColumn('status',function(Permission $Permission) {
|
||||
if($Permission->status == 'active'){
|
||||
return '<span class="badge text-bg-info">Active</span>';
|
||||
} else {
|
||||
return '<span class="badge text-bg-danger">In-Active</span>';
|
||||
}
|
||||
})
|
||||
->editColumn('image',function(Permission $Permission) {
|
||||
if(isset($Permission->image_path)){
|
||||
return '<img src="http://127.0.0.1:8000/'.($Permission->image_path).'" width="100px">';
|
||||
} else {
|
||||
;
|
||||
}
|
||||
})
|
||||
->editcolumn('actions',function(Permission $Permission) {
|
||||
$editRoute = route('permission.edit',$Permission->id);
|
||||
$deleteRoute = route('permission.destroy',$Permission->id);
|
||||
return getTableHtml($Permission,'actions',$editRoute,$deleteRoute);
|
||||
return getTableHtml($Permission,'image');
|
||||
})->rawColumns(['visibility','availability','status','image'])->make(true);
|
||||
}
|
||||
|
||||
public function create(array $data)
|
||||
{
|
||||
try {
|
||||
/* $data['keywords'] = '"'.$data['keywords'].'"';*/
|
||||
//dd($data);
|
||||
// DB::table('permissions')->insert(['guard_name' => 'web']);
|
||||
$Permission = SepPermission::create($data);
|
||||
return $Permission;
|
||||
|
||||
} catch (Exception $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Paginate all Permission
|
||||
*
|
||||
* @param array $filter
|
||||
* @return Collection
|
||||
*/
|
||||
public function paginate(array $filter = [])
|
||||
{
|
||||
$filter['limit'] = 25;
|
||||
|
||||
return $this->Permission->orderBy('id','DESC')->whereIsDeleted('no')->paginate($filter['limit']);
|
||||
}
|
||||
/**
|
||||
* Get all Permission
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function all()
|
||||
{
|
||||
return $this->Permission->whereIsDeleted('no')->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all Permissions with supervisor type
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
|
||||
|
||||
public function find($PermissionId)
|
||||
{
|
||||
try {
|
||||
return $this->Permission->whereIsDeleted('no')->find($PermissionId);
|
||||
} catch (Exception $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function update($PermissionId, array $data)
|
||||
{
|
||||
try {
|
||||
$data['last_updated_by']= Auth::user()->id;
|
||||
$Permission= $this->Permission->find($PermissionId);
|
||||
$Permission = $Permission->update($data);
|
||||
//$this->logger->info(' created successfully', $data);
|
||||
|
||||
return $Permission;
|
||||
} catch (Exception $e) {
|
||||
//$this->logger->error($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a Permission
|
||||
*
|
||||
* @param Id
|
||||
* @return bool
|
||||
*/
|
||||
public function delete($PermissionId)
|
||||
{
|
||||
try {
|
||||
|
||||
$data['last_deleted_by']= Auth::Permission()->id;
|
||||
$data['deleted_at']= Carbon::now();
|
||||
$Permission = $this->Permission->find($PermissionId);
|
||||
$data['is_deleted']='yes';
|
||||
return $Permission = $Permission->update($data);
|
||||
|
||||
} catch (Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* write brief description
|
||||
* @param $name
|
||||
* @return mixed
|
||||
*/
|
||||
public function getByName($name){
|
||||
return $this->Permission->whereIsDeleted('no')->whereName($name);
|
||||
}
|
||||
|
||||
public function getBySlug($slug){
|
||||
return $this->Permission->whereIsDeleted('no')->whereSlug($slug)->first();
|
||||
}
|
||||
|
||||
|
||||
function uploadFile($file)
|
||||
{
|
||||
if (!empty($file)) {
|
||||
$this->uploadPath = 'uploads/Permission';
|
||||
return $fileName = $this->uploadFromAjax($file);
|
||||
}
|
||||
}
|
||||
|
||||
public function __deleteImages($subCat)
|
||||
{
|
||||
try {
|
||||
if (is_file($subCat->image_path))
|
||||
unlink($subCat->image_path);
|
||||
|
||||
if (is_file($subCat->thumbnail_path))
|
||||
unlink($subCat->thumbnail_path);
|
||||
} catch (\Exception $e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function updateImage($PermissionId, array $data)
|
||||
{
|
||||
try {
|
||||
$Permission = $this->Permission->find($PermissionId);
|
||||
$Permission = $Permission->update($data);
|
||||
|
||||
return $Permission;
|
||||
} catch (Exception $e) {
|
||||
//$this->logger->error($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function getPermissionByGroupWise()
|
||||
{
|
||||
$groupPermissions = $this->Permission->all();
|
||||
return $groupPermissions;
|
||||
}
|
||||
}
|
224
app/Modules/Service/Role/RoleService.php
Normal file
224
app/Modules/Service/Role/RoleService.php
Normal file
@@ -0,0 +1,224 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Service\Role;
|
||||
|
||||
use App\Modules\Models\Role\Role;
|
||||
use App\Modules\Service\Service;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Yajra\DataTables\Facades\DataTables;
|
||||
|
||||
class RoleService extends Service
|
||||
{
|
||||
protected $role;
|
||||
|
||||
public function __construct(Role $role)
|
||||
{
|
||||
$this->role = $role;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*For DataTable*/
|
||||
public function getAllData()
|
||||
{
|
||||
$query = $this->role->whereIsDeleted('no');
|
||||
return DataTables::of($query)
|
||||
->addIndexColumn()
|
||||
// ->editColumn('brand',function(role $role) {
|
||||
// if($role->brand->name) {
|
||||
// return $role->brand->name;
|
||||
// }
|
||||
// })
|
||||
// ->editColumn('role',function(role $role) {
|
||||
// if($role->role->name) {
|
||||
// return $role->role->name;
|
||||
// }
|
||||
// })
|
||||
->editColumn('visibility',function(Role $role) {
|
||||
if($role->visibility == 'visible'){
|
||||
return '<span class="badge text-bg-info">Visible</span>';
|
||||
} else {
|
||||
return '<span class="badge text-bg-danger">In-Visible</span>';
|
||||
}
|
||||
})
|
||||
->editColumn('availability',function(Role $role) {
|
||||
if($role->availability == 'available'){
|
||||
return '<span class="badge text-bg-info">Available</span>';
|
||||
} else {
|
||||
return '<span class="badge text-bg-danger">Un-Available</span>';
|
||||
}
|
||||
})
|
||||
->editColumn('status',function(Role $role) {
|
||||
if($role->status == 'active'){
|
||||
return '<span class="badge text-bg-info">Active</span>';
|
||||
} else {
|
||||
return '<span class="badge text-bg-danger">In-Active</span>';
|
||||
}
|
||||
})
|
||||
->editcolumn('actions',function(Role $role) {
|
||||
$editRoute = route('role.edit',$role->id);
|
||||
$deleteRoute = route('role.destroy',$role->id);
|
||||
return getTableHtml($role,'actions',$editRoute,$deleteRoute);
|
||||
return getTableHtml($role,'image');
|
||||
})->rawColumns(['visibility','availability','status','image'])->make(true);
|
||||
}
|
||||
|
||||
public function create(array $data)
|
||||
{
|
||||
try {
|
||||
/* $data['keywords'] = '"'.$data['keywords'].'"';*/
|
||||
$data['visibility'] = (isset($data['visibility']) ? $data['visibility'] : '')=='on' ? 'visible' : 'invisible';
|
||||
$data['status'] = (isset($data['status']) ? $data['status'] : '')=='on' ? 'active' : 'in_active';
|
||||
$data['availability'] = (isset($data['availability']) ? $data['availability'] : '')=='on' ? 'available' : 'not_available';
|
||||
$data['created_by']= Auth::role()->id;
|
||||
//dd($data);
|
||||
$role = $this->role->create($data);
|
||||
return $role;
|
||||
|
||||
} catch (Exception $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Paginate all role
|
||||
*
|
||||
* @param array $filter
|
||||
* @return Collection
|
||||
*/
|
||||
public function paginate(array $filter = [])
|
||||
{
|
||||
$filter['limit'] = 25;
|
||||
|
||||
return $this->role->orderBy('id','DESC')->whereIsDeleted('no')->paginate($filter['limit']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all role
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function all()
|
||||
{
|
||||
return $this->role->whereIsDeleted('no')->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all roles with supervisor type
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
|
||||
|
||||
public function find($roleId)
|
||||
{
|
||||
try {
|
||||
return $this->role->whereIsDeleted('no')->find($roleId);
|
||||
} catch (Exception $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function update($roleId, array $data)
|
||||
{
|
||||
try {
|
||||
|
||||
$data['visibility'] = (isset($data['visibility']) ? $data['visibility'] : '')=='on' ? 'visible' : 'invisible';
|
||||
$data['status'] = (isset($data['status']) ? $data['status'] : '')=='on' ? 'active' : 'in_active';
|
||||
$data['availability'] = (isset($data['availability']) ? $data['availability'] : '')=='on' ? 'available' : 'not_available';
|
||||
$data['has_subrole'] = (isset($data['has_subrole']) ? $data['has_subrole'] : '')=='on' ? 'yes' : 'no';
|
||||
$data['last_updated_by']= Auth::role()->id;
|
||||
$role= $this->role->find($roleId);
|
||||
|
||||
$role = $role->update($data);
|
||||
//$this->logger->info(' created successfully', $data);
|
||||
|
||||
return $role;
|
||||
} catch (Exception $e) {
|
||||
//$this->logger->error($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a role
|
||||
*
|
||||
* @param Id
|
||||
* @return bool
|
||||
*/
|
||||
public function delete($roleId)
|
||||
{
|
||||
try {
|
||||
|
||||
$data['last_deleted_by']= Auth::user()->id;
|
||||
$data['deleted_at']= Carbon::now();
|
||||
$role = $this->role->find($roleId);
|
||||
$data['is_deleted']='yes';
|
||||
return $role = $role->update($data);
|
||||
|
||||
} catch (Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* write brief description
|
||||
* @param $name
|
||||
* @return mixed
|
||||
*/
|
||||
public function getByName($name){
|
||||
return $this->role->whereIsDeleted('no')->whereName($name);
|
||||
}
|
||||
|
||||
public function getBySlug($slug){
|
||||
return $this->role->whereIsDeleted('no')->whereSlug($slug)->first();
|
||||
}
|
||||
|
||||
public function getAssignedPermission($id){
|
||||
try{
|
||||
$role = Role::with('permissions')->find($id);
|
||||
$per = $role->permissions;
|
||||
return $per;
|
||||
}catch (Exception $e){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function uploadFile($file)
|
||||
{
|
||||
if (!empty($file)) {
|
||||
$this->uploadPath = 'uploads/role';
|
||||
return $fileName = $this->uploadFromAjax($file);
|
||||
}
|
||||
}
|
||||
|
||||
public function __deleteImages($subCat)
|
||||
{
|
||||
try {
|
||||
if (is_file($subCat->image_path))
|
||||
unlink($subCat->image_path);
|
||||
|
||||
if (is_file($subCat->thumbnail_path))
|
||||
unlink($subCat->thumbnail_path);
|
||||
} catch (\Exception $e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function updateImage($roleId, array $data)
|
||||
{
|
||||
try {
|
||||
$role = $this->role->find($roleId);
|
||||
$role = $role->update($data);
|
||||
|
||||
return $role;
|
||||
} catch (Exception $e) {
|
||||
//$this->logger->error($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
185
app/Modules/Service/Service.php
Normal file
185
app/Modules/Service/Service.php
Normal file
@@ -0,0 +1,185 @@
|
||||
<?php
|
||||
namespace App\Modules\Service;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Intervention\Image\Facades\Image;
|
||||
use Symfony\Component\HttpFoundation\File\File;
|
||||
|
||||
/**
|
||||
* Class Service
|
||||
*
|
||||
* @package App\Services
|
||||
*/
|
||||
abstract class Service
|
||||
{
|
||||
|
||||
protected $uploadPath = '/uploads';
|
||||
|
||||
public function upload(UploadedFile $file, $width = 1170, $height = 559)
|
||||
{
|
||||
if(!is_dir('uploads'))
|
||||
mkdir('uploads');
|
||||
|
||||
if(!is_dir($this->uploadPath))
|
||||
mkdir($this->uploadPath);
|
||||
|
||||
$destination = $this->uploadPath;
|
||||
if ($file->isValid()) {
|
||||
$fileName = $file->getClientOriginalName();
|
||||
$file_type = $file->getClientOriginalExtension();
|
||||
$newFileName = sprintf("%s.%s", sha1($fileName . time()), $file_type);
|
||||
try {
|
||||
$image = $file->move($destination, $newFileName);
|
||||
if(substr($file->getClientMimeType(), 0, 5) == 'image')
|
||||
$this->createThumb($image, $width, $height);
|
||||
return $image->getFilename();
|
||||
} catch (Exception $e) {
|
||||
return $e->getMessage();
|
||||
$this->logger->error(sprintf('File could not be uploaded : %s', $e->getMessage()));
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function uploadFromAjax(UploadedFile $file, $width = 320, $height = 320)
|
||||
{
|
||||
if (!is_dir('uploads'))
|
||||
mkdir('uploads');
|
||||
|
||||
if (!is_dir($this->uploadPath))
|
||||
mkdir($this->uploadPath);
|
||||
|
||||
$destination = $this->uploadPath;
|
||||
if ($file->isValid()) {
|
||||
$fileName = $file->getClientOriginalName();
|
||||
$file_type = $file->extension();
|
||||
$newFileName = sprintf("%s.%s", sha1($fileName . time()), $file_type);
|
||||
try {
|
||||
$image = $file->move($destination, $newFileName);
|
||||
if (substr($file->getClientMimeType(), 0, 5) == 'image')
|
||||
$this->createThumb($image, $width, $height);
|
||||
return $image->getFilename();
|
||||
} catch (Exception $e) {
|
||||
return $e->getMessage();
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Create Image thumb
|
||||
*
|
||||
* @param File $image
|
||||
* @param int $width
|
||||
* @param int $height
|
||||
* @return boolean
|
||||
*/
|
||||
public function createThumb(File $image, $width = 320, $height = 320)
|
||||
{
|
||||
try{
|
||||
$img = Image::make($image->getPathname());
|
||||
$img->fit($width, $height);
|
||||
$path = sprintf('%s/thumb/%s', $image->getPath(), $image->getFilename());
|
||||
$directory = sprintf('%s/thumb', $image->getPath());
|
||||
if (!file_exists($directory)) {
|
||||
mkdir($directory, 0777, true);
|
||||
}
|
||||
return $img->save($path);
|
||||
}catch (\Exception $e){
|
||||
return '';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete Image
|
||||
*
|
||||
* @param $image
|
||||
* @return bool
|
||||
*/
|
||||
public function deleteImage($image)
|
||||
{
|
||||
$path = $this->uploadPath;
|
||||
try {
|
||||
$large = $path . '/' . $image;
|
||||
unlink($large);
|
||||
$thumb = sprintf('%s/thumb/%s', $path, $image);
|
||||
unlink($thumb);
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteMultipleImages($images)
|
||||
{
|
||||
$path = $this->uploadPath;
|
||||
try {
|
||||
foreach ($images as $image) {
|
||||
$large = $path . '/' . $image;
|
||||
unlink($large);
|
||||
$thumb = sprintf('%s/thumb/%s', $path, $image);
|
||||
unlink($thumb);
|
||||
}
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function uploadExcel($file) {
|
||||
$destinationPath = base_path() . '/public/uploads';
|
||||
|
||||
$fileName = $file->getClientOriginalName();
|
||||
$file_type = $file->getClientOriginalExtension();
|
||||
|
||||
$newFileName = sprintf("%s.%s", sha1($fileName . time()), $file_type);
|
||||
|
||||
try {
|
||||
return $file->move($destinationPath, $newFileName);
|
||||
} catch (Exception $e) {
|
||||
$this->logger->error(sprintf('File could not be uploaded : %s', $e->getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
public function uploadFile($file) {
|
||||
$destination = $this->uploadPath;
|
||||
|
||||
$fileName = $file->getClientOriginalName();
|
||||
$file_type = $file->getClientOriginalExtension();
|
||||
|
||||
$newFileName = sprintf("%s.%s", sha1($fileName . time()), $file_type);
|
||||
|
||||
try {
|
||||
$file->move($destination, $newFileName);
|
||||
|
||||
return $newFileName;
|
||||
} catch (Exception $e) {
|
||||
$this->logger->error(sprintf('File could not be uploaded : %s', $e->getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteFile($file)
|
||||
{
|
||||
$path = $this->uploadPath;
|
||||
try {
|
||||
$large = $path . '/' . $file;
|
||||
unlink($large);
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function generateCode($base = '') {
|
||||
return sha1($base . rand() . time());
|
||||
}
|
||||
|
||||
}
|
272
app/Modules/Service/User/UserService.php
Normal file
272
app/Modules/Service/User/UserService.php
Normal file
@@ -0,0 +1,272 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Service\User;
|
||||
|
||||
use App\Modules\Models\User;
|
||||
use App\Modules\Service\Service;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Yajra\DataTables\Facades\DataTables;
|
||||
|
||||
class UserService extends Service
|
||||
{
|
||||
protected $user;
|
||||
|
||||
public function __construct(User $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*For DataTable*/
|
||||
public function getAllData()
|
||||
|
||||
{
|
||||
$query = $this->user->whereIsDeleted('no');
|
||||
return DataTables::of($query)
|
||||
->addIndexColumn()
|
||||
// ->editColumn('brand',function(user $user) {
|
||||
// if($user->brand->name) {
|
||||
// return $user->brand->name;
|
||||
// }
|
||||
// })
|
||||
// ->editColumn('category',function(user $user) {
|
||||
// if($user->category->name) {
|
||||
// return $user->category->name;
|
||||
// }
|
||||
// })
|
||||
->editColumn('visibility',function(user $user) {
|
||||
if($user->visibility == 'visible'){
|
||||
return '<span class="badge text-bg-info">Visible</span>';
|
||||
} else {
|
||||
return '<span class="badge text-bg-danger">In-visible</span>';
|
||||
}
|
||||
})
|
||||
->editColumn('availability',function(user $user) {
|
||||
if($user->availability == 'available'){
|
||||
return '<span class="badge text-bg-info">Available</span>';
|
||||
} else {
|
||||
return '<span class="badge text-bg-danger">Un-Available</span>';
|
||||
}
|
||||
})
|
||||
->editColumn('status',function(user $user) {
|
||||
if($user->status == 'active'){
|
||||
return '<span class="badge text-bg-info">Active</span>';
|
||||
} else {
|
||||
return '<span class="badge text-bg-danger">In-Active</span>';
|
||||
}
|
||||
})
|
||||
->editColumn('image',function(user $user) {
|
||||
if(isset($user->image_path)){
|
||||
return '<img src="http://127.0.0.1:8000/'.($user->image_path).'" width="100px">';
|
||||
} else {
|
||||
;
|
||||
}
|
||||
})
|
||||
->editcolumn('actions',function(user $user) {
|
||||
$editRoute = route('user.edit',$user->id);
|
||||
$deleteRoute = route('user.destroy',$user->id);
|
||||
return getTableHtml($user,'actions',$editRoute,$deleteRoute);
|
||||
return getTableHtml($user,'image');
|
||||
})->rawColumns(['visibility','availability','status','image'])->make(true);
|
||||
}
|
||||
|
||||
public function create(array $data)
|
||||
{
|
||||
try {
|
||||
// dd($data);
|
||||
/* $data['keywords'] = '"'.$data['keywords'].'"';*/
|
||||
$data['visibility'] = (isset($data['visibility']) ? $data['visibility'] : '')=='on' ? 'visible' : 'invisible';
|
||||
$data['status'] = (isset($data['status']) ? $data['status'] : '')=='on' ? 'active' : 'in_active';
|
||||
$data['availability'] = (isset($data['availability']) ? $data['availability'] : '')=='on' ? 'available' : 'not_available';
|
||||
$data['created_by']= Auth::user()->id;
|
||||
$data['password'] = Hash::make($data['password']);
|
||||
//dd($data);
|
||||
$user = $this->user->create($data);
|
||||
return $user;
|
||||
|
||||
} catch (Exception $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Paginate all User
|
||||
*
|
||||
* @param array $filter
|
||||
* @return Collection
|
||||
*/
|
||||
public function paginate(array $filter = [])
|
||||
{
|
||||
$filter['limit'] = 25;
|
||||
|
||||
return $this->user->orderBy('id','DESC')->whereIsDeleted('no')->paginate($filter['limit']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all User
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function all()
|
||||
{
|
||||
return $this->user->whereIsDeleted('no')->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all users with supervisor type
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
|
||||
|
||||
public function find($userId)
|
||||
{
|
||||
try {
|
||||
return $this->user->whereIsDeleted('no')->find($userId);
|
||||
} catch (Exception $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function update($userId, array $data)
|
||||
{
|
||||
try {
|
||||
|
||||
$data['visibility'] = (isset($data['visibility']) ? $data['visibility'] : '')=='on' ? 'visible' : 'invisible';
|
||||
$data['status'] = (isset($data['status']) ? $data['status'] : '')=='on' ? 'active' : 'in_active';
|
||||
$data['availability'] = (isset($data['availability']) ? $data['availability'] : '')=='on' ? 'available' : 'not_available';
|
||||
$data['has_subuser'] = (isset($data['has_subuser']) ? $data['has_subuser'] : '')=='on' ? 'yes' : 'no';
|
||||
$data['last_updated_by']= Auth::user()->id;
|
||||
$user= $this->user->find($userId);
|
||||
|
||||
$user = $user->update($data);
|
||||
//$this->logger->info(' created successfully', $data);
|
||||
|
||||
return $user;
|
||||
} catch (Exception $e) {
|
||||
//$this->logger->error($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a User
|
||||
*
|
||||
* @param Id
|
||||
* @return bool
|
||||
*/
|
||||
public function delete($userId)
|
||||
{
|
||||
try {
|
||||
$data['last_deleted_by']= Auth::user()->id;
|
||||
$data['deleted_at']= Carbon::now();
|
||||
$user = $this->user->find($userId);
|
||||
$data['is_deleted']='yes';
|
||||
return $user = $user->update($data);
|
||||
|
||||
} catch (Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function getUserRoles($id){
|
||||
try{
|
||||
$user = User::with('roles')->find($id);
|
||||
$roles = $user->roles;
|
||||
return $roles;
|
||||
}catch (Exception $e){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* write brief description
|
||||
* @param $name
|
||||
* @return mixed
|
||||
*/
|
||||
public function getByName($name){
|
||||
return $this->user->whereIsDeleted('no')->whereName($name);
|
||||
}
|
||||
|
||||
public function getBySlug($id){
|
||||
return $this->user->whereIsDeleted('no')->whereId($id)->first();
|
||||
}
|
||||
|
||||
|
||||
function uploadFile($file)
|
||||
{
|
||||
if (!empty($file)) {
|
||||
$this->uploadPath = 'uploads/user';
|
||||
return $fileName = $this->uploadFromAjax($file);
|
||||
}
|
||||
}
|
||||
|
||||
public function __deleteImages($subCat)
|
||||
{
|
||||
try {
|
||||
if (is_file($subCat->image_path))
|
||||
unlink($subCat->image_path);
|
||||
|
||||
if (is_file($subCat->thumbnail_path))
|
||||
unlink($subCat->thumbnail_path);
|
||||
} catch (\Exception $e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function updateImage($userId, array $data)
|
||||
{
|
||||
try {
|
||||
$user = $this->user->find($userId);
|
||||
$user = $user->update($data);
|
||||
|
||||
return $user;
|
||||
} catch (Exception $e) {
|
||||
//$this->logger->error($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function profileUpdate(array $data, $userId)
|
||||
{
|
||||
try {
|
||||
$data['email'] = $data['email'];
|
||||
$data['password'] = Hash::make($data['password']);
|
||||
$data['last_updated_by']= Auth::user()->id;
|
||||
$user= $this->user->find($userId);
|
||||
$user = $user->update($data);
|
||||
//$this->logger->info(' created successfully', $data);
|
||||
|
||||
return $user;
|
||||
} catch (Exception $e) {
|
||||
//$this->logger->error($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function passwordUpdate(array $data)
|
||||
{
|
||||
try {
|
||||
$user= $this->user->where('email',$data['email'])->first();
|
||||
if(isset($user)) {
|
||||
$data['password'] = Hash::make($data['password']);
|
||||
$user = $user->update($data);
|
||||
} else {
|
||||
Toastr()->error('The requested email does not exist','Sorry');
|
||||
return false;
|
||||
}
|
||||
//$this->logger->info(' created successfully', $data);
|
||||
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
//$this->logger->error($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
75
app/Modules/Service/UserRole/UserRoleService.php
Normal file
75
app/Modules/Service/UserRole/UserRoleService.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: aarrunyal
|
||||
* Date: 03/01/2019
|
||||
* Time: 17:53
|
||||
*/
|
||||
|
||||
namespace App\Modules\Service\UserRole;
|
||||
|
||||
use App\Modules\Models\Role\PermissionRole;
|
||||
use App\Modules\Models\User\RoleUser;
|
||||
|
||||
class UserRoleService
|
||||
{
|
||||
protected $userRole;
|
||||
protected $rolePermission;
|
||||
|
||||
function __construct(
|
||||
RoleUser $userRoleModel,
|
||||
PermissionRole $rolePermissionModel
|
||||
)
|
||||
{
|
||||
$this->userRole = $userRoleModel;
|
||||
$this->rolePermission = $rolePermissionModel;
|
||||
}
|
||||
|
||||
//User role deletion using roleid and userid
|
||||
public function deleteUserRoleByUserId($id){
|
||||
try{
|
||||
$role = $this->userRole->where('user_id', '=', $id)->delete();
|
||||
return true;
|
||||
}catch (Exception $e){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteUserRoleByRoleId($id){
|
||||
try{
|
||||
$role = $this->userRole->where('role_id', '=', $id)->delete();
|
||||
return true;
|
||||
}catch (Exception $e){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//permission deletion using roleid and permissionid
|
||||
public function deleteRolePermissionByPermissionId($id){
|
||||
try{
|
||||
$permission = $this->rolePermission->where('permission_id', '=', $id)->delete();
|
||||
return true;
|
||||
}catch (Exception $e){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteRolePermissionByRoleId($id){
|
||||
try{
|
||||
$permission = $this->rolePermission->where('role_id', '=', $id)->delete();
|
||||
return true;
|
||||
}catch (Exception $e){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function getAllUserWithRoleId($roleId){
|
||||
try{
|
||||
$users = $this->userRole->where('role_id','=', $roleId)->get();
|
||||
return $users;
|
||||
}catch (\Exception $e){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user