function traitEntityItemDelete()
 {
     $this->traitEntity_assertReason($this->model, 'delete');
     $data = ['vendor' => (string) static::getVendor(), 'entity' => \Str::snake($this->getEntity())];
     if ($this->model->deleted_at) {
         //            $this->model->restore();
         //            dd();
         $data['state'] = -1;
         $data['message'] = static::translateAction('item|delete.success.hard', ['model' => $this->model]);
         $data['models'][] = ['id' => $this->model->id];
         $this->model->forceDelete();
     } else {
         $this->model->delete();
         $data['state'] = 0;
         $data['message'] = static::translateAction('item|delete.success.soft', ['model' => $this->model]);
         $row_types = ManagerRowType::get(ManagerRowType::makeKey(static::getVendor(), static::getEntity()));
         $rows = [];
         foreach ($row_types as $row_type) {
             $rows[$row_type] = (string) Accessor::factory($this->model)->row($row_type);
         }
         $data['models'][] = ['id' => $this->model->id, 'model' => $this->model->toArray(), 'rows' => $rows];
     }
     $this->traitAjax_set($data);
     Event::notify('larakit::model_delete-admin', $data);
     return $this->traitAjax_response();
 }
示例#2
0
 /**
  * Get the @class (Class Name) associated with the model.
  *
  * @return string
  */
 public function getTable()
 {
     if (isset($this->table)) {
         return $this->table;
     }
     return str_replace('\\', '', Str::snake(Str::plural(class_basename($this))));
 }
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     if (parent::fire() !== false) {
         if ($this->option('migration')) {
             $table = Str::plural(Str::snake(class_basename($this->argument('name'))));
             $this->call('make:rethink-migration', ['name' => "create_{$table}_table", '--create' => $table]);
         }
     }
 }
示例#4
0
 public function __construct()
 {
     $class = get_class($this);
     $this->name = \Str::snake($class);
     $this->key = str_replace('_plugin', '', $this->name);
     $this->config = $this->loadConfig();
     if (!bool(element('enabled', $this->config, true))) {
         throw new \InvalidEntryException();
     }
 }
示例#5
0
 static function makeModelClass($vendor, $entity)
 {
     $class = $vendor;
     $data = explode('\\', $class);
     $count = substr_count($class, '\\');
     if ($count >= 3) {
         $class = \Str::snake(Arr::get($data, 0) . Arr::get($data, 1), '-');
     } else {
         $class = \Str::snake(Arr::get($data, 0));
     }
     return \Str::studly($class) . '\\Model\\' . \Str::studly($entity);
 }
 function traitEntityRestore()
 {
     $this->traitEntity_assertReason($this->model, 'restore');
     $this->model->restore();
     $row_types = ManagerRowType::get(ManagerRowType::makeKey(static::getVendor(), static::getEntity()));
     $rows = [];
     foreach ($row_types as $row_type) {
         $rows[$row_type] = (string) Accessor::factory($this->model)->row($row_type);
     }
     $data = ['models' => [['model' => $this->model->toArray(), 'rows' => $rows, 'id' => $this->model->id]], 'vendor' => (string) static::getVendor(), 'entity' => \Str::snake($this->getEntity()), 'message' => sprintf($this->traitEntityItemRestore_success(), $this->model), 'state' => 1];
     Event::notify('larakit::model_restore-admin', $data);
     $this->traitAjax_set($data);
     return $this->traitAjax_response();
 }
示例#7
0
 /**
  * Remove a site from the config.
  *
  * @param $site
  *
  * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
  */
 public function deleteConfig($site)
 {
     // Convert yaml to array
     $config = $this->getConfig();
     // Look for the site in sites and in databases
     foreach ($config['sites'] as $key => $homesteadSite) {
         if ($homesteadSite['map'] == $site->name) {
             unset($config['sites'][$key]);
         }
     }
     foreach ($config['databases'] as $key => $homesteadDatabase) {
         if ($homesteadDatabase == Str::snake(str_replace('.app', '', $site->name))) {
             unset($config['databases'][$key]);
         }
     }
     // Rebuild the yaml
     $this->saveConfig($config);
 }
