From eafb158f20d98b4cd84913d1e738a94021928b78 Mon Sep 17 00:00:00 2001 From: Shawn Rice Date: Tue, 1 Aug 2023 15:53:12 -0400 Subject: [PATCH] fix: Define vars, use correct var --- .../Controllers/Api/AccountsController.php | 2 +- .../Http/Controllers/Api/CartController.php | 6 +- .../Http/Controllers/Api/ItemsController.php | 2 +- .../Controllers/Api/ProductsController.php | 2 +- .../Controllers/Site/OrdersController.php | 3 +- app/Modules/Orders/Models/Item.php | 1 + app/Modules/Publications/Helpers/Download.php | 26 +- .../Publications/Helpers/Formatter.php | 2 +- .../Controllers/Admin/AuthorsController.php | 522 +----------------- 9 files changed, 54 insertions(+), 512 deletions(-) diff --git a/app/Modules/Orders/Http/Controllers/Api/AccountsController.php b/app/Modules/Orders/Http/Controllers/Api/AccountsController.php index 26fae7ff2..ae32ba849 100644 --- a/app/Modules/Orders/Http/Controllers/Api/AccountsController.php +++ b/app/Modules/Orders/Http/Controllers/Api/AccountsController.php @@ -743,7 +743,7 @@ public function update($id, Request $request) $row->amount = $request->input('amount'); // Auto approve for orders less than 1000. Should not effect recurring orders. - if (config('orders.admin_user') && $submitter != config('orders.admin_user')) + if (config('orders.admin_user') && $row->order->submitteruserid != config('orders.admin_user')) { if ($row->amount > 5000 && $row->amount <= 100000) { diff --git a/app/Modules/Orders/Http/Controllers/Api/CartController.php b/app/Modules/Orders/Http/Controllers/Api/CartController.php index 248b9baff..34757bc00 100644 --- a/app/Modules/Orders/Http/Controllers/Api/CartController.php +++ b/app/Modules/Orders/Http/Controllers/Api/CartController.php @@ -3,7 +3,7 @@ namespace App\Modules\Orders\Http\Controllers\Api; use Illuminate\Http\Request; -use Illuminate\Http\Response; +use Illuminate\Http\JsonResponse; use Illuminate\Routing\Controller; use Illuminate\Support\Facades\Validator; use App\Modules\Orders\Models\Product; @@ -69,7 +69,7 @@ public function index(Request $request) * } * } * @param Request $request - * @return Response|CartResource + * @return JsonResponse|CartResource */ public function create(Request $request) { @@ -188,7 +188,7 @@ public function read($id) * } * @param int $id * @param Request $request - * @return Response|CartResource + * @return JsonResponse|CartResource */ public function update($id, Request $request) { diff --git a/app/Modules/Orders/Http/Controllers/Api/ItemsController.php b/app/Modules/Orders/Http/Controllers/Api/ItemsController.php index 231caab0c..e8ed9673c 100644 --- a/app/Modules/Orders/Http/Controllers/Api/ItemsController.php +++ b/app/Modules/Orders/Http/Controllers/Api/ItemsController.php @@ -186,7 +186,7 @@ public function index(Request $request) if ($filters['user']) { - $query->where(function($where) use ($o) + $query->where(function($where) use ($o, $filters) { $where->where($o . '.userid', '=', $filters['user']) ->orWhere($o . '.submitteruserid', '=', $filters['user']); diff --git a/app/Modules/Orders/Http/Controllers/Api/ProductsController.php b/app/Modules/Orders/Http/Controllers/Api/ProductsController.php index 12bd77b61..080d71dd2 100644 --- a/app/Modules/Orders/Http/Controllers/Api/ProductsController.php +++ b/app/Modules/Orders/Http/Controllers/Api/ProductsController.php @@ -370,7 +370,7 @@ public function create(Request $request) } } - $row->datetimecreated = Carbon::now()->toDateTimeString(); + $row->datetimecreated = Carbon::now(); if (!$row->save()) { diff --git a/app/Modules/Orders/Http/Controllers/Site/OrdersController.php b/app/Modules/Orders/Http/Controllers/Site/OrdersController.php index f1b82f35e..c54a32c13 100644 --- a/app/Modules/Orders/Http/Controllers/Site/OrdersController.php +++ b/app/Modules/Orders/Http/Controllers/Site/OrdersController.php @@ -28,7 +28,7 @@ class OrdersController extends Controller /** * Display a listing of the resource. * - * @param Request $request + * @param StatefulRequest $request * @return View|StreamedResponse */ public function index(StatefulRequest $request) @@ -787,6 +787,7 @@ private function getSpreadsheetData($path) $parts = explode('.', $path); $extension = end($parts); $extension = strtolower($extension); + $headers = array(); /*$handle = fopen($path, 'r'); diff --git a/app/Modules/Orders/Models/Item.php b/app/Modules/Orders/Models/Item.php index 2bb9cf094..8351a5d72 100755 --- a/app/Modules/Orders/Models/Item.php +++ b/app/Modules/Orders/Models/Item.php @@ -22,6 +22,7 @@ * @property int $origorderitemid * @property int $prevorderitemid * @property int $quantity + * @property int $price * @property int $origunitprice * @property int $recurringtimeperiodid * @property int $timeperiodcount diff --git a/app/Modules/Publications/Helpers/Download.php b/app/Modules/Publications/Helpers/Download.php index c83a52762..049deabc6 100644 --- a/app/Modules/Publications/Helpers/Download.php +++ b/app/Modules/Publications/Helpers/Download.php @@ -52,10 +52,17 @@ class Download * @param string $format * @return void */ - public function __construct(Publication $reference=null, $format='Bibtex') + public function __construct(Publication $reference = null, $format = 'Bibtex') { - $this->setFormat($format); - $this->setReference($reference); + if ($format) + { + $this->setFormat($format); + } + + if ($reference) + { + $this->setReference($reference); + } } /** @@ -157,7 +164,7 @@ public function getExtension(): string * @param string $format * @return self */ - public function setFormatter(Downloadable $formatter, $format=''): self + public function setFormatter(Downloadable $formatter, $format = ''): self { $format = ($format) ? $format : $this->_format; @@ -172,7 +179,7 @@ public function setFormatter(Downloadable $formatter, $format=''): self * @param string $format Format to get * @return Downloadable|null */ - public function getFormatter($format='') + public function getFormatter($format = '') { $format = ($format) ? $format : $this->_format; @@ -186,14 +193,11 @@ public function getFormatter($format='') * @return string * @throws Exception */ - public function formatReference($reference=null): string + public function formatReference($reference = null): string { - if (!$reference) - { - $reference = $this->getReference(); - } + $reference = $reference ?: $this->getReference(); - if (!$reference || (!is_array($reference) && !is_object($reference))) + if (!$reference) { return ''; } diff --git a/app/Modules/Publications/Helpers/Formatter.php b/app/Modules/Publications/Helpers/Formatter.php index 04439698b..cddb73bb7 100644 --- a/app/Modules/Publications/Helpers/Formatter.php +++ b/app/Modules/Publications/Helpers/Formatter.php @@ -78,7 +78,7 @@ class Formatter /** * Function to set the template keys the formatter will use * - * @param array $template_keys + * @param array $template_keys * @return void */ public static function setTemplateKeys($template_keys): void diff --git a/app/Modules/Publications/Http/Controllers/Admin/AuthorsController.php b/app/Modules/Publications/Http/Controllers/Admin/AuthorsController.php index 85aa55882..7dcdca865 100644 --- a/app/Modules/Publications/Http/Controllers/Admin/AuthorsController.php +++ b/app/Modules/Publications/Http/Controllers/Admin/AuthorsController.php @@ -7,40 +7,31 @@ use Illuminate\Contracts\View\View; use Illuminate\Routing\Controller; use Illuminate\Support\Facades\Validator; -use App\Modules\Publications\Helpers\ItemType; use App\Modules\Publications\Models\Type; -use App\Modules\Publications\Models\Item; -use App\Halcyon\Html\Builder\Select; -use App\Halcyon\Models\Extension; +use App\Modules\Publications\Models\Author; use App\Halcyon\Http\StatefulRequest; use Carbon\Carbon; class AuthorsController extends Controller { /** - * Display a listing of the resource. + * Display a listing of entries. * * @param StatefulRequest $request - * @param string $menutype * @return View */ - public function index(StatefulRequest $request, $menutype = null) + public function index(StatefulRequest $request) { // Get filters $filters = array( - 'menutype' => $menutype, 'search' => null, - 'state' => 'published', - 'access' => null, - 'parent' => 0, - 'level' => 0, - 'language' => '', + 'publication_id' => 0, // Paging 'limit' => config('list_limit', 20), 'page' => 1, // Sorting - 'order' => Item::$orderBy, - 'order_dir' => Item::$orderDir, + 'order' => Author::$orderBy, + 'order_dir' => Author::$orderDir, ); $reset = false; @@ -48,334 +39,41 @@ public function index(StatefulRequest $request, $menutype = null) foreach ($filters as $key => $default) { if ($key != 'page' - && $request->has($key) //&& session()->has('menus.items.filter_' . $key) - && $request->input($key) != session()->get('menus.items.filter_' . $key)) + && $request->has($key) //&& session()->has('publications.authors.filter_' . $key) + && $request->input($key) != session()->get('publications.authors.filter_' . $key)) { $reset = true; } - $filters[$key] = $request->state('menus.items.' . $key, $key, $default); + $filters[$key] = $request->state('publications.authors.' . $key, $key, $default); } $filters['page'] = $reset ? 1 : $filters['page']; - if ($menutype) + if (!in_array($filters['order'], ['id', 'name', 'created_at', 'publication_id'])) { - $filters['menutype'] = $menutype; - } - - if (!in_array($filters['order'], ['id', 'title', 'published', 'access'])) - { - $filters['order'] = Item::$orderBy; + $filters['order'] = Author::$orderBy; } if (!in_array($filters['order_dir'], ['asc', 'desc'])) { - $filters['order_dir'] = Item::$orderDir; - } - - // Get records - $menu = Type::findByMenutype((string)$filters['menutype']); - - if (!$menu) - { - return redirect(route('admin.menus.index')); - } - - $query = Item::query(); - - $a = (new Item)->getTable(); - - // Select all fields from the table. - $query->select([$a . '.id', - $a . '.menutype', - $a . '.title', - $a . '.alias', - $a . '.note', - $a . '.path', - $a . '.link', - $a . '.type', - $a . '.parent_id', - $a . '.level', - $a . '.published AS state', - $a . '.module_id', - $a . '.ordering', - $a . '.checked_out', - $a . '.checked_out_time', - $a . '.target', - $a . '.access', - $a . '.class', - //$a . '.template_style_id', - $a . '.params', - $a . '.lft', - $a . '.rgt', - $a . '.home', - $a . '.language', - $a . '.client_id', - $a . '.deleted_at', - //'l.title AS language_title', - //'l.image AS image', - 'u.name AS editor', - 'c.element AS componentname', - 'ag.title AS access_level', - 'e.name AS name', - \DB::raw('CASE ' . $a . '.type' . - ' WHEN \'module\' THEN ' . $a . '.published+2*(e.enabled-1) ' . - ' WHEN \'url\' THEN ' . $a . '.published+2 ' . - ' WHEN \'alias\' THEN ' . $a . '.published+4 ' . - ' WHEN \'separator\' THEN ' . $a . '.published+6 ' . - ' END AS published')]); - //$query->from($query->getTableName(), 'a'); - - // Join over the language - //$query->leftJoin('languages AS l', 'l.lang_code', $a . '.language', 'left'); - - // Join over the users. - $query->leftJoin('users AS u', 'u.id', $a . '.checked_out'); - - // Join over components - $query->leftJoin('extensions AS c', 'c.id', $a . '.module_id'); - - // Join over the asset groups. - $query->leftJoin('viewlevels AS ag', 'ag.id', $a . '.access'); - - // Join over the associations. - /*$assoc = isset($app->menu_associations) ? $app->menu_associations : 0; - if ($assoc) - { - $query->select('COUNT(asso2.id)>1 AS association'); - $query->leftJoin('associations AS asso', 'asso.id = ' . $a . '.id AND asso.context=\'com_menus.item\''); - $query->leftJoin('associations AS asso2', 'asso2.key', 'asso.key'); - $query->groupBy($a . '.id'); - }*/ - - // Join over the extensions - $query->leftJoin('extensions AS e', 'e.id', $a . '.module_id'); - - // Exclude the root category. - $query->where($a . '.id', '>', 1); - $query->where($a . '.client_id', '=', 0); - - // Filter on the published state. - //$published = $filters['state']; - if ($filters['state'] == 'published') - { - $query->where($a . '.published', '=', 1); - } - elseif ($filters['state'] == 'unpublished') - { - $query->where($a . '.published', '=', 0); - } - elseif ($filters['state'] == 'trashed') - { - $query->onlyTrashed(); - } - /*else - { - $query->withTrashed(); - } - if (is_numeric($published)) - { - $query->withTrashed()->where($a . '.published', '=', (int) $published); - } - elseif ($published === '') - { - $query->withTrashed()->whereIn($a . '.published', array(0, 1)); - } - elseif ($published == '*') - { - $query->withTrashed(); - }*/ - - // Filter by search in title, alias or id - if ($search = trim($filters['search'])) - { - if (stripos($search, 'id:') === 0) - { - $query->where('a.id', '=', (int) substr($search, 3)); - } - elseif (stripos($search, 'link:') === 0) - { - if ($search = substr($search, 5)) - { - $query->where($a . '.link', 'like', '%' . $search . '%'); - } - } - else - { - $query->where(function($where) use ($a, $search) - { - $where->where($a . '.title', 'like', '%' . $search . '%') - ->orWhere($a . '.alias', 'like', '%' . $search . '%') - ->orWhere($a . '.note', 'like', '%' . $search . '%'); - }); - } - } - - // Filter the items over the parent id if set. - $parentId = $filters['parent']; - if (!empty($parentId)) - { - $query->where('p.id', '=', (int)$parentId); - } - - // Filter the items over the menu id if set. - $menuType = $filters['menutype']; - if (!empty($menuType)) - { - $query->where($a . '.menutype', '=', $menuType); - } - - // Filter on the access level. - if ($access = $filters['access']) - { - $query->where($a . '.access', '=', (int) $access); + $filters['order_dir'] = Author::$orderDir; } - // Implement View Level Access - if (!auth()->user()->can('admin')) - { - $query->whereIn($a . '.access', auth()->user()->getAuthorisedViewLevels()); - } - - // Filter on the level. - if ($level = $filters['level']) - { - $query->where($a . '.level', '<=', (int) $level); - } + $query = Author::query(); - // Filter on the language. - if ($language = $filters['language']) + if ($filters['publication_id']) { - $query->where($a . '.language', '=', $language); + $query->where('publication_id', '=', (int)$filters['publication_id']); } - // Get records $rows = $query ->orderBy($filters['order'], $filters['order_dir']) ->paginate($filters['limit'], ['*'], 'page', $filters['page']) ->appends(array_filter($filters)); - $ordering = array(); - - // Preprocess the list of items to find ordering divisions. - foreach ($rows as $item) - { - $ordering[$item->parent_id][] = $item->id; - - // item type text - switch ($item->type) - { - case 'url': - $value = trans('menus::menus.TYPE_EXTERNAL_URL'); - break; - - case 'alias': - $value = trans('menus::menus.TYPE_ALIAS'); - break; - - case 'separator': - $value = trans('menus::menus.TYPE_SEPARATOR'); - break; - - case 'module': - default: - // load language - if (!empty($item->componentname)) - { - $value = trans($item->componentname); - $vars = null; - - parse_str($item->link, $vars); - - if (isset($vars['view'])) - { - // Attempt to load the view xml file. - $file = app_path() . '/Modules/' . $item->componentname . '/Resources/views/site/' . $vars['view'] . '/metadata.xml'; - - if (file_exists($file) && $xml = simplexml_load_file($file)) - { - // Look for the first view node off of the root node. - if ($view = $xml->xpath('view[1]')) - { - if (!empty($view[0]['title'])) - { - $vars['layout'] = isset($vars['layout']) ? $vars['layout'] : 'default'; - - // Attempt to load the layout xml file. - // If Alternative Menu Item, get template folder for layout file - if (strpos($vars['layout'], ':') > 0) - { - // Use template folder for layout file - $temp = explode(':', $vars['layout']); - $file = app_path() . '/Themes/' . $temp[0] . '/html/' . $item->componentname . '/' . $vars['view'] . '/' . $temp[1] . '.xml'; - } - else - { - // Get XML file from component folder for standard layouts - $file = app_path() . '/Modules/' . $item->componentname . '/Resources/views/site/' . $vars['view'] . '/' . $vars['layout'] . '.xml'; - } - - if (file_exists($file) && $xml = simplexml_load_file($file)) - { - // Look for the first view node off of the root node. - if ($layout = $xml->xpath('layout[1]')) - { - if (!empty($layout[0]['title'])) - { - $value .= ' » ' . trans(trim((string) $layout[0]['title'])); - } - } - if (!empty($layout[0]->message[0])) - { - $item->item_type_desc = trans(trim((string) $layout[0]->message[0])); - } - } - } - } - unset($xml); - } - else - { - // Special case for absent views - $value .= ' » ' . trans($item->componentname . '::' . $item->componentname . '.' . $vars['view'] . '.VIEW_DEFAULT_TITLE'); - } - } - } - else - { - if (preg_match("/^index.php\?option=([a-zA-Z\-0-9_]*)/", $item->link, $result)) - { - $value = trans('menus::menus.TYPE_UNEXISTING', ['type' => $result[1]]); - } - else - { - $value = trans('menus::menus.TYPE_UNKNOWN'); - } - } - break; - } - $item->item_type = $value; - } - - // Levels filter. - $options = array(); - $options[] = Select::option('1', 1); - $options[] = Select::option('2', 2); - $options[] = Select::option('3', 3); - $options[] = Select::option('4', 4); - $options[] = Select::option('5', 5); - $options[] = Select::option('6', 6); - $options[] = Select::option('7', 7); - $options[] = Select::option('8', 8); - $options[] = Select::option('9', 9); - $options[] = Select::option('10', 10); - - return view('menus::admin.items.index', [ + return view('publications::admin.authors.index', [ 'rows' => $rows, 'filters' => $filters, - 'menu' => $menu, - 'f_levels' => $options, - 'ordering' => $ordering ]); } @@ -387,44 +85,15 @@ public function index(StatefulRequest $request, $menutype = null) */ public function create(Request $request) { - $row = new Item; - $row->type = 'module'; - $row->menutype = $request->input('menutype'); - - if (!$row->menutype) - { - $row->menutype = $request->session()->get('menus.items.menutype', $row->menutype); - } - - switch ($row->type) - { - case 'separator': - $row->link = ''; - $row->module_id = 0; - break; - - case 'url': - $row->module_id = 0; - break; - - case 'module': - default: - break; - } + $row = new Author; if ($fields = app('request')->old('fields')) { $row->fill($fields); } - $form = $row->getForm(); - - $widgets = \App\Modules\Publications\Models\Widget::forMenuId($row->id ? $row->id : 0); - - return view('menus::admin.items.edit', [ + return view('publications::admin.authors.edit', [ 'row' => $row, - 'form' => $form, - 'widgets' => $widgets, ]); } @@ -436,75 +105,15 @@ public function create(Request $request) */ public function edit($id) { - $row = Item::withTrashed()->findOrFail($id); - - // Fail if checked out not by 'me' - if ($row->isCheckedOut()) - { - return $this->cancel()->with('warning', trans('global.messages.item checked out')); - } + $row = Author::withTrashed()->findOrFail($id); if ($fields = app('request')->old('fields')) { $row->fill($fields); } - switch ($row->type) - { - case 'alias': - $row->module_id = 0; - $args = array(); - - parse_str(parse_url($row->link, PHP_URL_QUERY), $args); - break; - - case 'separator': - $row->link = ''; - $row->module_id = 0; - break; - - case 'url': - $row->module_id = 0; - - //parse_str(parse_url($row->link, PHP_URL_QUERY)); - break; - - case 'module': - default: - // Enforce a valid type. - $row->type = 'module'; - - // Ensure the integrity of the module_id field is maintained, particularly when changing the menu item type. - //$args = array(); - //parse_str(parse_url($row->link, PHP_URL_QUERY), $args); - $args = explode('.', $row->link); - - if (isset($args[1])) - { - // Load the language file for the module. - $module = Extension::findByModule($args[1]); - if ($module) - { - $module->registerLanguage(); - - // Determine the module id. - if ($module->id) - { - $row->module_id = $module->id; - } - } - } - break; - } - - $form = $row->getForm(); - - $widgets = \App\Modules\Publications\Models\Widget::forMenuId($row->id); - - return view('menus::admin.items.edit', [ + return view('publications::admin.authors.edit', [ 'row' => $row, - 'form' => $form, - 'widgets' => $widgets, ]); } @@ -516,12 +125,10 @@ public function edit($id) */ public function store(Request $request) { - //$request->validate([ $rules = [ - 'fields.menutype' => 'required|string|max:24', - 'fields.title' => 'nullable|string|max:255', - 'fields.path' => 'nullable|string|max:1024', - 'fields.link' => 'nullable|string|max:1024', + 'publication_id' => 'required|integer', + 'name' => 'required|string|max:255', + 'user_id' => 'nullable|integer', ]; $validator = Validator::make($request->all(), $rules); @@ -533,28 +140,17 @@ public function store(Request $request) ->withErrors($validator->messages()); } - $id = $request->input('fields.id'); + $id = $request->input('id'); - $row = $id ? Item::findOrFail($id) : new Item(); + $row = $id ? Author::findOrFail($id) : new Author(); $row->fill($request->input('fields')); - if ($request->has('fields.page_id')) - { - $row->page_id = $request->input('fields.page_id'); - } - $row->params; if (!$row->save()) { return redirect()->back()->withError(trans('global.messages.save failed')); } - $root = Item::rootNode(); - $row->rebuild($root->id); - - // Set this to redirects work correctly. - $request->merge(['menutype' => $row->menutype]); - - return $this->cancel($row->menutype)->with('success', trans('global.messages.item ' . ($id ? 'updated' : 'created'))); + return $this->cancel()->with('success', trans('global.messages.item ' . ($id ? 'updated' : 'created'))); } /** @@ -576,7 +172,7 @@ public function delete(Request $request, $id = null) { // Delete the entry // Note: This is recursive and will also remove all descendents - $row = Item::withTrashed()->find($id); + $row = Author::withTrashed()->find($id); if (!$row) { @@ -611,66 +207,6 @@ public function delete(Request $request, $id = null) return $this->cancel(); } - /** - * Sets the state of one or more entries - * - * @param Request $request - * @param int $id - * @return void - */ - public function state(Request $request, $id) - { - $action = app('request')->segment(count($request->segments()) - 1); - $state = $action == 'publish' ? 1 : 0; - - // Incoming - $ids = $request->input('id', array($id)); - $ids = (!is_array($ids) ? array($ids) : $ids); - - // Check for an ID - if (count($ids) < 1) - { - $request->session()->flash('warning', trans($state ? 'menus::menus.select to publish' : 'menus::menus.select to unpublish')); - return $this->cancel(); - } - - $success = 0; - - // Update record(s) - foreach ($ids as $id) - { - $row = Item::findOrFail(intval($id)); - $row->timestamps = false; - - if ($row->published == $state) - { - continue; - } - - $row->published = $state; - - if (!$row->save()) - { - $request->session()->flash('error', trans('global.messages.save failed')); - continue; - } - - $success++; - } - - // Set message - if ($success) - { - $msg = $state - ? 'menus::menus.items published' - : 'menus::menus.items unpublished'; - - $request->session()->flash('success', trans($msg, ['count' => $success])); - } - - return $this->cancel(); - } - /** * Sets the state of one or more entries * @@ -695,7 +231,7 @@ public function restore(Request $request) // Update record(s) foreach ($ids as $id) { - $row = Item::withTrashed()->findOrFail(intval($id)); + $row = Author::withTrashed()->findOrFail(intval($id)); if (!$row->restore()) { @@ -725,7 +261,7 @@ public function restore(Request $request) public function reorder($id, Request $request) { // Get the element being moved - $row = Item::findOrFail($id); + $row = Author::findOrFail($id); $move = ($request->segment(4) == 'orderup') ? -1 : +1; if (!$row->move($move))