Beispiel #1
0
 /**
  *
  */
 function __construct()
 {
     parent::__construct('control-column', '');
     $admin = Admin::instance();
     $this->router = $admin->router;
     $this->formBuilder = $admin->formBuilder;
 }
Beispiel #2
0
 function __construct()
 {
     $this->formBuilder = Admin::instance()->formBuilder;
     $this->items = [];
     $this->inlineItems = [];
     $this->groups = [];
 }
Beispiel #3
0
 /**
  *
  */
 function __construct($name, $label = null)
 {
     parent::__construct($name, $label);
     $this->sortable = false;
     $admin = Admin::instance();
     $this->router = $admin->router;
     $this->formBuilder = $admin->formBuilder;
 }
Beispiel #4
0
 public function delete($group)
 {
     $group->delete();
     $all_groups = \App\Group::all();
     $title = 'Groups';
     $html = view('admin.groups.table', compact('title', 'all_groups'))->render();
     return Admin::view($html);
 }
Beispiel #5
0
 /**
  * @param null $name
  * @param null $label
  */
 function __construct($name = null, $label = null)
 {
     $this->formBuilder = Admin::instance()->formBuilder;
     $this->label = $label;
     $this->name = $name;
     if ($modelItem = ModelItem::$current) {
         $this->form = $modelItem->getForm();
     }
 }
Beispiel #6
0
 /** @test */
 public function it_generates_url_to_item()
 {
     $menu = new MenuItem();
     $menu->url('/');
     $this->assertEquals('route-wildcard', $menu->getUrl());
     Admin::model('\\MenuItemTestModel');
     $menu = new MenuItem('\\MenuItemTestModel');
     $this->assertEquals('route-to-model', $menu->getUrl());
 }
Beispiel #7
0
 public function render()
 {
     AssetManager::addScript(Admin::instance()->router->routeToAsset('ckeditor/ckeditor.js'));
     if (!isset($this->attributes['class'])) {
         $this->attributes['class'] = '';
     }
     $this->attributes['class'] .= ' ckeditor';
     return parent::render();
 }
Beispiel #8
0
 /**
  * @param $assets
  * @return array
  */
 protected static function assets($assets)
 {
     return array_map(function ($asset) {
         if (strpos($asset, 'admin::') !== false) {
             $asset = str_replace('admin::', '', $asset);
             return Admin::instance()->router->routeToAsset($asset);
         }
         return $asset;
     }, array_unique($assets));
 }
Beispiel #9
0
 function __construct($name, $label = null)
 {
     $this->name = $name;
     if (is_null($label)) {
         $this->label = ucwords(str_replace('_', ' ', $name));
     } else {
         $this->label = $label;
     }
     $this->sortable(false);
     $this->htmlBuilder = Admin::instance()->htmlBuilder;
 }
 protected function registerPatterns()
 {
     Route::pattern('adminModelId', '[0-9]+');
     Route::pattern('adminModel', implode('|', Admin::modelAliases()));
     Route::bind('adminModel', function ($model) {
         $class = array_search($model, Admin::modelAliases());
         if ($class === false) {
             throw new ModelNotFoundException();
         }
         return Admin::model($class);
     });
     Route::pattern('adminWildcard', '.*');
 }
 /**
  *
  */
 public function boot()
 {
     $this->loadViewsFrom(__DIR__ . '/../../views', 'admin');
     $this->loadTranslationsFrom(__DIR__ . '/../../lang', 'admin');
     $this->mergeConfigFrom(__DIR__ . '/../../config/config.php', 'admin');
     $this->publishes([__DIR__ . '/../../config/config.php' => config_path('admin.php')], 'config');
     $this->publishes([__DIR__ . '/../../migrations/' => base_path('/database/migrations')], 'migrations');
     $this->publishes([__DIR__ . '/../../../public/' => public_path('packages/sleeping-owl/admin/')], 'assets');
     app('SleepingOwl\\Admin\\Helpers\\StartSession')->run();
     Admin::instance()->router->registerRoutes();
     $this->registerValidator();
     $this->registerFilters();
 }
Beispiel #12
0
 /**
  * @param $assets
  * @return array
  */
 protected static function assets($assets)
 {
     return array_map(function ($asset) {
         if (strpos($asset, 'admin::') !== false) {
             $asset = str_replace('admin::', '', $asset);
             $pathToAsset = public_path() . DIRECTORY_SEPARATOR . 'packages' . DIRECTORY_SEPARATOR . 'sleeping-owl' . DIRECTORY_SEPARATOR . 'admin' . DIRECTORY_SEPARATOR . $asset;
             if (file_exists($pathToAsset)) {
                 $asset .= '?ver=' . filemtime($pathToAsset);
             }
             return Admin::instance()->router->routeToAsset($asset);
         }
         return $asset;
     }, array_unique($assets));
 }
