2016-08-02 22:59:39 -04:00
|
|
|
<?php namespace App\Http\Controllers;
|
2016-01-26 23:20:08 -05:00
|
|
|
|
2018-04-24 20:38:04 -04:00
|
|
|
use Auth;
|
2018-01-11 01:13:58 -05:00
|
|
|
use File;
|
2016-01-26 23:20:08 -05:00
|
|
|
use Image;
|
2024-03-19 17:11:58 -04:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Routing\Controllers\HasMiddleware;
|
|
|
|
use Illuminate\Routing\Controllers\Middleware;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
2020-12-09 16:00:01 -05:00
|
|
|
use App\Models\User;
|
2018-04-23 23:39:40 -04:00
|
|
|
use App\Dashboard;
|
2016-01-26 23:20:08 -05:00
|
|
|
|
2024-03-19 17:11:58 -04:00
|
|
|
class DashboardController extends Controller implements HasMiddleware
|
|
|
|
{
|
2016-01-26 23:20:08 -05:00
|
|
|
/**
|
2024-03-19 17:11:58 -04:00
|
|
|
* Get the middleware that should be assigned to the controller.
|
2016-01-26 23:20:08 -05:00
|
|
|
*/
|
2024-03-19 17:11:58 -04:00
|
|
|
public static function middleware(): array
|
2016-01-26 23:20:08 -05:00
|
|
|
{
|
2024-03-19 17:11:58 -04:00
|
|
|
return [ 'auth' ];
|
2016-01-26 23:20:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-04-25 01:22:33 -04:00
|
|
|
* Dashboard CMS
|
2016-01-26 23:20:08 -05:00
|
|
|
*/
|
2018-04-18 23:32:22 -04:00
|
|
|
public function getIndex()
|
2016-01-26 23:20:08 -05:00
|
|
|
{
|
2018-04-24 20:38:04 -04:00
|
|
|
return view('dashboard.pages.home');
|
2016-01-26 23:20:08 -05:00
|
|
|
}
|
|
|
|
|
2021-07-29 16:40:55 -04:00
|
|
|
// Page to View Model Data
|
2018-04-18 00:38:11 -04:00
|
|
|
public function getView($model)
|
2016-01-26 23:20:08 -05:00
|
|
|
{
|
2018-04-18 00:38:11 -04:00
|
|
|
$model_class = Dashboard::getModel($model, 'view');
|
|
|
|
|
|
|
|
if ($model_class != null) {
|
2018-04-24 20:38:04 -04:00
|
|
|
return view('dashboard.pages.view', [
|
2021-07-29 16:40:55 -04:00
|
|
|
'heading' => $model_class->getDashboardHeading(),
|
2018-04-18 00:38:11 -04:00
|
|
|
'column_headings' => $model_class::getDashboardColumnData('headings'),
|
|
|
|
'model' => $model,
|
|
|
|
'rows' => $model_class::getDashboardData(),
|
|
|
|
'columns' => $model_class::$dashboard_columns
|
|
|
|
]);
|
|
|
|
} else {
|
|
|
|
abort(404);
|
|
|
|
}
|
2016-01-26 23:20:08 -05:00
|
|
|
}
|
|
|
|
|
2021-07-29 16:40:55 -04:00
|
|
|
// Page to Edit List of Model Rows
|
2018-04-18 00:38:11 -04:00
|
|
|
public function getEditList($model)
|
2016-01-26 23:20:08 -05:00
|
|
|
{
|
2018-04-18 00:38:11 -04:00
|
|
|
$model_class = Dashboard::getModel($model, 'edit');
|
|
|
|
|
|
|
|
if ($model_class != null) {
|
2020-04-24 00:22:42 -04:00
|
|
|
$data = $model_class::getDashboardData(true);
|
|
|
|
|
2018-04-24 20:38:04 -04:00
|
|
|
return view('dashboard.pages.edit-list', [
|
2021-07-29 16:40:55 -04:00
|
|
|
'heading' => $model_class->getDashboardHeading(),
|
2020-04-24 00:22:42 -04:00
|
|
|
'model' => $model,
|
|
|
|
'rows' => $data['rows'],
|
|
|
|
'paramdisplay' => $data['paramdisplay'],
|
|
|
|
'query' => $model_class::getQueryString(),
|
|
|
|
'display' => $model_class::$dashboard_display,
|
2022-07-25 17:16:55 -04:00
|
|
|
'columns' => $model_class::$dashboard_columns,
|
2020-04-24 00:22:42 -04:00
|
|
|
'button' => $model_class::$dashboard_button,
|
|
|
|
'idlink' => $model_class::$dashboard_id_link,
|
|
|
|
'sortcol' => $model_class::$dashboard_reorder ? $model_class::$dashboard_sort_column : false,
|
|
|
|
'paginate' => $model_class::$items_per_page !== 0,
|
|
|
|
'create' => $model_class::$create,
|
|
|
|
'delete' => $model_class::$delete,
|
|
|
|
'filter' => $model_class::$filter,
|
|
|
|
'export' => $model_class::$export
|
2018-04-18 00:38:11 -04:00
|
|
|
]);
|
|
|
|
} else {
|
|
|
|
abort(404);
|
|
|
|
}
|
2016-01-26 23:20:08 -05:00
|
|
|
}
|
|
|
|
|
2021-07-29 16:40:55 -04:00
|
|
|
// Page to Create and Edit Model Item
|
2018-04-18 00:38:11 -04:00
|
|
|
public function getEditItem($model, $id = 'new')
|
|
|
|
{
|
|
|
|
$model_class = Dashboard::getModel($model, 'edit');
|
|
|
|
|
|
|
|
if ($model_class != null) {
|
|
|
|
if ($id == 'new') {
|
2022-06-14 01:36:21 -04:00
|
|
|
$item = new $model_class;
|
2018-04-18 00:38:11 -04:00
|
|
|
} else {
|
|
|
|
if ($model_class::where('id', $id)->exists()) {
|
|
|
|
$item = $model_class::find($id);
|
|
|
|
|
|
|
|
if (is_null($item) || !$item->userCheck()) {
|
|
|
|
return view('errors.no-such-record');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return view('errors.no-such-record');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-14 01:36:21 -04:00
|
|
|
foreach ($model_class::$dashboard_columns as $column) {
|
|
|
|
if ($column['type'] === 'list') {
|
|
|
|
$list_model_class = 'App\\Models\\' . $column['model'];
|
|
|
|
$list_model_instance = new $list_model_class;
|
|
|
|
|
|
|
|
$item->{$column['name']} = [
|
|
|
|
'model' => $list_model_instance->getTable(),
|
|
|
|
'list' => $id == 'new' ? [] : $list_model_instance::where($column['foreign'], $item->id)->orderBy($column['sort'])->get()
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-24 20:38:04 -04:00
|
|
|
return view('dashboard.pages.edit-item', [
|
2022-06-14 01:36:21 -04:00
|
|
|
'heading' => $model_class->getDashboardHeading(),
|
|
|
|
'default_img_ext' => $model_class::$default_image_ext,
|
|
|
|
'model' => $model,
|
|
|
|
'id' => $id,
|
|
|
|
'item' => $item,
|
|
|
|
'help_text' => $model_class::$dashboard_help_text,
|
|
|
|
'columns' => $model_class::$dashboard_columns
|
2018-04-18 00:38:11 -04:00
|
|
|
]);
|
|
|
|
} else {
|
|
|
|
abort(404);
|
|
|
|
}
|
|
|
|
}
|
2016-01-26 23:20:08 -05:00
|
|
|
|
2018-04-25 01:22:33 -04:00
|
|
|
// Export Spreadsheet of Model Data
|
2016-01-26 23:20:08 -05:00
|
|
|
public function getExport($model)
|
|
|
|
{
|
2018-04-18 00:38:11 -04:00
|
|
|
$model_class = Dashboard::getModel($model);
|
|
|
|
|
|
|
|
if ($model_class != null && $model_class::$export) {
|
2018-07-12 11:40:33 -04:00
|
|
|
$filename = preg_replace([ '/\ /', '/[^a-z0-9\-]/' ], [ '-', '' ], strtolower(env('APP_NAME'))) . '-' . $model . '-' . date('m-d-Y') . '.xlsx';
|
2018-04-18 00:38:11 -04:00
|
|
|
$headings = $model_class::getDashboardColumnData('headings', false);
|
|
|
|
$items = $model_class::select($model_class::getDashboardColumnData('names', false))->get()->toArray();
|
|
|
|
array_unshift($items, $headings);
|
|
|
|
$spreadsheet = new Spreadsheet();
|
|
|
|
$spreadsheet->getActiveSheet()->getDefaultColumnDimension()->setWidth(25);
|
|
|
|
$spreadsheet->getActiveSheet()->fromArray($items, NULL, 'A1');
|
|
|
|
$writer = new Xlsx($spreadsheet);
|
|
|
|
header('Content-Type: application/vnd.ms-excel');
|
|
|
|
header('Content-Disposition: attachment;filename="' . $filename . '"');
|
|
|
|
header('Cache-Control: max-age=0');
|
|
|
|
$writer->save('php://output');
|
|
|
|
} else {
|
|
|
|
abort(404);
|
2016-01-26 23:20:08 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-25 01:22:33 -04:00
|
|
|
// Reorder Model Rows
|
2018-04-18 00:38:11 -04:00
|
|
|
public function postReorder(Request $request)
|
2016-01-26 23:20:08 -05:00
|
|
|
{
|
2024-03-19 17:11:58 -04:00
|
|
|
$request->validate([
|
2018-04-18 00:38:11 -04:00
|
|
|
'order' => 'required',
|
|
|
|
'column' => 'required',
|
|
|
|
'model' => 'required'
|
2018-01-18 22:29:49 -05:00
|
|
|
]);
|
|
|
|
|
2018-04-18 00:38:11 -04:00
|
|
|
$model_class = Dashboard::getModel($request['model'], 'edit');
|
2016-01-26 23:20:08 -05:00
|
|
|
|
2018-04-18 00:38:11 -04:00
|
|
|
if ($model_class != null) {
|
|
|
|
$order = $request['order'];
|
|
|
|
$column = $request['column'];
|
2016-01-26 23:20:08 -05:00
|
|
|
|
2018-04-18 00:38:11 -04:00
|
|
|
// update each row with the new order
|
|
|
|
foreach (array_keys($order) as $order_id) {
|
|
|
|
$item = $model_class::find($order_id);
|
|
|
|
$item->$column = $order[$order_id];
|
|
|
|
$item->save();
|
|
|
|
}
|
2018-01-18 22:29:49 -05:00
|
|
|
|
2018-04-18 00:38:11 -04:00
|
|
|
return 'success';
|
2018-01-18 22:29:49 -05:00
|
|
|
} else {
|
2018-04-18 00:38:11 -04:00
|
|
|
return 'model-access-fail';
|
2018-01-18 22:29:49 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-25 01:22:33 -04:00
|
|
|
// Create and Update Model Item Data
|
2018-04-18 00:38:11 -04:00
|
|
|
public function postUpdate(Request $request)
|
2016-01-26 23:20:08 -05:00
|
|
|
{
|
2024-03-19 17:11:58 -04:00
|
|
|
$request->validate([
|
2016-01-26 23:20:08 -05:00
|
|
|
'id' => 'required',
|
|
|
|
'model' => 'required',
|
|
|
|
'columns' => 'required'
|
|
|
|
]);
|
|
|
|
|
2018-04-18 00:38:11 -04:00
|
|
|
$model_class = Dashboard::getModel($request['model'], 'edit');
|
2016-01-26 23:20:08 -05:00
|
|
|
|
2018-04-18 00:38:11 -04:00
|
|
|
if ($model_class != null) {
|
|
|
|
if ($request['id'] == 'new') {
|
|
|
|
$item = new $model_class;
|
2018-05-01 20:14:00 -04:00
|
|
|
|
|
|
|
if ($model_class::$dashboard_reorder) {
|
|
|
|
$item->{$model_class::$dashboard_sort_column} = $model_class::count();
|
|
|
|
}
|
2018-04-18 00:38:11 -04:00
|
|
|
} else {
|
|
|
|
$item = $model_class::find($request['id']);
|
2016-01-26 23:20:08 -05:00
|
|
|
|
2018-04-18 00:38:11 -04:00
|
|
|
if (is_null($item)) {
|
|
|
|
return 'record-access-fail';
|
|
|
|
} else if (!$item->userCheck()) {
|
|
|
|
return 'permission-fail';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-24 00:22:42 -04:00
|
|
|
// check to ensure required columns have values
|
|
|
|
$empty = [];
|
|
|
|
|
|
|
|
foreach ($model_class::$dashboard_columns as $column) {
|
|
|
|
if ($request->has($column['name']) && array_key_exists('required', $column) && $column['required'] && ($request[$column['name']] == '' || $request[$column['name']] == null)) {
|
|
|
|
if (array_key_exists('title', $column)) {
|
|
|
|
array_push($empty, "'" . $column['title'] . "'");
|
|
|
|
} else {
|
|
|
|
array_push($empty, "'" . ucfirst($column['name']) . "'");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count($empty) > 0) {
|
|
|
|
return 'required:' . implode(',', $empty);
|
|
|
|
}
|
|
|
|
|
2023-07-03 22:18:19 -04:00
|
|
|
// check to ensure unique columns are unique when they aren't empty
|
2020-04-24 00:22:42 -04:00
|
|
|
$not_unique = [];
|
|
|
|
|
|
|
|
foreach ($model_class::$dashboard_columns as $column) {
|
2023-07-03 22:18:19 -04:00
|
|
|
$column_name = $column['name'];
|
|
|
|
|
|
|
|
if ($request->has($column['name']) && $request->$column_name != '' && array_key_exists('unique', $column) && $column['unique'] && $model_class::where($column['name'], $request[$column['name']])->where('id', '!=', $item->id)->exists()) {
|
2020-04-24 00:22:42 -04:00
|
|
|
if (array_key_exists('title', $column)) {
|
|
|
|
array_push($not_unique, "'" . $column['title'] . "'");
|
|
|
|
} else {
|
|
|
|
array_push($not_unique, "'" . ucfirst($column['name']) . "'");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count($not_unique) > 0) {
|
|
|
|
return 'not-unique:' . implode(',', $not_unique);
|
|
|
|
}
|
|
|
|
|
|
|
|
// populate the eloquent object with the non-list items in $request
|
|
|
|
foreach ($request['columns'] as $column) {
|
|
|
|
if ($column['type'] !== 'list') {
|
|
|
|
$column_name = $column['name'];
|
|
|
|
$item->$column_name = $request[$column_name];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// save the item if it's new so we can access its id
|
|
|
|
if ($request['id'] == 'new') {
|
|
|
|
$item->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
// populate connected lists with list items in $request
|
2022-06-14 01:36:21 -04:00
|
|
|
$lists = [];
|
|
|
|
|
2018-04-18 00:38:11 -04:00
|
|
|
foreach ($request['columns'] as $column) {
|
2020-04-24 00:22:42 -04:00
|
|
|
if ($column['type'] === 'list') {
|
|
|
|
$column_name = $column['name'];
|
|
|
|
|
|
|
|
foreach ($model_class::$dashboard_columns as $dashboard_column) {
|
|
|
|
if ($dashboard_column['name'] === $column_name) {
|
|
|
|
$foreign = $dashboard_column['foreign'];
|
|
|
|
$list_model_class = 'App\\Models\\' . $dashboard_column['model'];
|
|
|
|
|
2022-06-14 01:36:21 -04:00
|
|
|
if ($list_model_class::$dashboard_type == 'list') {
|
|
|
|
$ids = [];
|
|
|
|
|
|
|
|
if ($request->has($column_name)) {
|
|
|
|
foreach ($request[$column_name] as $index => $row) {
|
|
|
|
if ($row['id'] == 'new') {
|
|
|
|
$list_model_item = new $list_model_class;
|
|
|
|
} else {
|
|
|
|
$list_model_item = $list_model_class::find($row['id']);
|
|
|
|
}
|
|
|
|
|
|
|
|
$list_model_item->$foreign = $item->id;
|
|
|
|
$list_model_item->{$dashboard_column['sort']} = $index;
|
2020-04-24 00:22:42 -04:00
|
|
|
|
2022-06-14 01:36:21 -04:00
|
|
|
foreach ($row['data'] as $key => $data) {
|
|
|
|
if ($data['type'] == 'string') {
|
|
|
|
$list_model_item->$key = $data['value'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$list_model_item->save();
|
|
|
|
array_push($ids, $list_model_item->id);
|
2020-04-24 00:22:42 -04:00
|
|
|
}
|
2022-06-14 01:36:21 -04:00
|
|
|
}
|
2020-04-24 00:22:42 -04:00
|
|
|
|
2022-06-14 01:36:21 -04:00
|
|
|
// delete any associated row that wasn't just created or edited
|
|
|
|
foreach ($list_model_class::where($foreign, $item->id)->whereNotIn('id', $ids)->get() as $list_item) {
|
|
|
|
$list_item->delete();
|
2020-04-24 00:22:42 -04:00
|
|
|
}
|
2022-06-14 01:36:21 -04:00
|
|
|
|
|
|
|
// store the sets of ids for each list
|
|
|
|
$lists[$column_name] = $ids;
|
|
|
|
|
|
|
|
// stop looping through dashboard columns
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
return 'invalid-list-model:' . $dashboard_column['model'];
|
2020-04-24 00:22:42 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-04-18 00:38:11 -04:00
|
|
|
}
|
2016-01-26 23:20:08 -05:00
|
|
|
|
2020-04-24 00:22:42 -04:00
|
|
|
// update the item
|
2018-04-18 00:38:11 -04:00
|
|
|
$item->save();
|
2016-01-26 23:20:08 -05:00
|
|
|
|
2018-04-18 00:38:11 -04:00
|
|
|
// return the id number in the format '^id:[0-9][0-9]*$' on success
|
2022-06-14 01:36:21 -04:00
|
|
|
return [
|
|
|
|
'id' => $item->id,
|
|
|
|
'lists' => $lists
|
|
|
|
];
|
2018-04-18 00:38:11 -04:00
|
|
|
} else {
|
|
|
|
return 'model-access-fail';
|
|
|
|
}
|
2016-01-26 23:20:08 -05:00
|
|
|
}
|
|
|
|
|
2018-04-25 01:22:33 -04:00
|
|
|
// Upload Model Item Image
|
2018-04-18 00:38:11 -04:00
|
|
|
public function postImageUpload(Request $request)
|
2016-01-26 23:20:08 -05:00
|
|
|
{
|
2024-03-19 17:11:58 -04:00
|
|
|
$request->validate([
|
2018-04-18 00:38:11 -04:00
|
|
|
'id' => 'required',
|
|
|
|
'model' => 'required',
|
|
|
|
'name' => 'required'
|
2016-01-26 23:20:08 -05:00
|
|
|
]);
|
|
|
|
|
2022-06-14 01:36:21 -04:00
|
|
|
$model_class = Dashboard::getModel($request['model'], [ 'edit', 'list' ]);
|
2018-04-18 00:38:11 -04:00
|
|
|
|
|
|
|
if ($model_class != null) {
|
|
|
|
$item = $model_class::find($request['id']);
|
|
|
|
|
|
|
|
if (is_null($item)) {
|
|
|
|
return 'record-access-fail';
|
|
|
|
} else if ($request->hasFile('file')) {
|
2021-07-29 16:40:55 -04:00
|
|
|
$save_result = $item->saveImage($request['name'], $request->file('file'));
|
|
|
|
|
|
|
|
if ($save_result == 'success') {
|
|
|
|
$item->touch();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $save_result;
|
2018-04-18 00:38:11 -04:00
|
|
|
} else {
|
|
|
|
return 'file-upload-fail';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return 'model-access-fail';
|
2016-01-26 23:20:08 -05:00
|
|
|
}
|
2018-04-18 00:38:11 -04:00
|
|
|
}
|
2016-01-26 23:20:08 -05:00
|
|
|
|
2018-04-25 01:22:33 -04:00
|
|
|
// Upload Model Item File
|
2018-04-18 00:38:11 -04:00
|
|
|
public function postFileUpload(Request $request)
|
|
|
|
{
|
2024-03-19 17:11:58 -04:00
|
|
|
$request->validate([
|
2018-04-18 00:38:11 -04:00
|
|
|
'id' => 'required',
|
|
|
|
'model' => 'required',
|
2021-07-29 16:40:55 -04:00
|
|
|
'name' => 'required'
|
2018-04-18 00:38:11 -04:00
|
|
|
]);
|
|
|
|
|
2022-06-14 01:36:21 -04:00
|
|
|
$model_class = Dashboard::getModel($request['model'], [ 'edit', 'list' ]);
|
2018-04-18 00:38:11 -04:00
|
|
|
|
|
|
|
if ($model_class != null) {
|
|
|
|
$item = $model_class::find($request['id']);
|
|
|
|
|
|
|
|
if (is_null($item)) {
|
|
|
|
return 'record-access-fail';
|
|
|
|
} else if ($request->hasFile('file')) {
|
2021-07-29 16:40:55 -04:00
|
|
|
$save_result = $item->saveFile($request['name'], $request->file('file'));
|
|
|
|
|
|
|
|
if ($save_result == 'success') {
|
|
|
|
$item->touch();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $save_result;
|
2018-04-18 00:38:11 -04:00
|
|
|
} else {
|
|
|
|
return 'file-upload-fail';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return 'model-access-fail';
|
|
|
|
}
|
2016-01-26 23:20:08 -05:00
|
|
|
}
|
|
|
|
|
2018-04-25 01:22:33 -04:00
|
|
|
// Delete Model Item
|
2016-01-26 23:20:08 -05:00
|
|
|
public function deleteDelete(Request $request)
|
|
|
|
{
|
2024-03-19 17:11:58 -04:00
|
|
|
$request->validate([
|
2016-01-26 23:20:08 -05:00
|
|
|
'id' => 'required',
|
|
|
|
'model' => 'required'
|
|
|
|
]);
|
|
|
|
|
2018-04-18 00:38:11 -04:00
|
|
|
$model_class = Dashboard::getModel($request['model'], 'edit');
|
2016-01-26 23:20:08 -05:00
|
|
|
|
2018-04-18 00:38:11 -04:00
|
|
|
if ($model_class != null) {
|
|
|
|
$item = $model_class::find($request['id']);
|
2016-01-26 23:20:08 -05:00
|
|
|
|
2018-04-18 00:38:11 -04:00
|
|
|
if (is_null($item)) {
|
|
|
|
return 'record-access-fail';
|
|
|
|
} else if (!$item->userCheck()) {
|
|
|
|
return 'permission-fail';
|
|
|
|
}
|
2018-01-10 23:58:06 -05:00
|
|
|
|
2022-06-14 01:36:21 -04:00
|
|
|
// delete associated list items
|
|
|
|
foreach ($item::$dashboard_columns as $column) {
|
|
|
|
if ($column['type'] == 'list') {
|
|
|
|
$list_model_class = Dashboard::getModel($column['model'], 'list');
|
|
|
|
|
|
|
|
if ($list_model_class != null) {
|
|
|
|
foreach ($list_model_class::where($column['foreign'], $item->id)->get() as $list_item) {
|
|
|
|
$list_item->delete();
|
|
|
|
}
|
|
|
|
}
|
2018-01-18 22:29:49 -05:00
|
|
|
}
|
2018-01-11 01:13:58 -05:00
|
|
|
}
|
2016-01-26 23:20:08 -05:00
|
|
|
|
2021-07-29 16:40:55 -04:00
|
|
|
// delete the row
|
|
|
|
$item->delete();
|
|
|
|
|
2018-05-01 20:14:00 -04:00
|
|
|
// update the order of the remaining rows if $dashboard_reorder is true
|
|
|
|
if ($model_class::$dashboard_reorder) {
|
|
|
|
foreach ($model_class::getDashboardData() as $index => $item) {
|
|
|
|
$item->{$model_class::$dashboard_sort_column} = $index;
|
|
|
|
$item->save();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-18 00:38:11 -04:00
|
|
|
// Return a success
|
|
|
|
return 'success';
|
|
|
|
} else {
|
|
|
|
return 'model-access-fail';
|
|
|
|
}
|
2016-01-26 23:20:08 -05:00
|
|
|
}
|
2016-08-02 22:58:40 -04:00
|
|
|
|
2018-04-25 01:22:33 -04:00
|
|
|
// Delete Model Item Image
|
2018-01-21 20:55:07 -05:00
|
|
|
public function deleteImageDelete(Request $request)
|
|
|
|
{
|
2024-03-19 17:11:58 -04:00
|
|
|
$request->validate([
|
2018-01-21 20:55:07 -05:00
|
|
|
'id' => 'required',
|
|
|
|
'model' => 'required',
|
|
|
|
'name' => 'required'
|
|
|
|
]);
|
|
|
|
|
2022-06-14 01:36:21 -04:00
|
|
|
$model_class = Dashboard::getModel($request['model'], [ 'edit', 'list' ]);
|
2018-01-21 20:55:07 -05:00
|
|
|
|
2018-04-18 00:38:11 -04:00
|
|
|
if ($model_class != null) {
|
|
|
|
$item = $model_class::find($request['id']);
|
2018-01-21 20:55:07 -05:00
|
|
|
|
2018-04-18 00:38:11 -04:00
|
|
|
if (is_null($item)) {
|
|
|
|
return 'record-access-fail';
|
|
|
|
}
|
|
|
|
|
2021-07-29 16:40:55 -04:00
|
|
|
return $item->deleteImage($request['name'], true);
|
2018-04-18 00:38:11 -04:00
|
|
|
} else {
|
|
|
|
return 'model-access-fail';
|
|
|
|
}
|
2018-01-21 20:55:07 -05:00
|
|
|
}
|
|
|
|
|
2018-04-25 01:22:33 -04:00
|
|
|
// Delete Model Item File
|
2018-01-21 20:55:07 -05:00
|
|
|
public function deleteFileDelete(Request $request)
|
|
|
|
{
|
2024-03-19 17:11:58 -04:00
|
|
|
$request->validate([
|
2018-01-21 20:55:07 -05:00
|
|
|
'id' => 'required',
|
|
|
|
'model' => 'required',
|
2021-07-29 16:40:55 -04:00
|
|
|
'name' => 'required'
|
2018-01-21 20:55:07 -05:00
|
|
|
]);
|
|
|
|
|
2022-06-14 01:36:21 -04:00
|
|
|
$model_class = Dashboard::getModel($request['model'], [ 'edit', 'list' ]);
|
2018-01-21 20:55:07 -05:00
|
|
|
|
2018-04-18 00:38:11 -04:00
|
|
|
if ($model_class != null) {
|
|
|
|
$item = $model_class::find($request['id']);
|
|
|
|
|
|
|
|
if (is_null($item)) {
|
|
|
|
return 'record-access-fail';
|
|
|
|
}
|
2018-01-21 20:55:07 -05:00
|
|
|
|
2021-07-29 16:40:55 -04:00
|
|
|
return $item->deleteFile($request['name'], true);
|
2018-04-18 00:38:11 -04:00
|
|
|
} else {
|
|
|
|
return 'model-access-fail';
|
|
|
|
}
|
2018-01-21 20:55:07 -05:00
|
|
|
}
|
|
|
|
|
2018-04-25 01:22:33 -04:00
|
|
|
/**
|
|
|
|
* Dashboard settings
|
|
|
|
*/
|
|
|
|
public function getSettings()
|
|
|
|
{
|
|
|
|
return view('dashboard.pages.settings', [
|
|
|
|
'user' => User::find(Auth::id())
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// User Password Update
|
|
|
|
public function postUserPasswordUpdate(Request $request)
|
|
|
|
{
|
2024-03-19 17:11:58 -04:00
|
|
|
$request->validate([
|
2018-04-25 01:22:33 -04:00
|
|
|
'oldpass' => 'required|string|min:6',
|
|
|
|
'newpass' => 'required|string|min:6|confirmed'
|
|
|
|
]);
|
|
|
|
|
|
|
|
if (User::find(Auth::id())->updatePassword($request['oldpass'], $request['newpass'])) {
|
|
|
|
return 'success';
|
|
|
|
} else {
|
|
|
|
return 'old-password-fail';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-25 23:27:45 -04:00
|
|
|
// User Profile Update
|
|
|
|
public function postUserProfileUpdate(Request $request)
|
|
|
|
{
|
2024-03-19 17:11:58 -04:00
|
|
|
$request->validate([
|
2018-04-25 23:27:45 -04:00
|
|
|
'name' => 'required|string|max:255'
|
|
|
|
]);
|
|
|
|
|
|
|
|
$user = User::find(Auth::id());
|
|
|
|
$user->name = $request['name'];
|
|
|
|
$user->website = $request['website'];
|
|
|
|
$user->facebook = $request['facebook'];
|
|
|
|
$user->soundcloud = $request['soundcloud'];
|
|
|
|
$user->instagram = $request['instagram'];
|
|
|
|
$user->twitter = $request['twitter'];
|
|
|
|
$user->save();
|
|
|
|
return 'success';
|
|
|
|
}
|
|
|
|
|
2018-04-25 01:22:33 -04:00
|
|
|
// User Profile Image Upload
|
|
|
|
public function postUserProfileImageUpload(Request $request)
|
|
|
|
{
|
|
|
|
if ($request->hasFile('file')) {
|
|
|
|
$user = User::find(Auth::id());
|
|
|
|
|
|
|
|
if ($user !== null) {
|
2024-03-19 17:11:58 -04:00
|
|
|
$image = Image::read($request->file('file'));
|
2018-04-25 01:22:33 -04:00
|
|
|
$max_width = User::$profile_image_max['width'];
|
|
|
|
$max_height = User::$profile_image_max['height'];
|
|
|
|
|
|
|
|
if ($image->width() > $max_width || $image->height() > $max_height) {
|
|
|
|
$new_width = $max_width;
|
|
|
|
$new_height = ($new_width / $image->width()) * $image->height();
|
|
|
|
|
|
|
|
if ($new_height > $max_height) {
|
|
|
|
$new_height = $max_height;
|
|
|
|
$new_width = ($new_height / $image->height()) * $image->width();
|
|
|
|
}
|
|
|
|
|
2024-03-19 17:11:58 -04:00
|
|
|
$image->scaleDown($new_width, $new_height);
|
2018-04-25 01:22:33 -04:00
|
|
|
}
|
|
|
|
|
2020-02-25 15:40:15 -05:00
|
|
|
File::makeDirectory(base_path() . '/public' . User::$profile_image_dir, 0755, true, true);
|
2018-04-25 01:22:33 -04:00
|
|
|
$image->save($user->profileImage(true, true));
|
|
|
|
$user->touch();
|
|
|
|
return $user->profileImage() . '?version=' . $user->timestamp();
|
|
|
|
} else {
|
|
|
|
return 'record-access-fail';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return 'file-upload-fail';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// User Profile Image Delete
|
|
|
|
public function deleteUserProfileImageDelete(Request $request)
|
|
|
|
{
|
|
|
|
$user = User::find(Auth::id());
|
|
|
|
|
|
|
|
if ($user !== null) {
|
|
|
|
$profile_image = $user->profileImage(true);
|
|
|
|
|
|
|
|
if ($profile_image === null) {
|
|
|
|
return 'image-not-exists-fail';
|
|
|
|
} else if (!unlink($profile_image)) {
|
|
|
|
return 'image-delete-fail';
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'success';
|
|
|
|
} else {
|
|
|
|
return 'record-access-fail';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Credits Page
|
|
|
|
*/
|
|
|
|
public function getCredits()
|
|
|
|
{
|
|
|
|
return view('dashboard.pages.credits');
|
|
|
|
}
|
2016-01-26 23:20:08 -05:00
|
|
|
}
|