'; -// echo 'last:'.$key; -// print_r($array); -// echo ''; - } - } - /** * Gracefully handle decrypting the legacy data (encrypted via mcrypt) and use the new @@ -646,7 +660,8 @@ class Helper * @param String $string * @return string */ - public static function gracefulDecrypt(CustomField $field, $string) { + public static function gracefulDecrypt(CustomField $field, $string) + { if ($field->isFieldDecryptable($string)) { @@ -663,26 +678,52 @@ class Helper } - /** - * Strip HTML out of returned JSON. This is pretty gross, and I'd like to find a better way - * to handle this, but the REST API will solve some of these problems anyway. - * - * This is not currently used, but will be. - * - * @author A. Gianotto - * @since 3.4 - * @param $array array - * @return Array - */ - public static function stripTagsFromJSON(Array $array) { - foreach ($array as $key => $value) { - $clean_value = strip_tags($value); - $clean_array[$key] = $clean_value; + + public static function formatStandardApiResponse($status, $payload = null, $messages = null) { + + $array['status'] = $status; + $array['messages'] = $messages; + if (($messages) && (count($messages) > 0)) { + $array['messages'] = $messages; } - return $clean_array; + ($payload) ? $array['payload'] = $payload : $array['payload'] = null; + return $array; + } + + + /* + Possible solution for unicode fieldnames + */ + public static function make_slug($string) { + return preg_replace('/\s+/u', '_', trim($string)); + } + + + public static function getFormattedDateObject($date, $type = 'datetime', $array = true) { + + if ($date=='') { + return null; + } + + $settings = Setting::getSettings(); + $tmp_date = new \Carbon($date); + + if ($type == 'datetime') { + $dt['datetime'] = $tmp_date->format('Y-m-d H:i:s'); + $dt['formatted'] = $tmp_date->format($settings->date_display_format .' '. $settings->time_display_format); + } else { + $dt['date'] = $tmp_date->format('Y-m-d'); + $dt['formatted'] = $tmp_date->format($settings->date_display_format); + } + + if ($array == 'true') { + return $dt; + } + return $dt['formatted']; } + } diff --git a/app/Http/Controllers/AccessoriesController.php b/app/Http/Controllers/AccessoriesController.php index 6bf5c8f62c..6658997cf7 100755 --- a/app/Http/Controllers/AccessoriesController.php +++ b/app/Http/Controllers/AccessoriesController.php @@ -3,9 +3,7 @@ namespace App\Http\Controllers; use App\Helpers\Helper; use App\Models\Accessory; -use App\Models\Actionlog; use App\Models\Company; -use App\Models\Setting; use App\Models\User; use Auth; use Carbon\Carbon; @@ -16,7 +14,7 @@ use Input; use Lang; use Mail; use Redirect; -use Request; +use Illuminate\Http\Request; use Slack; use Str; use View; @@ -38,9 +36,10 @@ class AccessoriesController extends Controller * @since [v1.0] * @return View */ - public function getIndex(Request $request) + public function index(Request $request) { - return View::make('accessories/index'); + $this->authorize('index', Accessory::class); + return view('accessories/index'); } @@ -50,10 +49,11 @@ class AccessoriesController extends Controller * @author [A. Gianotto] [