Beispiel #13
0
 /**
  * @param $instance
  * @param int $totalCount
  * @return string
  * @throws \SleepingOwl\Admin\Exceptions\ModelNotFoundException
  */
 public function render($instance, $totalCount)
 {
     $filterValue = $this->valueFromInstance($instance, $this->value);
     $modelItem = Admin::instance()->models->modelWithClassname($this->model);
     $url = $this->router->routeToModel($modelItem->getAlias(), [$this->name => $filterValue]);
     if ($this->model === $this->modelItem->getModelClass()) {
         $class = 'fa-filter';
         $title = Lang::get('admin::lang.table.filter');
     } else {
         $class = 'fa-arrow-circle-o-right';
         $title = Lang::get('admin::lang.table.filter-goto');
     }
     $content = $this->htmlBuilder->tag('i', ['class' => ['fa', $class], 'data-toggle' => 'tooltip', 'title' => $title]);
     return $this->htmlBuilder->tag('a', ['href' => $url], $content);
 }
Beispiel #14
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if (Sentinel::guest()) {
         return redirect('login');
     }
     if (Sentinel::inRole('admin')) {
         return $next($request);
     }
     $arrSlugs = str_getcsv($request->path(), '/');
     $method = Request::method();
     $user = Sentinel::check();
     if ($method == 'DELETE') {
         $permit = $arrSlugs[0] . '.' . $arrSlugs[1] . '.delete';
         if ($user->hasAccess([$permit])) {
             return $next($request);
         }
         if ($user->hasAccess(['admin'])) {
             $content = 'Для удаления объекта необходимы установленные права <b>' . $permit . '</b> Для получения прав обратитесь к администратору';
             return Admin::view($content, 'Dashboard');
         }
         //            return Redirect::back();
         return Redirect::intended('/');
     }
     $permit = $arrSlugs[0];
     if (isset($arrSlugs[1])) {
         $permit = $permit . '.' . $arrSlugs[1];
     }
     if (isset($arrSlugs[2]) && $arrSlugs[2] == "create") {
         $permit = $permit . '.' . $arrSlugs[2];
     }
     if (isset($arrSlugs[3])) {
         $permit = $permit . '.' . $arrSlugs[3];
     }
     if ($user->hasAccess([$permit])) {
         return $next($request);
     }
     if ($user->hasAccess(['admin'])) {
         $content = 'Для удаления объекта необходимы установленные права <b>' . $permit . '</b> Для получения прав обратитесь к администратору';
         return Admin::view($content, 'Dashboard');
     }
     //        return Redirect::back();
     return Redirect::intended('/');
 }
 public function getSendProducts()
 {
     $users = User::all();
     $count_users = count($users);
     $count_success = 0;
     $max_products_per_user = config('main.max_products_per_user', 3);
     foreach ($users as $key => $user) {
         $active_products = $user->list_active_products;
         $count_active_products = count($active_products);
         if ($count_active_products >= 0 && $count_active_products < $max_products_per_user) {
             $random_product = Product::orderByRaw("RAND()")->first();
             try {
                 $user_product = UserProduct::create(['user_id' => $user->id, 'product_id' => $random_product->id]);
                 $count_success++;
             } catch (QueryException $e) {
                 //Nothing
             }
         }
     }
     $result_str = "Раздача товаров...<br>Всего юзеров: " . $count_users . ". Успешно раздали: " . $count_success;
     return Admin::view($result_str, 'Раздача товаров');
 }
Beispiel #16
0
 /**
  * Register all admin routes
  */
 public function registerRoutes()
 {
     $this->registerAssetsRoutes();
     $this->registerAuthRoutes();
     $this->registerImageCacheRoute();
     $models = Admin::instance()->models->getAllAliases();
     $this->laravelRouter->group(['prefix' => $this->prefix, 'before' => $this->getBeforeFilters(), 'namespace' => 'SleepingOwl\\Admin\\Controllers'], function () use($models) {
         if (empty($models)) {
             $models = ['__empty_models__'];
         }
         $this->laravelRouter->group(['where' => ['model' => implode('|', $models)]], function () {
             foreach (static::$modelRoutes as $route) {
                 $url = $route['url'];
                 $action = $route['action'];
                 $method = $route['method'];
                 $controller = isset($route['controller']) ? $route['controller'] : 'AdminController';
                 $this->laravelRouter->{$method}($url, ['as' => $this->routePrefix . '.table.' . $action, 'uses' => $controller . '@' . $action]);
             }
         });
         $wildcardRoute = $this->laravelRouter->any('{wildcard?}', ['as' => $this->routePrefix . '.wildcard', 'uses' => 'AdminController@getWildcard'])->where('wildcard', '.*');
         $this->setRoutePriority($wildcardRoute, 0);
     });
 }