示例#8
0
 /**
  * @var \Eloquent
  */
 function __construct()
 {
     $class = new \ReflectionClass(get_called_class());
     $methods = $class->getMethods();
     foreach ($methods as $method) {
         $name = $method->getName();
         if ('rule' == mb_substr($name, 0, 4)) {
             $rule = [];
             $rule[] = static::getVendor();
             $rule[] = static::getEntity();
             $rule[] = \Str::snake(mb_substr($name, 4));
             $ext = [];
             $ext[] = $class->getName();
             $ext[] = $name;
             $rule = implode('_', $rule);
             $ext = implode('@', $ext);
             \Validator::extend($rule, $ext);
         }
     }
 }
示例#9
0
<?php

Route::pattern('idu', '[0-9]+');
Route::group(array('before' => 'basicAuth', 'prefix' => Config::get('backend.uri') . '/' . Config::get('backend.group_advertiser_manager_url')), function () {
    $prefixName = Str::studly(pathinfo(__DIR__, PATHINFO_BASENAME));
    $prefixSlug = Str::snake($prefixName, '-');
    Route::get('/tool', array('as' => $prefixName . 'ShowTool', 'uses' => $prefixName . 'Controller@tool'));
    Route::post('/tool/search', array('uses' => $prefixName . 'Controller@getListSelect'));
    //profile publisher
    Route::get('/tool/profile', array('before' => 'hasPermissions:' . $prefixSlug . '-edit', 'as' => $prefixName . 'Profile', 'uses' => $prefixName . 'Controller@myProfile'));
    Route::post('/tool/profile', array('before' => 'hasPermissions:' . $prefixSlug . '-edit', 'as' => $prefixName . 'Profile', 'uses' => $prefixName . 'Controller@myProfile'));
    Route::post('/tool/get-list', array('as' => $prefixName . 'GetList', 'uses' => $prefixName . 'Controller@getList'));
    Route::post('/tool/get-user', array('as' => $prefixName . 'GetUser', 'uses' => $prefixName . 'Controller@getUserId'));
    Route::get('/tool/user-manager', array('before' => 'hasPermissions:' . $prefixSlug . '-edit', 'as' => $prefixName . 'UserManager', 'uses' => $prefixName . 'Controller@userManager'));
    Route::get('/tool/list-publisher', array('before' => 'hasPermissions:' . $prefixSlug . '-read', 'as' => $prefixName . 'ShowListPublisher', 'uses' => $prefixName . 'Controller@showListPublisher'));
    Route::post('/tool/get-list-publisher', array('as' => $prefixName . 'GetListPublisher', 'uses' => $prefixName . 'Controller@getListPublisherManager'));
    Route::get('/tool/user-edit/{idu}', array('as' => $prefixName . 'ShowUpdate', 'uses' => $prefixName . 'Controller@myProfile'));
    Route::post('/tool/user-edit/{idu}', array('as' => $prefixName . 'ShowUpdate', 'uses' => $prefixName . 'Controller@myProfile'));
    Route::post('/tool/sort-flight-running', array('before' => 'hasPermissions:' . $prefixSlug . '-edit', 'as' => $prefixName . 'SortFlightRunning', 'uses' => $prefixName . 'Controller@sortFlightRunning'));
    Route::post('/tool/update-sort-flight-running', array('before' => 'hasPermissions:' . $prefixSlug . '-edit', 'as' => $prefixName . 'UpdateSortFlightRunning', 'uses' => $prefixName . 'Controller@postSortFlightRunning'));
    Route::post('/tool/preview', array('as' => $prefixName . 'Preview', 'uses' => $prefixName . 'Controller@preview'));
    Route::get('/tool/dashboard', array('as' => $prefixName . 'Preview', 'uses' => $prefixName . 'Controller@getDashboard'));
    Route::post('/tool/dashboard/campaign', array('as' => $prefixName . 'PreviewCampaign', 'uses' => $prefixName . 'Controller@getDashboardCampaign'));
    Route::post('/tool/dashboard/flightwebsite', array('as' => $prefixName . 'PreviewFlightWebsite', 'uses' => $prefixName . 'Controller@getDashboardFilghtWebsite'));
    Route::get('/tool/create-new-url-track', array('as' => $prefixName . 'CreateNew', 'uses' => $prefixName . 'Controller@createNewTrackURL'));
    Route::post('/tool/create-new-url-track', array('as' => $prefixName . 'CreateNew', 'uses' => $prefixName . 'Controller@createNewTrackURl'));
    Route::get('/tool/url-track-ga', array('as' => $prefixName . 'URLTrackGA', 'uses' => $prefixName . 'Controller@getUrlTrackGA'));
    Route::get('/tool/edit-url-track/{id}', array('as' => $prefixName . 'Edit', 'uses' => $prefixName . 'Controller@editTrackURL'));
    Route::post('/tool/edit-url-track/{id}', array('as' => $prefixName . 'Edit', 'uses' => $prefixName . 'Controller@editTrackURL'));
    Route::get('/tool/detail-url-track/{id}', array('as' => $prefixName . 'DetailUrlTrack', 'uses' => $prefixName . 'Controller@detailTrackURL'));
    Route::post('/tool/delete-url-track', array('as' => $prefixName . 'Delete', 'uses' => $prefixName . 'Controller@deleteTrackURL'));
 /**
  * get model table columns
  *
  * @return mixed
  */
 protected function getColumns()
 {
     static $columns = [];
     if (!isset($columns[$this->modelClass])) {
         // if implemented "getAvailableFields"
         $callable = [$this->modelClass, 'getAvailableFields'];
         if (is_callable($callable)) {
             $columns[$this->modelClass] = call_user_func($callable);
         } else {
             /** @var \Illuminate\Database\Connection $connection */
             $connection = $this->_query()->getQuery()->getConnection();
             $columns[$this->modelClass] = $connection->getSchemaBuilder()->getColumnListing(str_replace('\\', '', Str::snake(Str::plural(class_basename($this->modelClass)))));
         }
     }
     return $columns[$this->modelClass];
 }
示例#11
0
 /**
  * Convert a string to snake case.
  *
  * @param  string  $value
  * @param  string  $delimiter
  * @return string
  */
 function snake_case($value, $delimiter = '_')
 {
     return Str::snake($value, $delimiter);
 }
 function traitEntityHasMany_item()
 {
     if (\Request::method() == 'POST') {
         $this->traitEntityHasMany_save();
         //переоткроем модель
         $model_name = $this->getClassModel();
         if ($model_name::isSoftDelete()) {
             $model = $model_name::withTrashed()->with($this->relation)->find(\Route::input('id'));
         } else {
             $model = $model_name::with($this->relation)->find(\Route::input('id'));
         }
         $row_types = ManagerRowType::get(ManagerRowType::makeKey(static::getVendor(), static::getEntity()));
         $rows = [];
         foreach ($row_types as $row_type) {
             $rows[$row_type] = (string) Accessor::factory($model)->row($row_type);
         }
         $data = ['models' => [['rows' => $rows, 'model' => $model->toArray(), 'id' => $model->id]], 'vendor' => (string) static::getVendor(), 'entity' => \Str::snake(static::getEntity()), 'message' => sprintf($this->traitEntityHasMany_successMessage(), $model)];
         Event::notify('larakit::model_edit-admin', $data);
         $this->traitAjax_set($data);
         return $this->traitAjax_response();
     }
     $this->traitAjax_set('id', $this->model->id)->traitAjax_set('result', 'curtain')->traitAjax_set('vendor', (string) \Str::snake($this->getVendor()))->traitAjax_set('entity', (string) \Str::snake($this->getEntity()))->traitAjax_set('model', $this->model->toArray())->traitAjax_set('header', (string) $this->traitEntityHasMany_header())->traitAjax_set('body', (string) $this->traitEntityHasMany_body())->traitAjax_set('footer', (string) $this->traitEntityHasMany_footer());
     return $this->traitAjax_response();
 }
示例#13
0
 function traitEntityAddJson()
 {
     $this->traitAjax_set('id', $this->model->id)->traitAjax_set('result', 'curtain')->traitAjax_set('vendor', (string) static::getVendor())->traitAjax_set('entity', (string) \Str::snake($this->getEntity()))->traitAjax_set('model', $this->model->toArray())->traitAjax_set('header', (string) $this->traitEntityAdd_header())->traitAjax_set('body', (string) $this->traitEntityAdd_body())->traitAjax_set('footer', (string) $this->traitEntityAdd_footer());
     return $this->traitAjax_response();
 }
示例#14
0
 /**
  * Get the table associated with the model.
  *
  * @return string
  */
 public function getTable()
 {
     $table = \Config::get('auditing.table');
     if (isset($table)) {
         return $table;
     }
     return str_replace('\\', '', Str::snake(Str::plural(class_basename($this))));
 }
示例#15
0
 /**
  * @param \Controller $class_name
  *
  * @return array
  */
 protected static function deNormalizeController($class_name)
 {
     preg_match('|^([A-Za-z\\\\]+)Controller\\\\([A-Za-z\\\\]+)Controller([A-Za-z]+)$|Umsi', $class_name, $matches);
     $vendor = trim(Arr::get($matches, 1, ''), '\\');
     $section = trim(Arr::get($matches, 2, ''), '\\');
     $entity = mb_substr(Arr::get($matches, 3), mb_strlen($section));
     if (method_exists($class_name, 'getEntitySuffix')) {
         $suffix = \Str::studly($class_name::getEntitySuffix());
         if ($suffix) {
             $entity = mb_substr($entity, 0, 0 - mb_strlen($suffix));
         }
     }
     return ['vendor' => str_replace('\\', '', \Str::snake($vendor, '-')), 'entity' => \Str::snake($entity), 'section' => \Str::snake($section), 'route_prefix' => \Str::snake($section)];
 }
示例#16
0
/**
 * Tries to translate a module/model/controller name.
 * 
 * @param  string $name     The name of the module/model/controller
 * @param  string $module   The name of the module
 * @return string 
 */
function trans_object($name, $module = null)
{
    $translator = app('translator');
    $name = Str::snake($name);
    $moduleKey = $module . '::object_' . $name;
    $appKey = 'app.object_' . $name;
    if ($module and $translator->has($moduleKey)) {
        return trans($moduleKey);
    }
    if ($translator->has($appKey)) {
        return trans($appKey);
    }
    return $name;
}
示例#17
0
 /**
  * @return LaraForm
  */
 function build()
 {
     $rfl = new \ReflectionClass($this);
     foreach ($rfl->getMethods() as $method) {
         $name = $method->getName();
         if (0 === mb_strpos($name, 'add') && $name != 'add') {
             $field = \Str::snake(mb_substr($name, 3));
             $this->add($field);
         }
     }
     return $this->form;
 }
 function traitEntityBelongsTo_item()
 {
     if (\Request::method() == 'POST') {
         $id = (int) \Input::get('belongs_to');
         $this->model->{$this->getRelationKey()} = $id;
         $this->model->save();
         //                        ->sync($ids);
         //переоткроем модель
         $model_name = $this->getClassModel();
         /** @var Model $model */
         if ($model_name::isSoftDelete()) {
             $model = $model_name::withTrashed();
         } else {
             $model = $model_name::select();
         }
         //откроем со всеми связями, которые могут потребоваться для шаблона ROW
         foreach ($model->getModel()->getRelations() as $relation) {
             $model->with($relation);
         }
         $model = $model->find(\Route::input('id'));
         $row_types = ManagerRowType::get(ManagerRowType::makeKey(static::getVendor(), static::getEntity()));
         $rows = [];
         foreach ($row_types as $row_type) {
             $rows[$row_type] = (string) Accessor::factory($model)->row($row_type);
         }
         $data = ['models' => [['rows' => $rows, 'model' => $model->toArray(), 'id' => $model->id]], 'vendor' => (string) static::getVendor(), 'entity' => \Str::snake(static::getEntity()), 'message' => sprintf($this->traitEntityBelongsTo_successMessage(), $model)];
         Event::notify('larakit::model_edit-admin', $data);
         $this->traitAjax_set($data);
         return $this->traitAjax_response();
     }
     $this->traitAjax_set('id', $this->model->id)->traitAjax_set('result', 'curtain')->traitAjax_set('vendor', static::getVendor())->traitAjax_set('entity', $this->getEntity())->traitAjax_set('model', $this->model->toArray())->traitAjax_set('header', (string) $this->traitEntityBelongsTo_header())->traitAjax_set('body', (string) $this->traitEntityBelongsTo_body())->traitAjax_set('footer', (string) $this->traitEntityBelongsTo_footer());
     return $this->traitAjax_response();
 }
示例#19
0
 /**
  * Make the classes from controller and action
  *
  * @return string
  */
 public function makeClassFromController()
 {
     if (!($action = Route::currentRouteAction())) {
         return;
     }
     // Strip restful prefixes and suffices
     preg_match('#(\\w+)Controller@(?:get|post)?(\\w+)#i', $action, $matches);
     // Make an action for missing methods
     if ($matches[2] == 'missingMethod') {
         $matches[2] = implode(' ', Request::segments());
     }
     // Combine controller and action to make class
     return str_snake($matches[1], '-') . ' ' . Str::snake($matches[2], '-');
 }
示例#20
0
 /**
  * Creates a snake plural
  */
 public function transformPluralSnake($key, $value)
 {
     return array('_' . Str::plural(Str::snake($key)) . '_', Str::plural(Str::snake($value)));
 }
 function traitEntityItemToggle()
 {
     $field = \Input::get('field');
     $this->traitEntity_assertReason($this->model, 'toggle_' . $field);
     $method = \Str::camel('switch_' . $field);
     if (!is_callable([$this, $method])) {
         throw new Exception('Поле не является тумблером');
     }
     $message = call_user_func([$this, $method]);
     $this->model->save();
     $row_types = ManagerRowType::get(ManagerRowType::makeKey(static::getVendor(), static::getEntity()));
     $rows = [];
     foreach ($row_types as $row_type) {
         $rows[$row_type] = (string) Accessor::factory($this->model)->row($row_type);
     }
     $data = ['models' => [['rows' => $rows, 'model' => $this->model->toArray(), 'id' => $this->model->id]], 'vendor' => (string) static::getVendor(), 'entity' => \Str::snake(static::getEntity()), 'message' => $message ? sprintf($message, $this->model) : 'Значение поля изменено на противоположное'];
     if (in_array($field, $this->traitEntityItemToggle_mass())) {
         $rows = [];
         $model_name = get_class($this->model);
         foreach ($model_name::get() as $model) {
             $rows = [];
             foreach ($row_types as $row_type) {
                 $rows[$row_type] = (string) Accessor::factory($model)->row($row_type);
             }
             $data['models'][] = ['rows' => $rows, 'model' => $model->toArray(), 'id' => $model->id];
         }
     }
     $this->traitAjax_set($data);
     return $this->traitAjax_response();
 }
示例#22
0
<?php

/*
=================================================
Module Name     :   Company Info
Module Version  :   v1.0
Compatible CMS  :   v1.2
Site            :   http://doptor.net
Description     :
===================================================
*/
$current_dir = Str::snake(basename(__DIR__), '_');
$routeCollection = Route::getRoutes();
/* Company Info Homepage */
Route::get('modules/' . $current_dir, ['uses' => 'Modules\\Doptor\\CompanyInfo\\Controllers\\CompanyController@index', 'as' => 'modules.' . $current_dir]);
Route::get('admin/modules/' . $current_dir, ['uses' => 'Modules\\Doptor\\CompanyInfo\\Controllers\\CompanyController@index', 'as' => 'admin.modules.' . $current_dir]);
Route::get('backend/modules/' . $current_dir, ['uses' => 'Modules\\Doptor\\CompanyInfo\\Controllers\\CompanyController@index', 'as' => 'backend.modules.' . $current_dir]);
/* View Branches of a company */
Route::get('modules/' . $current_dir . '/{company_id}/branches', ['uses' => 'Modules\\Doptor\\CompanyInfo\\Controllers\\CompanyBranchController@index', 'as' => 'modules.' . $current_dir . '.companies.branches']);
Route::get('admin/modules/' . $current_dir . '/{company_id}/branches', ['uses' => 'Modules\\Doptor\\CompanyInfo\\Controllers\\CompanyBranchController@index', 'as' => 'admin.modules.' . $current_dir . '.companies.branches']);
Route::get('backend/modules/' . $current_dir . '/{company_id}/branches', ['uses' => 'Modules\\Doptor\\CompanyInfo\\Controllers\\CompanyBranchController@index', 'as' => 'backend.modules.' . $current_dir . '.companies.branches']);
/* Company Branches */
Route::resource('modules/' . $current_dir . '/branches', 'Modules\\Doptor\\CompanyInfo\\Controllers\\CompanyBranchController');
Route::resource('admin/modules/' . $current_dir . '/branches', 'Modules\\Doptor\\CompanyInfo\\Controllers\\CompanyBranchController');
Route::resource('backend/modules/' . $current_dir . '/branches', 'Modules\\Doptor\\CompanyInfo\\Controllers\\CompanyBranchController');
/* Companies */
Route::resource('modules/' . $current_dir . '/companies', 'Modules\\Doptor\\CompanyInfo\\Controllers\\CompanyController');
Route::resource('admin/modules/' . $current_dir . '/companies', 'Modules\\Doptor\\CompanyInfo\\Controllers\\CompanyController');
Route::resource('backend/modules/' . $current_dir . '/companies', 'Modules\\Doptor\\CompanyInfo\\Controllers\\CompanyController');
/*foreach ($routeCollection as $value) {
    // dd(get_class_methods($value));
 /**
  * @param \Illuminate\Database\Eloquent\Model $model
  */
 protected function getPropertiesFromMethods($model)
 {
     $methods = get_class_methods($model);
     if ($methods) {
         foreach ($methods as $method) {
             if (\Str::startsWith($method, 'get') && \Str::endsWith($method, 'Attribute') && $method !== 'setAttribute') {
                 //Magic get<name>Attribute
                 $name = \Str::snake(substr($method, 3, -9));
                 if (!empty($name)) {
                     $this->setProperty($name, null, true, null);
                 }
             } elseif (\Str::startsWith($method, 'set') && \Str::endsWith($method, 'Attribute') && $method !== 'setAttribute') {
                 //Magic set<name>Attribute
                 $name = \Str::snake(substr($method, 3, -9));
                 if (!empty($name)) {
                     $this->setProperty($name, null, null, true);
                 }
             } elseif (\Str::startsWith($method, 'scope') && $method !== 'scopeQuery') {
                 //Magic set<name>Attribute
                 $name = \Str::camel(substr($method, 5));
                 if (!empty($name)) {
                     $reflection = new \ReflectionMethod($model, $method);
                     $args = $this->getParameters($reflection);
                     //Remove the first ($query) argument
                     array_shift($args);
                     $this->setMethod($name, $reflection->class, $args);
                 }
             } elseif (!method_exists('Eloquent', $method) && !\Str::startsWith($method, 'get')) {
                 //Use reflection to inspect the code, based on Illuminate/Support/SerializableClosure.php
                 $reflection = new \ReflectionMethod($model, $method);
                 $file = new \SplFileObject($reflection->getFileName());
                 $file->seek($reflection->getStartLine() - 1);
                 $code = '';
                 while ($file->key() < $reflection->getEndLine()) {
                     $code .= $file->current();
                     $file->next();
                 }
                 $begin = strpos($code, 'function(');
                 $code = substr($code, $begin, strrpos($code, '}') - $begin + 1);
                 $begin = stripos($code, 'return $this->');
                 $parts = explode("'", substr($code, $begin + 14), 3);
                 //"return $this->" is 14 chars
                 if (isset($parts[2])) {
                     list($relation, $returnModel, $rest) = $parts;
                     $returnModel = "\\" . ltrim($returnModel, "\\");
                     $relation = trim($relation, ' (');
                     if ($relation === "belongsTo" or $relation === 'hasOne') {
                         //Single model is returned
                         $this->setProperty($method, $returnModel, true, null);
                     } elseif ($relation === "belongsToMany" or $relation === 'hasMany') {
                         //Collection or array of models (because Collection is Arrayable)
                         $this->setProperty($method, '\\Illuminate\\Database\\Eloquent\\Collection|' . $returnModel . '[]', true, null);
                     }
                 } else {
                     //Not a relation
                 }
             }
         }
     }
 }