/**
  * @param array $data
  * @return CampaignEmail
  */
 public function createEntity($data = array())
 {
     $final = [];
     foreach ($data as $key => $value) {
         $newKey = camel_case($key);
         // sort out dates
         if ($newKey == 'createdAt') {
             $value = new DateTime($value);
         }
         if ($newKey == 'updatedAt') {
             $value = new DateTime($value);
         }
         // sort out emails
         if ($newKey == 'emailAddress') {
             $value = new Email($value);
         }
         if ($newKey == 'variables') {
             if (!is_array($value)) {
                 $value = json_decode($value, true);
             }
         }
         $final[$newKey] = $value;
     }
     return new CampaignEmail($final);
 }
示例#2
0
 /**
  * Map to get.
  *
  * @param $name
  * @return mixed
  */
 public function __get($name)
 {
     if ($this->has($name)) {
         return $this->get($name);
     }
     return call_user_func([$this, camel_case($name)]);
 }
示例#3
0
 /**
  * @param \stdClass|array $parameters
  */
 public function build($parameters)
 {
     foreach ($parameters as $property => $value) {
         $property = camel_case($property);
         $this->{$property} = $value;
     }
 }
示例#4
0
 /**
  * Get an instance of the current geoip.
  *
  * @return \PulkitJalan\GeoIP\GeoIP
  */
 function geoip($key = null)
 {
     if (is_null($key)) {
         return app('geoip');
     }
     return app('geoip')->{'get' . ucwords(camel_case($key))}();
 }
示例#5
0
 /**
  * Render a Field.
  *
  * @param string $type
  * @param string $attribute
  * @param string $field
  * @param string $options
  *
  * @return \Illuminate\Http\Response
  */
 public function render($action, $type, $attribute, $value = null, $options = [])
 {
     if (!isset($type)) {
         throw new \Exception('Field Type cannot be empty or undefined.');
     }
     return call_user_func_array([$this->create($type, $attribute, $value, $options), camel_case('render_' . $action)], []);
 }
 private function doGenerateMethods()
 {
     $methodPostfix = ucfirst(camel_case(preg_replace('~2~', '_to_', $this->table)));
     $this->info('Routes:');
     $getRoute = "Route::get('" . $this->trimAdminPrefix($this->getRequestUri) . "', 'TableAdminController@show" . $methodPostfix . "');";
     $postRoute = "Route::post('" . $this->trimAdminPrefix($this->postRequestUri) . "', 'TableAdminController@handle" . $methodPostfix . "');";
     $this->line($getRoute);
     $this->line($postRoute);
     $this->info('Methods:');
     $showMethod = 'public function show' . $methodPostfix . '()' . PHP_EOL;
     $showMethod .= '{' . PHP_EOL;
     $showMethod .= '    $options = array(' . PHP_EOL;
     $showMethod .= "        'url'      => '" . $this->getRequestUri . "'," . PHP_EOL;
     $showMethod .= "        'def_name' => '" . $this->definition . "'," . PHP_EOL;
     $showMethod .= '    );' . PHP_EOL;
     $showMethod .= '    list($table, $form) = Jarboe::table($options);' . PHP_EOL . PHP_EOL;
     $showMethod .= "    return View::make('admin::table', compact('table', 'form'));" . PHP_EOL;
     $showMethod .= '} // end show' . $methodPostfix . PHP_EOL . PHP_EOL;
     echo $showMethod;
     $postMethod = 'public function handle' . $methodPostfix . '()' . PHP_EOL;
     $postMethod .= '{' . PHP_EOL;
     $postMethod .= '    $options = array(' . PHP_EOL;
     $postMethod .= "        'url'      => '" . $this->getRequestUri . "'," . PHP_EOL;
     $postMethod .= "        'def_name' => '" . $this->definition . "'," . PHP_EOL;
     $postMethod .= '    );' . PHP_EOL . PHP_EOL;
     $postMethod .= '    return Jarboe::table($options);' . PHP_EOL;
     $postMethod .= '} // end handle' . $methodPostfix . PHP_EOL;
     echo $postMethod;
 }
 public function handle()
 {
     if ($this->option('only-state')) {
         $this->input->setOption('template', 0);
         $this->input->setOption('controller', 0);
         $this->input->setOption('abstract', 1);
     }
     $state = $this->argument('state');
     $abstractOption = $this->option('abstract');
     $templateOption = $this->option('template');
     $controllerOption = $this->option('controller');
     $statePieces = explode('.', $state);
     $path = 'src/application/' . str_replace('.', '/', $state);
     $absolutePath = public_path($path);
     $controller = implode(array_map(function ($piece) {
         return ucfirst(camel_case($piece));
     }, $statePieces)) . 'Ctrl';
     $name = end($statePieces);
     $variables = compact('name', 'state', 'absolutePath', 'path', 'controller', 'abstractOption', 'templateOption', 'controllerOption');
     if (!file_exists($absolutePath) && $this->confirm('The folder does not exist, shall I create it?')) {
         mkdir($absolutePath);
     }
     $this->make('.html', $variables);
     $this->make('.controller.js', $variables);
     $this->make('.state.js', $variables);
 }