Beispiel #17
0
 public function delete($user)
 {
     $user->delete();
     $all_users = \App\User::all();
     $title = 'Users';
     $html = view('admin.users.table', compact('title', 'all_users'))->render();
     return Admin::view($html);
 }
Beispiel #18
0
 public static function textarea($name, $label, $value = null, array $options = [])
 {
     $options['id'] = uniqid();
     if (!empty($options['data-editor'])) {
         switch ($options['data-editor']) {
             case FormItem\Textarea::EDITOR_WYSIHTML:
                 AssetManager::addStyle(Admin::instance()->router->routeToAsset('css/bootstrap-wysihtml5.css'));
                 AssetManager::addScript(Admin::instance()->router->routeToAsset('js/wysihtml5-0.3.0.js'));
                 AssetManager::addScript(Admin::instance()->router->routeToAsset('js/bootstrap-wysihtml5.js'));
                 break;
         }
     }
     AssetManager::addScript(Admin::instance()->router->routeToAsset('js/parsley.min.js'));
     AssetManager::addScript(Admin::instance()->router->routeToAsset('js/parsley-init.js'));
     return view('admin::_partials/form_elements/textarea')->with('name', $name)->with('label', $label)->with('value', $value)->with('options', $options)->with('id', $options['id'])->with('error', self::getError($name));
 }
Beispiel #19
0
<?php

/**
 * Created by PhpStorm.
 * User: hlogeon
 * Date: 6/18/15
 * Time: 5:39 AM
 */
use SleepingOwl\Admin\Admin;
use SleepingOwl\Admin\Columns\Column;
use SleepingOwl\Admin\Models\Form\FormItem;
Admin::model('\\Hlogeon\\Scms\\Models\\Type')->title('Типы')->as('page-type')->with('typeLayout', 'listLayout')->columns(function () {
    // Describing columns for table view
    Column::string('id', 'ID');
    Column::string('name', 'Название');
    Column::string('alias', 'Алиас');
    //    Column::string('alias', 'Алиас');
})->form(function () {
    // Describing elements in create and editing forms
    FormItem::text('name', 'Название');
    FormItem::text('alias', 'Алиас');
    FormItem::checkbox('enable_in_menu', 'Разрешить добавлять в меню?');
    FormItem::checkbox('enable_own_layout', 'Разрешить собственный лэйаут для каждой страницы?');
    FormItem::checkbox('enable_own_sidebar', 'Разрешить собственный сайдбар для каждой страницы?');
    FormItem::select('type_layout_id', 'Лэйаут страницы')->list('\\Hlogeon\\Scms\\Models\\Layout');
    FormItem::select('list_layout_id', 'Лэйаут списка')->list('\\Hlogeon\\Scms\\Models\\Layout');
    FormItem::select('sidebar', 'Сайдбар списка')->list('\\Hlogeon\\Scms\\Models\\Sidebar');
    FormItem::select('item_sidebar', 'Сайдбар элемента')->list('\\Hlogeon\\Scms\\Models\\Sidebar');
    FormItem::checkbox('type_in_menu', 'Отображать тип в меню?');
});
Beispiel #20
0
<?php

/*
 * Describe your menu here.
 *
 * There is some simple examples what you can use:
 *
 * 		Admin::menu()->url('/')->label('Start page')->icon('fa-dashboard')->uses('\AdminController@getIndex');
 * 		Admin::menu(User::class)->icon('fa-user');
 * 		Admin::menu()->label('Menu with subitems')->icon('fa-book')->items(function ()
 * 		{
 * 			Admin::menu(\Foo\Bar::class)->icon('fa-sitemap');
 * 			Admin::menu('\Foo\Baz')->label('Overwrite model title');
 * 			Admin::menu()->url('my-page')->label('My custom page')->uses('\MyController@getMyPage');
 * 		});
 */
use SleepingOwl\Admin\Admin;
Admin::menu('\\App\\User')->icon('fa-user');
Admin::menu()->label('Menu with subitems')->icon('fa-book')->items(function () {
    Admin::menu('\\Hlogeon\\Scms\\Models\\Page')->icon('fa-file');
    Admin::menu('\\Hlogeon\\Scms\\Models\\Category')->icon('fa-list-alt');
    Admin::menu('\\Hlogeon\\Scms\\Models\\Type')->icon('fa-bars');
    Admin::menu('\\Hlogeon\\Scms\\Models\\Layout')->icon('fa-cogs');
    Admin::menu('\\Hlogeon\\Scms\\Models\\MenuItem')->icon('fa-th-large');
    Admin::menu('\\Hlogeon\\Scms\\Models\\Sidebar')->icon('fa-code');
    Admin::menu('\\Hlogeon\\Scms\\Models\\Footer')->icon('fa-asterisk');
});
Beispiel #21
0
<?php

