public function __construct() { //$this->beforeFilter(function(){ }); $this->uriSegment = null; $this->modelName = null; $this->viewsPath = null; $this->resourceId = null; if (Route::input('alias') !== null) { $this->uriSegment = Route::input('alias'); $this->viewsPath = File::exists(app_path('views/' . Config::get('reactiveadmin::uri') . '/' . $this->uriSegment)) ? Config::get('reactiveadmin::uri') . '.' . $this->uriSegment : 'reactiveadmin::default'; $this->modelName = studly_case(str_singular(Route::input('alias'))); $this->modelWrapper = App::make('model_wrapper'); $this->modelWrapper->model($this->modelName); if (Route::input('id') !== null) { $this->resourceId = Route::input('id'); } View::share('config', $this->modelWrapper->getConfig()); // TODO: refactor this! // custom behavior switch ($this->uriSegment) { case 'settings': View::composer(array('admin.' . $this->viewsPath . '.index'), function ($view) { $view->with('settings', Settings::all()); }); break; default: # code... break; } } View::share('view', $this->uriSegment); View::share('model', $this->modelName); }
/** * Returns the initial HTML view for the admin interface. * * @param \Illuminate\Http\Request $request Laravel request object * @return \Illuminate\Contracts\View\View View for rendering the output */ public function indexAction(Request $request) { if (config('shop.authorize', true)) { $this->authorize('admin'); } $site = Route::input('site', 'default'); $lang = Input::get('lang', config('app.locale', 'en')); $aimeos = app('\\Aimeos\\Shop\\Base\\Aimeos')->get(); $cntlPaths = $aimeos->getCustomPaths('controller/extjs'); $context = app('\\Aimeos\\Shop\\Base\\Context')->get(false); $context = $this->setLocale($context, $site, $lang); $controller = new \Aimeos\Controller\ExtJS\JsonRpc($context, $cntlPaths); $cssFiles = array(); foreach ($aimeos->getCustomPaths('admin/extjs') as $base => $paths) { foreach ($paths as $path) { $jsbAbsPath = $base . '/' . $path; if (!is_file($jsbAbsPath)) { throw new \Exception(sprintf('JSB2 file "%1$s" not found', $jsbAbsPath)); } $jsb2 = new \Aimeos\MW\Jsb2\Standard($jsbAbsPath, dirname($path)); $cssFiles = array_merge($cssFiles, $jsb2->getUrls('css')); } } $jqadmUrl = route('aimeos_shop_jqadm_search', array('site' => $site, 'resource' => 'product')); $jsonUrl = route('aimeos_shop_extadm_json', array('site' => $site, '_token' => csrf_token())); $adminUrl = route('aimeos_shop_extadm', array('site' => '<site>', 'lang' => '<lang>', 'tab' => '<tab>')); $vars = array('lang' => $lang, 'cssFiles' => $cssFiles, 'languages' => $this->getJsonLanguages($context), 'config' => $this->getJsonClientConfig($context), 'site' => $this->getJsonSiteItem($context, $site), 'i18nContent' => $this->getJsonClientI18n($aimeos->getI18nPaths(), $lang), 'searchSchemas' => $controller->getJsonSearchSchemas(), 'itemSchemas' => $controller->getJsonItemSchemas(), 'smd' => $controller->getJsonSmd($jsonUrl), 'urlTemplate' => str_replace(['<', '>'], ['{', '}'], urldecode($adminUrl)), 'uploaddir' => config('shop::uploaddir'), 'activeTab' => Input::get('tab', 0), 'version' => $this->getVersion(), 'jqadmurl' => $jqadmUrl); return View::make('shop::admin.extadm-index', $vars); }
/** * Returns the initial HTML view for the admin interface. * * @param \Illuminate\Http\Request $request Laravel request object * @return \Illuminate\Contracts\View\View View for rendering the output */ public function indexAction(Request $request) { if (config('shop.authorize', true) && (Auth::check() === false || $request->user()->can('admin', ['admin', 'editor'])) === false) { return View::make('shop::admin.index'); } $param = array('resource' => 'dashboard', 'site' => Route::input('site', Input::get('site', 'default')), 'lang' => Route::input('lang', Input::get('lang', config('app.locale', 'en')))); return redirect()->route('aimeos_shop_jqadm_search', $param); }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @param String $model * @return mixed */ public function handle($request, Closure $next, $model) { if ($model == 'Mission') { Mission::whereSlug(Route::input('slug'))->firstOrFail(); } elseif ($model == 'Object') { Object::findOrFail(Route::input('object_id')); } elseif ($model == 'Tag') { Tag::where('name', Route::input('slug'))->firstOrFail(); } return $next($request); }
/** * Returns the locale item for the current request * * @param \Aimeos\MShop\Context\Item\Iface $context Context object * @return \Aimeos\MShop\Locale\Item\Iface Locale item object */ public function get(\Aimeos\MShop\Context\Item\Iface $context) { if ($this->locale === null) { $site = Route::input('site', Input::get('site', 'default')); $currency = Route::input('currency', Input::get('currency', '')); $lang = Route::input('locale', Input::get('locale', '')); $disableSites = $this->config->get('shop.disableSites', true); $localeManager = \Aimeos\MShop\Locale\Manager\Factory::createManager($context); $this->locale = $localeManager->bootstrap($site, $lang, $currency, $disableSites); } return $this->locale; }
/** * Returns the routing parameters passed in the URL * * @return array Associative list of parameters with "site", "locale" and "currency" if available */ protected function getFixedParams() { $fixed = array(); if (($value = Route::input('site')) !== null) { $fixed['site'] = $value; } if (($value = Route::input('locale')) !== null) { $fixed['locale'] = $value; } if (($value = Route::input('currency')) !== null) { $fixed['currency'] = $value; } return $fixed; }
/** * Single entry point for all JSON admin requests. * * @param \Illuminate\Http\Request $request Laravel request object * @return \Illuminate\Contracts\View\View View for rendering the output */ public function doAction(Request $request) { if (config('shop.authorize', true)) { $this->authorize('admin', [['admin']]); } $site = Route::input('site', Input::get('site', 'default')); $aimeos = app('\\Aimeos\\Shop\\Base\\Aimeos')->get(); $cntlPaths = $aimeos->getCustomPaths('controller/extjs'); $context = app('\\Aimeos\\Shop\\Base\\Context')->get(false, 'backend'); $context->setView(app('\\Aimeos\\Shop\\Base\\View')->create($context, array())); $context->setLocale(app('\\Aimeos\\Shop\\Base\\Locale')->getBackend($context, $site)); $controller = new \Aimeos\Controller\ExtJS\JsonRpc($context, $cntlPaths); $response = $controller->process(Input::instance()->request->all(), $request->getContent()); return View::make('shop::extadm.do', array('output' => $response)); }
/** * Checks if the user with the given ID is in the specified group * * @param string $userid Unique user ID * @param string|array $groupcodes Unique user/customer group codes that are allowed * @return boolean True if user is part of the group, false if not */ public function checkGroup($userid, $groupcodes) { $site = Route::current() ? Route::input('site', Input::get('site', 'default')) : 'default'; $context = $this->context->get(false); $context->setLocale($this->locale->getBackend($context, $site)); $manager = \Aimeos\MShop\Factory::createManager($context, 'customer/group'); $search = $manager->createSearch(); $search->setConditions($search->compare('==', 'customer.group.code', (array) $groupcodes)); $groupItems = $manager->searchItems($search); $manager = \Aimeos\MShop\Factory::createManager($context, 'customer/lists'); $search = $manager->createSearch(); $expr = array($search->compare('==', 'customer.lists.parentid', $userid), $search->compare('==', 'customer.lists.refid', array_keys($groupItems)), $search->compare('==', 'customer.lists.domain', 'customer/group')); $search->setConditions($search->combine('&&', $expr)); $search->setSlice(0, 1); return (bool) count($manager->searchItems($search)); }
/** * Register user * * @param $identify * @param $username * @param $client * @param $dni * @param $name * @param $lastname * @param $email * @return mixed|string */ public static function userRegister($identify, $username, $client, $dni, $name, $lastname, $email) { $access_token = Route::input('fantasy_token') ? Route::input('fantasy_token') : Session::get('fantasy_token'); if (is_null($access_token)) { $token = self::getAccessToken(); $access_token = $token->FantasyApi->data->access_token; } try { $url = Config::get('fantasy.fantasy_url'); $request = ['access_token' => $access_token, 'action' => 'USER', 'method' => 'REGISTER', 'identify' => $identify, 'username' => $username, 'client' => $client, 'dni' => $dni, 'name' => $name, 'lastname' => $lastname, 'email' => $email]; $curl = cURL::post($url, $request); $response = json_decode($curl); } catch (\Exception $ex) { \Log::error('FantasyWrapper.userRegister.catch', ['exception' => $ex, 'identify' => $identify, 'username' => $username, 'client' => $client, 'dni' => $dni, 'name' => $name, 'lastname' => $lastname, 'email' => $email, 'access_token' => $access_token]); $response = $ex->getMessage(); } return $response; }
/** * Returns the locale item for the current request * * @param \Aimeos\MShop\Context\Item\Iface $context Context object * @return \Aimeos\MShop\Locale\Item\Iface Locale item object */ protected function getLocale(\Aimeos\MShop\Context\Item\Iface $context) { if ($this->locale === null) { if (Route::current() !== null) { $site = Route::input('site', 'default'); $lang = Route::input('locale', ''); $currency = Route::input('currency', ''); } else { $site = 'default'; $lang = $currency = ''; } $disableSites = $this->config->has('shop.disableSites'); $localeManager = \Aimeos\MShop\Locale\Manager\Factory::createManager($context); $this->locale = $localeManager->bootstrap($site, $lang, $currency, $disableSites); } return $this->locale; }
/** * Returns the resource controller * * @return \Aimeos\MShop\Context\Item\Iface Context item */ protected function createClient() { $site = Route::input('site', Input::get('site', 'default')); $lang = Input::get('lang', config('app.locale', 'en')); $resource = Route::input('resource'); $aimeos = app('\\Aimeos\\Shop\\Base\\Aimeos')->get(); $templatePaths = $aimeos->getCustomPaths('admin/jqadm/templates'); $context = app('\\Aimeos\\Shop\\Base\\Context')->get(false); $context = $this->setLocale($context, $site, $lang); $view = app('\\Aimeos\\Shop\\Base\\View')->create($context->getConfig(), $templatePaths, $lang); $context->setView($view); return \Aimeos\Admin\JQAdm\Factory::createClient($context, $templatePaths, $resource); }
/** * Returns the JsonAdm client * * @return \Aimeos\Admin\JsonAdm\Iface JsonAdm client */ protected function createClient() { $site = Route::input('site', Input::get('site', 'default')); $lang = Input::get('lang', config('app.locale', 'en')); $resource = Route::input('resource'); $aimeos = app('\\Aimeos\\Shop\\Base\\Aimeos')->get(); $templatePaths = $aimeos->getCustomPaths('admin/jsonadm/templates'); $context = app('\\Aimeos\\Shop\\Base\\Context')->get(false, 'backend'); $context->setI18n(app('\\Aimeos\\Shop\\Base\\I18n')->get(array($lang, 'en'))); $context->setLocale(app('\\Aimeos\\Shop\\Base\\Locale')->getBackend($context, $site)); $context->setView(app('\\Aimeos\\Shop\\Base\\View')->create($context, $templatePaths, $lang)); return \Aimeos\Admin\JsonAdm\Factory::createClient($context, $templatePaths, $resource); }
/** * Determine if the user is authorized to make this request. * * @return bool */ public function authorize() { $plant = Plant::findOrFail(Route::input('id')); // authorize when the user is the owner of the plant return Auth::user()->id == $plant->users()->wherePivot('isOwner', true)->first()->id; }
/** * Adds the "url" helper to the view object * * @param \Aimeos\MW\View\Iface $view View object * @return \Aimeos\MW\View\Iface Modified view object */ protected function addUrl(\Aimeos\MW\View\Iface $view) { $fixed = array(); if (Route::current()) { if (($value = Route::input('site')) !== null) { $fixed['site'] = $value; } if (($value = Route::input('locale')) !== null) { $fixed['locale'] = $value; } if (($value = Route::input('currency')) !== null) { $fixed['currency'] = $value; } } $helper = new \Aimeos\MW\View\Helper\Url\Laravel5($view, app('url'), $fixed); $view->addHelper('url', $helper); return $view; }
/** * Returns the generated HTML code * * @param string $content Content from admin client * @return \Illuminate\Contracts\View\View View for rendering the output */ protected function getHtml($content) { $version = app('\\Aimeos\\Shop\\Base\\Aimeos')->getVersion(); $site = Route::input('site', Input::get('site', 'default')); $content = str_replace(['{type}', '{version}'], ['Laravel', $version], $content); return View::make('shop::jqadm.index', array('content' => $content, 'site' => $site)); }