示例#8
0
 public function apply($builder, RepositoryInterface $repository)
 {
     $fieldsSearchable = $repository->getFieldsSearchable();
     $search = $this->request->get(config('repository.criteria.params.search', 'search'), null);
     $searchFields = $this->request->get(config('repository.criteria.params.searchFields', 'searchFields'), null);
     $filter = $this->request->get(config('repository.criteria.params.filter', 'filter'), null);
     $orderBy = $this->request->get(config('repository.criteria.params.orderBy', 'orderBy'), null);
     $sortedBy = $this->request->get(config('repository.criteria.params.sortedBy', 'sortedBy'), 'asc');
     $sortedBy = !empty($sortedBy) ? $sortedBy : 'asc';
     if ($search && is_array($fieldsSearchable) && count($fieldsSearchable)) {
         $searchFields = is_array($searchFields) || is_null($searchFields) ? $searchFields : explode(';', $searchFields);
         $fields = $this->parserFieldsSearch($fieldsSearchable, $searchFields);
         $isFirstField = true;
         $searchData = $this->parserSearchData($search);
         $search = $this->parserSearchValue($search);
         $modelForceAndWhere = false;
         $builder = $builder->where(function ($query) use($fields, $search, $searchData, $isFirstField, $modelForceAndWhere) {
             foreach ($fields as $field => $condition) {
                 if (is_numeric($field)) {
                     $field = $condition;
                     $condition = '=';
                 }
                 $value = null;
                 $condition = trim(strtolower($condition));
                 if (isset($searchData[$field])) {
                     $value = $condition == 'like' ? "%{$searchData[$field]}%" : $searchData[$field];
                 } else {
                     if (!is_null($search)) {
                         $value = $condition == 'like' ? "%{$search}%" : $search;
                     }
                 }
                 if ($isFirstField || $modelForceAndWhere) {
                     if (!is_null($value)) {
                         $query->where($field, $condition, $value);
                         $isFirstField = false;
                     }
                 } else {
                     if (!is_null($value)) {
                         $query->orWhere($field, $condition, $value);
                     }
                 }
             }
         });
     }
     if (isset($orderBy) && in_array(strtolower($sortedBy), ['asc', 'desc'])) {
         $builder = $builder->orderBy($orderBy, $sortedBy);
     }
     if (isset($filter) && !empty($filter)) {
         if (is_string($filter)) {
             foreach (array_unique(explode(',', $filter)) as $filter) {
                 // eg. filter 'hot' 会调用方法 'filterHot'
                 $method_name = camel_case('filter_' . $filter);
                 if (method_exists($this, $method_name)) {
                     $builder = call_user_func([$this, $method_name], $builder);
                 }
             }
         }
     }
     return $builder;
 }