/**
 * Created by PhpStorm.
 * User: hlogeon
 * Date: 6/18/15
 * Time: 1:20 PM
 */
use SleepingOwl\Admin\Admin;
use SleepingOwl\Admin\Columns\Column;
use SleepingOwl\Admin\Models\Form\FormItem;
Admin::model('\\App\\User')->title('Пользователи')->as('user')->columns(function () {
    // Describing columns for table view
    Column::string('id', 'ID');
    Column::string('name', 'Имя');
    Column::string('email', 'email');
    //    Column::string('alias', 'Алиас');
})->form(function () {
    // Describing elements in create and editing forms
    FormItem::text('name', 'Имя');
    FormItem::text('email', 'Email');
    FormItem::text('company_info', 'Компания и должность');
    FormItem::password('password', 'Пароль');
    FormItem::image('profile_image', 'Аватар');
    FormItem::ckeditor('info', 'Информация');
});
Beispiel #22
0
 /**
  * @param string $wildcard
  * @return View
  * @throws \Exception
  */
 public function getWildcard($wildcard = '/')
 {
     $title = null;
     $content = '';
     if ($menuItem = Admin::instance()->menu->itemWithUrl($wildcard)) {
         if ($action = $menuItem->getUses()) {
             list($controller, $action) = explode('@', $action);
             $content = app($controller)->{$action}();
             if ($content instanceof Response) {
                 return $content;
             }
             $title = $wildcard !== '/' ? $menuItem->getLabel() : null;
         } else {
             throw new \Exception('You need to provide valid action for this route.');
         }
     } elseif ($wildcard !== '/') {
         App::abort(404);
     }
     return $this->makeView('page', compact('title', 'content'));
 }
Beispiel #23
0
 /**
  * @return string
  */
 public function renderTableAttributes()
 {
     $attributes = [];
     if (!$this->orderable) {
         $attributes['data-ordering'] = 'false';
     }
     $attributes['data-statesave'] = $this->stateSave();
     if ($this->isAsync()) {
         $url = Admin::instance()->router->routeToTable($this->getAlias(), \Input::all());
         $attributes['data-ajax'] = $url;
     }
     return $this->htmlBuilder->attributes($attributes);
 }
Beispiel #24
0
 /**
  * @return \SleepingOwl\Admin\Models\ModelItem
  * @throws \SleepingOwl\Admin\Exceptions\ModelNotFoundException
  */
 protected function getModelItem()
 {
     return Admin::instance()->models->modelWithClassname($this->modelClass);
 }
Beispiel #25
0
 /** @test */
 public function it_creates_menu_item()
 {
     $menu = Admin::menu('\\Foo\\Bar\\Model');
     $this->assertInstanceOf('\\SleepingOwl\\Admin\\Menu\\MenuItem', $menu);
 }
Beispiel #26
0
 /**
  * Get related model configuration
  * @return ModelConfiguration
  */
 protected function getModelItem()
 {
     return Admin::model($this->modelClass);
 }
Beispiel #27
0
 /**
  * Get filter url
  * @return string
  */
 public function getUrl()
 {
     $value = $this->getValue($this->instance, $this->field());
     return Admin::model($this->model)->displayUrl([$this->name() => $value]);
 }
Beispiel #28
0
 public function render()
 {
     $params = ['items' => $this->repository()->tree(), 'reorderable' => $this->reorderable(), 'url' => Admin::model($this->class)->displayUrl(), 'value' => $this->value(), 'creatable' => !is_null($this->model()->create()), 'createUrl' => $this->model()->createUrl($this->parameters() + Request::all()), 'controls' => [Column::treeControl()]];
     return view(AdminTemplate::view('display.tree'), $params);
 }
 /**
  * Get related form model configuration
  * @return ModelConfiguration
  */
 public function model()
 {
     return Admin::model($this->class);
 }
Beispiel #30
-1
 /**
  * @param string $name
  * @param string $label
  */
 function __construct($name, $label = null)
 {
     $this->name = $name;
     $this->label = is_null($label) ? ucwords(str_replace('_', ' ', $name)) : $label;
     $this->htmlBuilder = Admin::instance()->htmlBuilder;
     $this->modelItem = ModelItem::$current;
 }