示例#9
0
 /**
  * Create a new form.
  *
  * @param  string  $model
  * @param  array  $columns
  * @param  string  $view
  * @return void
  */
 public function create($model, $columns = [], $view = 'form')
 {
     $model = $this->sanitize($model);
     $this->writeLangFiles($columns, $model);
     $stub = $this->getStub('form.blade.stub');
     $el = [];
     foreach ($columns as $col) {
         $col['field'] = $this->sanitize($col['field'], '/[^a-zA-Z0-9_-]/');
         switch ($col['type']) {
             case 'text':
             case 'mediumText':
             case 'longText':
                 $inputStub = $this->getStub('form-textarea.stub');
                 break;
             case 'boolean':
             case 'tinyInteger':
                 $inputStub = $this->getStub('form-checkbox.stub');
                 break;
             case 'string':
             default:
                 $inputStub = $this->getStub('form-input.stub');
                 break;
         }
         $el[] = $this->prepare($inputStub, ['field_name' => $col['field'], 'camel_model' => camel_case(strtolower($model)), 'plural_lower_model' => strtolower(Str::plural($model))]);
     }
     $content = $this->prepare($stub, ['columns' => implode("\n\t\t\t\t", $el), 'camel_model' => camel_case(strtolower($model)), 'plural_lower_model' => strtolower(Str::plural($model))]);
     $filePath = $this->path . '/themes/admin/default/packages/' . $this->extension->lowerVendor . '/' . $this->extension->lowerName . '/views/' . Str::plural(strtolower($model)) . '/';
     $this->ensureDirectory($filePath);
     $this->files->put($filePath . $view . '.blade.php', $content);
 }
示例#10
0
 /**
  * Creates a new Lavary\Menu\MenuItem instance.
  *
  * @param  string  $title
  * @param  string  $url
  * @param  array  $attributes
  * @param  int  $parent
  * @param  \Lavary\Menu\Menu  $builder
  * @return void
  */
 public function __construct($builder, $id, $title, $options)
 {
     $this->builder = $builder;
     $this->id = $id;
     $this->title = $title;
     $this->nickname = camel_case($title);
     $this->attributes = $this->builder->extractAttributes($options);
     $this->parent = is_array($options) && isset($options['parent']) ? $options['parent'] : null;
     // Storing path options with each link instance.
     if (!is_array($options)) {
         $path = array('url' => $options);
     } elseif (isset($options['raw']) && $options['raw'] == true) {
         $path = null;
     } else {
         $path = array_only($options, array('url', 'route', 'action', 'secure'));
     }
     if (!is_null($path)) {
         $path['prefix'] = $this->builder->getLastGroupPrefix();
     }
     $this->link = $path ? new Link($path) : null;
     // If the item's URL is the same as request URI,
     // activate the item and it's parent nodes too.
     if (true === \Config::get('laravel-menu::options.auto_activate')) {
         if (\Request::url() == $this->url()) {
             $this->activate();
         }
     }
 }
 /**
  * @param array $data
  * @return Campaign
  */
 public function createEntity($data = array())
 {
     $final = [];
     foreach ($data as $key => $value) {
         $newKey = camel_case($key);
         // sort out dates
         if ($newKey == 'createdAt') {
             $value = new DateTime($value);
         }
         if ($newKey == 'updatedAt') {
             $value = new DateTime($value);
         }
         // sort out emails
         if ($newKey == 'fromEmail') {
             $value = new Email($value);
         }
         if ($newKey == 'replyToEmail') {
             if ($value) {
                 $value = new Email($value);
             } else {
                 continue;
             }
         }
         if ($newKey == 'bounceEmail') {
             if ($value) {
                 $value = new Email($value);
             } else {
                 continue;
             }
         }
         $final[$newKey] = $value;
     }
     return new Campaign($final);
 }
 /**
  * Check if name is not snake case.
  *
  * @param string $name
  * @param string $definedClass
  * @return boolean
  */
 public function validateName($name, $definedClass)
 {
     if ($name != camel_case($name)) {
         throw new Exception('Name "' . $name . '" (defined in class "' . $definedClass . '") is not a camel case name.');
     }
     return true;
 }
示例#13
0
 protected function setUpModel(\Illuminate\Http\Request $request)
 {
     $uri = $request->route()->uri();
     $modelSlug = strpos($uri, '/') ? substr($uri, 0, strpos($uri, '/')) : $uri;
     $modelName = ucfirst(camel_case(str_singular($modelSlug)));
     $modules = new \Ormic\Modules();
     $module = $modules->getModuleOfModel($modelName);
     if ($module) {
         $modelClass = 'Ormic\\modules\\' . $module . '\\Model\\' . $modelName;
         $viewName = snake_case($module) . '::' . snake_case($modelName) . '.' . $this->currentAction;
     } else {
         $modelClass = 'Ormic\\Model\\' . $modelName;
         $viewName = snake_case($modelName) . '.' . $this->currentAction;
     }
     $this->model = new $modelClass();
     $this->model->setUser($this->user);
     try {
         $this->view = view($viewName);
     } catch (\InvalidArgumentException $ex) {
         try {
             $this->view = view('models.' . $this->currentAction);
         } catch (\InvalidArgumentException $ex) {
             // Still no view; give up.
             $this->view = view();
         }
     }
     $this->view->title = ucwords(str_replace('-', ' ', $modelSlug));
     $this->view->modelSlug = $modelSlug;
     $this->view->columns = $this->model->getColumns();
     $this->view->record = $this->model;
 }
 /**
  * @param $query
  *
  * @return mixed
  */
 public function listData($query)
 {
     foreach ($this->search as $column => $search) {
         $query = $query->{'of' . ucfirst(camel_case(str_replace('.', '_', $column)))}($search);
     }
     return $query->orderBy($this->sort, $this->sortDirection)->select($this->tableName . '.*')->paginate($this->limit);
 }
示例#15
0
 public function stepsBeforeFilter(Route $route)
 {
     $routeStep = $this->getStepFromRoute($route);
     $this->stepSessionKey($route);
     $currentStep = $this->getCurrentStep();
     $state = 'complete';
     $this->stepsData = [];
     foreach ($this->steps as $step) {
         if ($step == $routeStep) {
             if ($state == 'disabled') {
                 return $this->stepNotAllowed();
             }
             $class = 'active';
             $state = 'disabled';
         }
         if ($step == $currentStep && $state != 'disabled') {
             $class = 'active';
             $state = 'disabled';
         } elseif ($step != $routeStep) {
             $class = $state;
         }
         $this->stepsData[$step] = ['class' => $class, 'action' => get_class() . '@get' . ucfirst(camel_case($step))];
     }
     $this->setCurrentStep($routeStep);
 }
 /**
  * @param $parameters
  * @return mixed
  */
 public function present($parameters)
 {
     if (method_exists($this, 'handle' . camel_case($parameters['action']))) {
         return $this->{'handle' . camel_case($parameters['action'])}($parameters['for_id'], $parameters['data']);
     }
     return $parameters['action'];
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $name = $this->argument('name');
     $view = $name;
     // items
     $request = str_singular(ucwords(camel_case($name))) . 'Request.php';
     // ItemRequest.php
     $model = str_singular(ucwords(camel_case($name))) . '.php';
     // Item.php;
     $presenter = str_singular(ucwords(camel_case($name))) . 'Presenter.php';
     // ItemPresenter.php;
     $controller = ucwords(camel_case($name)) . 'Controller.php';
     // ItemsController.php
     $seed = ucwords(camel_case($name)) . 'TableSeeder.php';
     // ItemsTableSeeder.php
     $views = base_path('resources/views/' . $view);
     $request = base_path('app/Http/Requests/' . $request);
     $model = base_path('app/Models/' . $model);
     $presenter = base_path('app/Presenters/' . $presenter);
     $controller = base_path('app/Http/Controllers/' . $controller);
     $seed = base_path('database/seeds/' . $seed);
     $this->files->delete([$request, $model, $presenter, $controller, $seed]);
     $this->files->deleteDirectory($views);
     $this->info('Delete ' . $views);
     $this->info('Delete ' . $request);
     $this->info('Delete ' . $model);
     $this->info('Delete ' . $presenter);
     $this->info('Delete ' . $controller);
     $this->info('Delete ' . $seed);
     $this->info('Dont forget to delete migration file and route');
 }
 public function getFolder($formatFolder = true, $delete = false)
 {
     if (is_null($this->folder)) {
         $reflect = new ReflectionClass(get_class($this));
         $folder = str_replace("App\\Http\\Controllers\\", '', $reflect->getName());
         $folder = str_replace('Controller', '', $folder);
         $view = str_replace('Controller', '', $reflect->getShortName());
         $aux = "";
         $folder_array = explode("\\", $folder);
         foreach ($folder_array as $i => $section) {
             $aux .= lcfirst($section) . '.';
             if ($i == count($folder_array) - 1) {
                 if (!$delete) {
                     $aux .= lcfirst($view);
                 }
             }
         }
         $this->folder = $aux;
         $this->folderUrlFormat = camel_case(str_replace('.', '/', $aux));
     }
     if ($formatFolder) {
         return $this->folder;
     } else {
         return $this->folderUrlFormat;
     }
 }
示例#19
0
 /**
  * @param \Illuminate\Database\Query\Builder $query
  * @param array $sortParameters
  *
  * @return \Illuminate\Database\Query\Builder
  *
  * @throws ColumnSortableException
  */
 private function queryOrderBuilder($query, array $sortParameters)
 {
     $model = $this;
     list($column, $direction) = $this->parseSortParameters($sortParameters);
     if (is_null($column)) {
         return $query;
     }
     if (method_exists($this, camel_case($column) . 'Sortable')) {
         return call_user_func_array([$this, camel_case($column) . 'Sortable'], [$query, $direction]);
     }
     $explodeResult = SortableLink::explodeSortParameter($column);
     if (!empty($explodeResult)) {
         $relationName = $explodeResult[0];
         $column = $explodeResult[1];
         try {
             $relation = $query->getRelation($relationName);
             $query = $this->queryJoinBuilder($query, $relation);
         } catch (BadMethodCallException $e) {
             throw new ColumnSortableException($relationName, 1, $e);
         } catch (\Exception $e) {
             throw new ColumnSortableException($relationName, 2, $e);
         }
         $model = $relation->getRelated();
     }
     if (isset($model->sortableAs) && in_array($column, $model->sortableAs)) {
         $query = $query->orderBy($column, $direction);
     } elseif ($this->columnExists($model, $column)) {
         $column = $model->getTable() . '.' . $column;
         $query = $query->orderBy($column, $direction);
     }
     return $query;
 }
 /**
  * Build the model class with the given name.
  *
  * @param  string  $name
  * @return string
  */
 protected function buildClass($name)
 {
     $stub = $this->files->get($this->getStub());
     $tableName = strtolower($this->getNameInput());
     $className = 'Create' . ucwords(camel_case($tableName)) . 'Table';
     $schema = $this->option('schema');
     $fields = explode(',', $schema);
     $data = array();
     $x = 0;
     foreach ($fields as $field) {
         $array = explode(':', $field);
         $data[$x]['name'] = trim($array[0]);
         $data[$x]['type'] = trim($array[1]);
         $x++;
     }
     $schemaFields = '';
     foreach ($data as $item) {
         if ($item['type'] == 'string') {
             $schemaFields .= "\$table->string('" . $item['name'] . "');";
         } elseif ($item['type'] == 'text') {
             $schemaFields .= "\$table->text('" . $item['name'] . "');";
         } elseif ($item['type'] == 'integer') {
             $schemaFields .= "\$table->integer('" . $item['name'] . "');";
         } elseif ($item['type'] == 'date') {
             $schemaFields .= "\$table->date('" . $item['name'] . "');";
         } else {
             $schemaFields .= "\$table->string('" . $item['name'] . "');";
         }
     }
     $schemaUp = "\n        Schema::create('" . $tableName . "', function(Blueprint \$table)\n        {\n            \$table->increments('id');\n            " . $schemaFields . "\n            \$table->timestamps();\n        });\n        ";
     $schemaDown = "Schema::drop('" . $tableName . "');";
     return $this->replaceSchemaUp($stub, $schemaUp)->replaceSchemaDown($stub, $schemaDown)->replaceClass($stub, $className);
 }
示例#21
0
 /**
  * Return plugin functions.
  *
  * @return array An array of functions
  */
 public function getFunctions()
 {
     return [new Twig_SimpleFunction('request_*', function ($name) {
         $arguments = array_slice(func_get_args(), 1);
         return call_user_func_array([$this->request, camel_case($name)], $arguments);
     })];
 }
 /**
  * Handle the command.
  */
 public function handle()
 {
     $stream = $this->builder->getTableStream();
     if (!$stream instanceof StreamInterface) {
         return;
     }
     $eager = [];
     if ($stream->isTranslatable()) {
         $eager[] = 'translations';
     }
     $assignments = $stream->getRelationshipAssignments();
     foreach ($this->builder->getColumns() as $column) {
         /**
          * If the column value is a string and uses a dot
          * format then check if it's a relation.
          */
         if (isset($column['value']) && is_string($column['value']) && preg_match("/^entry.([a-zA-Z\\_]+)./", $column['value'], $match)) {
             if ($assignment = $assignments->findByFieldSlug($match[1])) {
                 if ($assignment->getFieldType()->getNamespace() == 'anomaly.field_type.polymorphic') {
                     continue;
                 }
                 $eager[] = camel_case($match[1]);
             }
         }
     }
     $this->builder->setTableOption('eager', array_unique($this->builder->getTableOption('eager', []) + $eager));
 }
示例#23
0
 public static function dispatch()
 {
     // Include the routes
     require CONFIG_PATH . 'routes.php';
     // Grab the controller/action stack for request
     $request = self::request();
     try {
         // Make an instance of the controller's class
         $class = new ReflectionClass(camel_case($request['controller']));
         $controller = $class->newInstance();
         // Try and include the global helper file
         require_if_exists(APPLICATION_PATH . 'helpers/global.php');
         // Require the helper files for the controller
         $helpers = explode('>', $request['controller']);
         $helper_string = '';
         foreach ($helpers as $helper) {
             $helper_string .= "/{$helper}";
             $helper_file = HELPERS_PATH . $helper_string . '.php';
             require_if_exists($helper_file);
         }
         // Execute the action
         $method = $class->getMethod($request['action']);
         $result = $method->invokeArgs($controller, $request['arguments']);
     } catch (ReflectionException $e) {
         // ob_end_clean();
         die('<pre>' . $e . '</pre>');
     }
 }
 /**
  * Fire a set of closures by trigger.
  *
  * @param        $trigger
  * @param  array $parameters
  * @return $this
  */
 public function fire($trigger, array $parameters = [])
 {
     /*
      * First, fire global listeners.
      */
     foreach (array_get(self::$listeners, $trigger, []) as $callback) {
         if (is_string($callback) || $callback instanceof \Closure) {
             app()->call($callback, $parameters);
         }
         if (method_exists($callback, 'handle')) {
             app()->call([$callback, 'handle'], $parameters);
         }
     }
     /*
      * Next, check if the method
      * exists and run it if it does.
      */
     $method = camel_case('on_' . $trigger);
     if (method_exists($this, $method)) {
         app()->call([$this, $method], $parameters);
     }
     /*
      * Finally, run through all of
      * the registered callbacks.
      */
     foreach (array_get($this->callbacks, $trigger, []) as $callback) {
         if (is_string($callback) || $callback instanceof \Closure) {
             app()->call($callback, $parameters);
         }
         if (method_exists($callback, 'handle')) {
             app()->call([$callback, 'handle'], $parameters);
         }
     }
     return $this;
 }
示例#25
0
 /**
  * Build a fixture record using the passed in values.
  *
  * @param  string $tableName
  * @param  array $records
  * @return array
  */
 public function buildRecords($tableName, array $records)
 {
     $insertedRecords = array();
     $this->tables[$tableName] = $tableName;
     foreach ($records as $recordName => $recordValues) {
         $model = $this->generateModelName($tableName);
         $record = new $model();
         foreach ($recordValues as $columnName => $columnValue) {
             $camelKey = camel_case($columnName);
             // If a column name exists as a method on the model, we will just assume
             // it is a relationship and we'll generate the primary key for it and store
             // it as a foreign key on the model.
             if (method_exists($record, $camelKey)) {
                 $this->insertRelatedRecords($recordName, $record, $camelKey, $columnValue);
                 continue;
             }
             $record->{$columnName} = $columnValue;
         }
         // Generate a hash for this record's primary key.  We'll simply hash the name of the
         // fixture into an integer value so that related fixtures don't have to rely on
         // an auto-incremented primary key when creating foreign keys.
         $primaryKeyName = $record->getKeyName();
         $record->{$primaryKeyName} = $this->generateKey($recordName);
         $record->save();
         $insertedRecords[$recordName] = $record;
     }
     return $insertedRecords;
 }
 public function fire()
 {
     $tableName = $this->argument('table');
     $modelName = '\\Jarboe\\Component\\Structure\\Model\\' . ucfirst(camel_case($tableName));
     $model = $this->ask('Model class with namespace to handle current table structure? [' . $modelName . ']');
     Schema::create($tableName, function (Blueprint $table) {
         $table->increments('id');
         $table->integer('parent_id')->nullable()->index();
         $table->integer('lft')->nullable()->index();
         $table->integer('rgt')->nullable()->index();
         $table->integer('depth')->nullable();
         $table->string('title', 255);
         $table->string('slug', 255);
         $table->string('template', 255);
         $table->tinyInteger('is_active');
         $table->string('seo_title', 255);
         $table->string('seo_description', 255);
         $table->string('seo_keywords', 255);
         $table->timestamps();
     });
     $tree = array(array('id' => 1, 'title' => 'Home', 'slug' => '/', 'template' => 'default mainpage template', 'is_active' => 1));
     $model::buildTree($tree);
     // HACK: for homepage / url
     DB::table($tableName)->where('id', 1)->update(['slug' => '/']);
     $this->info('Structure table [' . $tableName . '] successfuly created!');
 }
示例#27
0
 /**
  * Fetch the presenter method name for the given variable.
  *
  * @param  string $variable
  * @return string|null
  */
 protected function getPresenterMethodFromVariable($variable)
 {
     $method = camel_case($variable);
     if (method_exists($this, $method)) {
         return $method;
     }
 }
 public function convertToObject($value)
 {
     if ($value instanceof \Eloquent) {
         $attributes = $value->toArray();
         $relations = $value->relationsToArray();
         $object = new stdClass();
         foreach ($attributes as $key => $attribute) {
             if (array_key_exists($key, $relations)) {
                 $key = camel_case($key);
                 $object->{$key} = $this->convertToObject($value->{$key});
             } else {
                 $object->{$key} = $attribute;
             }
         }
         return $object;
     }
     if ($value instanceof \Illuminate\Database\Eloquent\Collection) {
         $array = array();
         foreach ($value as $key => $element) {
             $array[$key] = $this->convertToObject($element);
         }
         return $array;
     }
     return $value;
 }
示例#29
0
 /**
  * Creates a new Lavary\Menu\MenuItem instance.
  *
  * @param  string  $title
  * @param  string  $url
  * @param  array  $attributes
  * @param  int  $parent
  * @param  \Lavary\Menu\Menu  $builder
  * @return void
  */
 public function __construct($builder, $id, $title, $options)
 {
     $this->builder = $builder;
     $this->id = $id;
     $this->title = $title;
     $this->nickname = camel_case($title);
     $this->attributes = $this->builder->extractAttributes($options);
     $this->parent = is_array($options) && isset($options['parent']) ? $options['parent'] : null;
     // Storing path options with each link instance.
     if (!is_array($options)) {
         $path = array('url' => $options);
     } elseif (isset($options['raw']) && $options['raw'] == true) {
         $path = null;
     } else {
         $path = array_only($options, array('url', 'route', 'action', 'secure'));
     }
     if (!is_null($path)) {
         $path['prefix'] = $this->builder->getLastGroupPrefix();
     }
     $this->link = $path ? new Link($path) : null;
     // Activate the item if items's url matches the request uri
     if (true === $this->builder->conf('auto_activate')) {
         $this->checkActivationStatus();
     }
 }
示例#30
0
文件: index.php 项目: hunanhd/cbm
function build_tbl_relations(&$relations, $tbl_name, $fields)
{
    //去掉cbm前缀,作为文件名
    $fname = table_no_prefix($tbl_name);
    //得到类名
    $clsname = camel_case($fname);
    foreach ($fields as $name => $type) {
        $param_type = $type;
        $parent_tbl_name = table_no_id($name);
        $var_name = $name;
        $field_name = table_no_prefix($parent_tbl_name);
        if ($name == 'id') {
            continue;
        }
        //该字段是外键(所有的外键ID都是以_id结尾的)
        if ($field_name != $name && $name != 'id') {
            $param_type = camel_case($field_name);
            $var_name = $field_name;
            if (!isset($relations[$parent_tbl_name])) {
                $relations[$parent_tbl_name] = array();
            }
            var_dump($parent_tbl_name . "-->" . $tbl_name);
            $relations[$parent_tbl_name][] = $tbl_name;
        }
    }
    // var_dump($relations);
}