Esempio n. 1
0
 /**
  * main
  *
  */
 public function main()
 {
     $schemaPo = APP . 'Locale' . DS . 'schema.pot';
     $conn = ConnectionManager::get('default');
     $collection = $conn->schemaCollection();
     $translations = new Translations();
     $tables = $collection->listTables();
     foreach ($tables as $table) {
         $translations->insert($table, Inflector::humanize(Inflector::underscore($table)));
         $translations->insert($table, Inflector::humanize(Inflector::underscore(Inflector::singularize($table))));
         $columns = $collection->describe($table)->columns();
         foreach ($columns as $column) {
             $c = $collection->describe($table)->column($column);
             $comment = $c['comment'];
             $t = new Translation($table . '.' . $column, Inflector::humanize(Inflector::underscore($column)));
             $translations[] = $t;
             $t->setTranslation($comment);
             $t = new Translation($table . '.' . $column, Inflector::humanize(Inflector::underscore(Inflector::singularize($table))) . ' ' . Inflector::humanize(Inflector::underscore($column)));
             $translations[] = $t;
             $t->setTranslation($comment);
         }
     }
     $poString = $translations->toPoString();
     $caked = preg_replace('/msgctxt "([^"]+)"/i', '#: \\1', $poString);
     $this->createFile($schemaPo, $caked);
 }
Esempio n. 2
0
 private function parse($json)
 {
     if (is_array($json)) {
         foreach ($json as $item) {
             $this->parse($item);
         }
     } else {
         $json = (array) $json;
     }
     foreach ($json as $tablename => $data) {
         if (!is_array($data)) {
             $this->parse($data);
         } else {
             $table = Inflector::tableize($tablename);
             $table = $table == 'armours' ? 'armour' : $table;
             // Hack for non-standard table names
             $table = TableRegistry::get($table);
             foreach ($data as $record) {
                 $record = (array) $record;
                 $new = $table->import($record);
                 $result = ['table' => Inflector::humanize($tablename), 'record' => $new->import_name, 'status' => $new->import_action, 'errors' => $new->import_errors];
                 $this->results[] = $result;
             }
         }
     }
 }
 /**
  * Displays a view
  *
  * @param mixed What page to display
  * @return void
  * @throws Cake\Error\NotFoundException When the view file could not be found
  *	or Cake\View\Error\MissingViewException in debug mode.
  */
 public function display()
 {
     $path = func_get_args();
     $count = count($path);
     if (!$count) {
         return $this->redirect('/');
     }
     $page = $subpage = $titleForLayout = null;
     if (!empty($path[0])) {
         $page = $path[0];
     }
     if (!empty($path[1])) {
         $subpage = $path[1];
     }
     if (!empty($path[$count - 1])) {
         $titleForLayout = Inflector::humanize($path[$count - 1]);
     }
     $this->set(array('page' => $page, 'subpage' => $subpage, 'title_for_layout' => $titleForLayout));
     try {
         $this->render(implode('/', $path));
     } catch (MissingViewException $e) {
         if (Configure::read('debug')) {
             throw $e;
         }
         throw new Error\NotFoundException();
     }
 }
 /**
  * Returns a counter string for the paged result set
  *
  * ### Options
  *
  * - `model` The model to use, defaults to PaginatorHelper::defaultModel();
  * - `format` The format string you want to use, defaults to 'pages' Which generates output like '1 of 5'
  *    set to 'range' to generate output like '1 - 3 of 13'. Can also be set to a custom string, containing
  *    the following placeholders `{{page}}`, `{{pages}}`, `{{current}}`, `{{count}}`, `{{model}}`, `{{start}}`, `{{end}}` and any
  *    custom content you would like.
  *
  * @param string|array $options Options for the counter string. See #options for list of keys.
  *   If string it will be used as format.
  * @return string Counter string.
  * @link http://book.cakephp.org/3.0/en/views/helpers/paginator.html#creating-a-page-counter
  */
 public function counter($options = [])
 {
     if (is_string($options)) {
         $options = ['format' => $options];
     }
     $default = ['model' => $this->defaultModel(), 'format' => 'pages'];
     $options = \Cake\Utility\Hash::merge($default, $options);
     $paging = $this->params($options['model']);
     if (!$paging['pageCount']) {
         $paging['pageCount'] = 1;
     }
     $start = 0;
     if ($paging['count'] >= 1) {
         $start = ($paging['page'] - 1) * $paging['perPage'] + 1;
     }
     $end = $start + $paging['perPage'] - 1;
     if ($paging['count'] < $end) {
         $end = $paging['count'];
     }
     switch ($options['format']) {
         case 'range':
         case 'pages':
             $template = 'counter' . ucfirst($options['format']);
             break;
         default:
             $template = 'counterCustom';
             $this->templater()->add([$template => $options['format']]);
     }
     $map = array_map([$this->Number, 'format'], ['page' => $paging['page'], 'pages' => $paging['pageCount'], 'current' => $paging['current'], 'count' => $paging['count'], 'start' => $start, 'end' => $end]);
     $map += ['model' => strtolower(Inflector::humanize(Inflector::tableize($options['model'])))];
     return $this->templater()->format($template, $map);
 }
Esempio n. 5
0
 /**
  * Class Constructor
  *
  * Merges defaults with
  * - Configure::read(Meta)
  * - Helper options
  * - viewVars _meta
  * in that order (the latter trumps)
  *
  * @param array $options
  */
 public function __construct(View $View, $options = [])
 {
     parent::__construct($View, $options);
     $configureMeta = (array) Configure::read('Meta');
     if (Configure::read('Meta.robots') && is_array(Configure::read('Meta.robots'))) {
         $configureMeta['robots'] = Hash::merge($this->meta['robots'], Configure::read('Meta.robots'));
     }
     $this->meta = $configureMeta + $this->meta;
     if (!empty($options['robots']) && is_array($options['robots'])) {
         $options['robots'] = Hash::merge($this->meta['robots'], $options['robots']);
     }
     $this->meta = $options + $this->meta;
     if (!empty($this->_View->viewVars['_meta'])) {
         $viewVarsMeta = (array) $this->_View->viewVars['_meta'];
         if (!empty($viewVarsMeta['robots']) && is_array($viewVarsMeta['robots'])) {
             $viewVarsMeta['robots'] = Hash::merge($this->meta['robots'], $viewVarsMeta['robots']);
         }
         $this->meta = $viewVarsMeta + $this->meta;
     }
     if ($this->meta['charset'] === null) {
         // By default include this
         $this->meta['charset'] = true;
     }
     if ($this->meta['icon'] === null) {
         // By default include this
         $this->meta['icon'] = true;
     }
     if ($this->meta['title'] === null) {
         $this->meta['title'] = __(Inflector::humanize(Inflector::underscore($this->request->params['controller']))) . ' - ' . __(Inflector::humanize(Inflector::underscore($this->request->params['action'])));
     }
 }
Esempio n. 6
0
 public function renderLayout($content, $layout = null)
 {
     try {
         $layout = $this->_getLayoutFileName($layout);
     } catch (MissingLayoutException $e) {
         $this->_renderLayoutAs = 'string';
     }
     if (empty($layout)) {
         return $this->Blocks->get('content');
     }
     if (empty($content)) {
         $content = $this->Blocks->get('content');
     } else {
         $this->Blocks->set('content', $content);
     }
     $this->dispatchEvent('View.beforeLayout', [$layout]);
     $title = $this->Blocks->get('title');
     if ($title === '') {
         $title = Inflector::humanize($this->viewPath);
         $this->Blocks->set('title', $title);
     }
     $this->_currentType = static::TYPE_LAYOUT;
     $this->Blocks->set('content', $this->_render($layout));
     $this->dispatchEvent('View.afterLayout', [$layout]);
     return $this->Blocks->get('content');
 }
Esempio n. 7
0
 /**
  * [_deriveFields description]
  *
  * @return array
  */
 protected function _deriveFields()
 {
     $table = $this->_table();
     $request = $this->_request();
     if (!method_exists($table, 'searchConfiguration')) {
         return [];
     }
     $filters = $table->searchConfiguration();
     $currentModel = $table->alias();
     $schema = $table->schema();
     $fields = [];
     foreach ($filters->all() as $filter) {
         if ($filter->config('form') === false) {
             continue;
         }
         $searchParam = $filter->name();
         $field = $filter->field() ?: $searchParam;
         // Ignore multi-field filters for now
         if (is_array($field)) {
             continue;
         }
         $input = [];
         $filterFormConfig = $filter->config();
         if (!empty($filterFormConfig['form'])) {
             $input = $filterFormConfig['form'];
         }
         $input += ['label' => Inflector::humanize(preg_replace('/_id$/', '', $searchParam)), 'required' => false, 'type' => 'text'];
         $value = $request->query($searchParam);
         if ($value !== null) {
             $input['value'] = $value;
         }
         if (empty($input['options']) && $table->hasField($field)) {
             if ($schema->columnType($field) === 'boolean') {
                 $input['options'] = ['No', 'Yes'];
                 $input['type'] = 'select';
             }
         }
         if (!empty($input['options'])) {
             $input['empty'] = true;
             $fields[$searchParam] = $input;
             continue;
         }
         if (empty($input['class'])) {
             $input['class'] = 'autocomplete';
         }
         if (empty($input['type'])) {
             $input['type'] = 'text';
         }
         $urlArgs = [];
         $fieldKeys = isset($input['fields']) ? $input['fields'] : ['id' => $field, 'value' => $field];
         foreach ($fieldKeys as $key => $val) {
             $urlArgs[$key] = $val;
         }
         unset($input['fields']);
         $url = ['action' => 'lookup', '?' => $urlArgs, '_ext' => 'json'];
         $input['data-url'] = Router::url($url);
         $fields[$searchParam] = $input;
     }
     return $fields;
 }
 public function getActionName($controller, $id)
 {
     $this->autoRender = false;
     $indexed_tables = $this->_getIndexedTables();
     if (isset($indexed_tables[$controller][$id])) {
         echo $indexed_tables[$controller][$id] . ' (' . __(Inflector::humanize(Inflector::underscore($controller))) . ' / ' . $id . ')';
     }
 }
Esempio n. 9
0
 /**
  * Generates default input for parameter
  *
  * @param BaseParameter $param Form parameter.
  * @return array
  */
 protected function _defaultInput($param)
 {
     $input = $param->formInputConfig();
     $name = $param->config('name');
     $input += ['type' => 'text', 'required' => false, 'label' => Inflector::humanize(preg_replace('/_id$/', '', $name))];
     if (!$param->visible()) {
         $input['type'] = 'hidden';
     }
     return $input;
 }
Esempio n. 10
0
 public function beforeSave(Event $event, EntityInterface $entity, ArrayObject $options)
 {
     if (empty($entity->display)) {
         $entity->display = Inflector::humanize($entity->name);
     }
     if ($entity->dirty('is_default') && $entity->is_default) {
         $this->updateAll(['is_default' => false], ['is_default' => true]);
     } elseif ($entity->dirty('is_default') && !$entity->is_default) {
         $entity->is_default = $entity->getOriginal('is_default');
     }
 }
 /**
  * [_deriveFields description]
  *
  * @return array
  */
 protected function _deriveFields()
 {
     $table = $this->_table();
     $request = $this->_request();
     $filters = null;
     if (method_exists($table, 'searchConfiguration')) {
         $filters = $table->searchConfiguration();
     } else {
         $filters = $table->searchManager();
     }
     $fields = [];
     $schema = $table->schema();
     $config = $this->_config;
     foreach ($filters->all() as $filter) {
         if ($filter->config('form') === false) {
             continue;
         }
         $field = $filter->name();
         $input = [];
         $filterFormConfig = $filter->config();
         if (!empty($filterFormConfig['form'])) {
             $input = $filterFormConfig['form'];
         }
         $input += ['label' => Inflector::humanize(preg_replace('/_id$/', '', $field)), 'required' => false, 'type' => 'text'];
         $input['value'] = $request->query($field);
         if (empty($input['options']) && $schema->columnType($field) === 'boolean') {
             $input['options'] = ['No', 'Yes'];
             $input['type'] = 'select';
         }
         if (!empty($input['options'])) {
             $input['empty'] = true;
             if (empty($input['class']) && !$config['selectize']) {
                 $input['class'] = 'no-selectize';
             }
             $fields[$field] = $input;
             continue;
         }
         if (empty($input['class']) && $config['autocomplete']) {
             $input['class'] = 'autocomplete';
         }
         $urlArgs = [];
         $fieldKeys = isset($input['fields']) ? $input['fields'] : ['id' => $field, 'value' => $field];
         foreach ($fieldKeys as $key => $val) {
             $urlArgs[$key] = $val;
         }
         unset($input['fields']);
         $url = array_merge(['action' => 'lookup', '_ext' => 'json'], $urlArgs);
         $input['data-url'] = Router::url($url);
         $fields[$field] = $input;
     }
     return $fields;
 }
Esempio n. 12
0
 /**
  * Displays a help file formatted in markdown.
  * Original method from CakePHP's PagesController file.
  *
  * @param mixed What page to display
  * @return void
  * @throws NotFoundException When the view file could not be found
  * 	or MissingViewException in debug mode.
  */
 public function display()
 {
     $this->viewClass = 'Sb.Markdown';
     // Layout
     if (!Configure::read('Sb.Croogo')) {
         $this->layout = 'doc';
     } else {
         $this->layout = 'doc_croogo';
     }
     $path = func_get_args();
     $docs = null;
     if (!empty($this->request->params['named']['docs'])) {
         $docs = $this->request->params['named']['docs'];
     }
     $base = null;
     // If you want to add other pathes, don't forget to add a trailing '::'
     switch ($docs) {
         case 'template':
             $base = Plugin::path('Sb') . 'template/docs::';
             break;
         default:
             $base = Plugin::path('Sb') . 'docs::';
             break;
     }
     $count = count($path);
     if (!$count) {
         return $this->redirect('/');
     }
     $page = $subpage = $title_for_layout = null;
     if (!empty($path[0])) {
         $page = $path[0];
     }
     if (!empty($path[1])) {
         $subpage = $path[1];
     }
     if (!empty($path[$count - 1])) {
         $title_for_layout = Inflector::humanize($path[$count - 1]);
     }
     $this->set(compact('page', 'subpage', 'title_for_layout'));
     try {
         $this->render($base . implode('/', $path), null);
     } catch (MissingViewException $e) {
         if (Configure::read('debug')) {
             throw $e;
         }
         throw new NotFoundException();
     }
 }
Esempio n. 13
0
 /**
  * 
  */
 public function initialize()
 {
     parent::initialize();
     /**
      * Use Builder Helpers
      */
     $this->loadHelper('Flash', ['className' => 'Builder.Flash']);
     /**
      * Set default layout for App using Layout/builder
      */
     if ($this->layout === 'default') {
         $this->layout('builder/default');
     }
     /**
      *  Set form templates
      */
     $_templates = ['dateWidget' => '<ul class="list-inline"><li class="year">{{year}}</li><li class="month">{{month}}</li><li class="day">{{day}}</li><li class="hour">{{hour}}</li><li class="minute">{{minute}}</li><li class="second">{{second}}</li><li class="meridian">{{meridian}}</li></ul>', 'error' => '<div class="help-block">{{content}}</div>', 'help' => '<div class="help-block">{{content}}</div>', 'inputContainer' => '<div class="form-group {{type}}{{required}}">{{content}}{{help}}</div>', 'inputContainerError' => '<div class="form-group {{type}}{{required}} has-error">{{content}}{{error}}{{help}}</div>', 'checkboxWrapper' => '<div class="checkbox"><label>{{input}}{{label}}</label></div>', 'multipleCheckboxWrapper' => '<div class="checkbox">{{label}}</div>', 'radioInlineFormGroup' => '{{label}}<div class="radio-inline-wrapper">{{input}}</div>', 'radioNestingLabel' => '<div class="radio">{{hidden}}<label{{attrs}}>{{input}}{{text}}</label></div>', 'staticControl' => '<p class="form-control-static">{{content}}</p>', 'inputGroupAddon' => '<span class="{{class}}">{{content}}</span>', 'inputGroupContainer' => '<div class="input-group">{{prepend}}{{content}}{{append}}</div>', 'input' => '<input class="form-control" type="{{type}}" name="{{name}}"{{attrs}}/>', 'textarea' => '<textarea class="form-control" name="{{name}}"{{attrs}}>{{value}}</textarea>', 'select' => '<select class="form-control" name="{{name}}"{{attrs}}>{{content}}</select>', 'selectMultiple' => '<select class="form-control" name="{{name}}[]" multiple="multiple"{{attrs}}>{{content}}</select>'];
     /**
      * 
      */
     $this->Form->templates($_templates);
     /**
      * Loader base styles using bower_components and default Builder settings
      */
     $this->start('builder-css');
     echo $this->Html->css(['/bower_components/jquery-ui/themes/smoothness/jquery-ui.min.css', '/bower_components/bootstrap/dist/css/bootstrap.min.css', '/bower_components/fontawesome/css/font-awesome.min.css', '/bower_components/datatables/media/css/dataTables.bootstrap.min.css', '/bower_components/summernote/dist/summernote.css', '/css/builder/base.css']);
     $this->end();
     /**
      * Laoder base scripts using bower_components and default Builder settings
      */
     $this->start('builder-script');
     echo $this->Html->script(['/bower_components/jquery/dist/jquery.min.js', '/bower_components/jquery-ui/jquery-ui.min.js', '/bower_components/bootstrap/dist/js/bootstrap.min.js', '/bower_components/datatables/media/js/jquery.dataTables.min.js', '/bower_components/datatables/media/js/dataTables.bootstrap.js', '/bower_components/summernote/dist/summernote.min.js', '/js/builder/base.js']);
     $this->end();
     /**
      * Load Builder default constructor element form Builder/Element/constructor
      */
     $this->prepend('builder-element', $this->element('Builder.constructor/default'));
     /**
      * If empty 'nav' block, set default navbar using Builder/Element/builder
      */
     if (!$this->fetch('nav')) {
         $this->assign('nav', $this->element('Builder.builder/navbar-fixed-top'));
     }
     /**
      * Set default title for layout using controller name
      */
     $this->assign('title', Inflector::humanize(Inflector::tableize($this->request->controller)));
 }
 /**
  * Method that converts Controller
  * full name to human readable label
  * @param  string $name Controller full name
  * @return void
  */
 public function groupName($name)
 {
     $parts = array_map(function ($n) {
         return Inflector::humanize(Inflector::underscore(str_replace('Controller', '', $n)));
     }, explode('\\', $name));
     /*
             removes empty array entries
     */
     $parts = array_filter($parts);
     /*
             get just the controller and plugin names
     */
     $parts = array_slice($parts, -2);
     $name = implode(' :: ', $parts);
     $this->set('groupName', $name);
 }
 /**
  * Format nested list element
  * 
  * Callback method used by The NestableHelper
  *
  * @param array $data NestableHelper configuration
  * @param \Cake\ORM\Entity $entity Entity to format
  */
 public function nestedListFormat(array $data, Entity $entity)
 {
     $displayField = TableRegistry::get($entity->source())->displayField();
     $html = '<span class="pull-right p10 pb5">';
     $html .= $this->Html->link('<i class="fa fa-edit"></i> ', ['action' => 'edit', $entity->id], ['class' => '', 'escape' => false, 'title' => __d('admin', 'Edit')]);
     $html .= $this->Form->postLink('<i class="fa fa-trash-o"></i>', ['action' => 'delete', $entity['id']], ['class' => '', 'title' => __d('admin', 'Delete {0}', Inflector::humanize($entity->source)), 'escape' => false, 'confirm' => __d('admin', 'Are you sure you want to delete #{0} {1}?', $entity->id, $entity->{$displayField})]);
     $html .= '</span>';
     $html .= '<div class="dd-handle" data-id="' . $entity->id . '">';
     if ($entity->active === false) {
         $html .= '<span class="text-muted">' . $entity->{$displayField} . '</span>';
         $html .= ' <span class="text-danger"><i class="fa fa-ban"></i><em class="sr-only">Non active</em></span>';
     } else {
         $html .= $entity->{$displayField};
     }
     $html .= '</div>';
     return $html;
 }
 public function display()
 {
     $path = func_get_args();
     $url = implode('/', $path);
     $count = count($path);
     if (!$count) {
         return $this->redirect('/');
     }
     $page = $subpage = $title_for_layout = null;
     if (!empty($path[0])) {
         $page = $path[0];
         if (in_array($page, ['challenges'])) {
             $landingpage = new LandingPageForm();
             $submitted = false;
             if ($this->request->is('post')) {
                 if ($landingpage->execute($this->request->data)) {
                     // store to db
                     $this->loadModel('LandingPagesFormdata');
                     $landingpageformdata = $this->LandingPagesFormdata;
                     $data = $landingpageformdata->newEntity(['url' => $url, 'serialized_data' => serialize($this->request->data)]);
                     $landingpageformdata->save($data);
                     // show thank you
                     $submitted = true;
                 } else {
                     $this->Flash->error('There was a problem submitting your form. Please ensure you have included your name and a valid email address.');
                 }
             }
             $this->set(compact('landingpage', 'submitted'));
         }
     }
     if (!empty($path[1])) {
         $subpage = $path[1];
     }
     if (!empty($path[$count - 1])) {
         $title_for_layout = Inflector::humanize($path[$count - 1]);
     }
     $this->set(compact('page', 'subpage', 'title_for_layout', 'url'));
     try {
         $this->render(implode('/', $path));
     } catch (Error\MissingViewException $e) {
         if (Configure::read('debug')) {
             throw $e;
         }
         throw new Error\NotFoundException();
     }
 }
 public function getChartArray($arrayName, $columns, $relatedEntries)
 {
     $html = "var {$arrayName} = [], chart = {};";
     foreach ($columns as $column) {
         $column = htmlspecialchars($column);
         $html .= "chart = {};";
         $html .= "chart.name = '{$column}';";
         $html .= "chart.title = '" . Inflector::humanize($column) . "';";
         $html .= "chart.labels = []; chart.values = [];";
         foreach ($relatedEntries[$column] as $entry) {
             $count = $entry['count'];
             $html .= "chart.labels.push('{$entry[$column]} ({$count})');";
             $html .= "chart.values.push({$count});";
         }
         $html .= "{$arrayName}.push(chart);";
     }
     return $html;
 }
Esempio n. 18
0
 /**
  * Generate inputs in all locales.
  *
  * @param \Cake\ORM\Entity $entity The entity that was fired.
  * @param string $field The field to process.
  * @param array $options The options to pass to the input.
  * @param string $divClass The class to set to the div before the input.
  * @param string $id The id of the input.
  *
  * @return string
  */
 public function i18nInput(Entity $entity, $field, $options = [], $divClass = 'col-sm-5', $id = 'CkEditorBox')
 {
     $html = '';
     $CkEditor = isset($options['CkEditor']) ? $options['CkEditor'] : false;
     $i = 0;
     foreach ($this->_locales as $locale => $lang) {
         if ($locale == Configure::read('I18n.locale')) {
             continue;
         }
         $i++;
         $translationOption = $options;
         $translationOption['label'] = Inflector::humanize($lang);
         $translationOption['value'] = $entity->translation($locale)->{$field};
         if (isset($options['CkEditor']) && $options['CkEditor'] == true) {
             $translationOption['id'] = $id . '-' . $i;
         }
         $html .= '<div class="form-group">';
         $html .= '<div class="col-sm-offset-2 ' . $divClass . '">';
         $html .= $this->Form->input('translations.' . $locale . '.' . $field, $translationOption);
         $html .= '</div></div>';
     }
     return $html;
 }
Esempio n. 19
0
 /**
  * Default cell method.
  *
  * @param array $tables Tables list.
  * @param array $blacklist Blacklisted tables list.
  * @return array
  */
 public function display($tables = null, $blacklist = null)
 {
     if (empty($tables)) {
         $connection = ConnectionManager::get('default');
         $schema = $connection->schemaCollection();
         $tables = $schema->listTables();
         ksort($tables);
         if (!empty($blacklist)) {
             $tables = array_diff($tables, $blacklist);
         }
     }
     $normal = [];
     foreach ($tables as $table => $config) {
         if (is_string($config)) {
             $config = ['table' => $config];
         }
         if (is_int($table)) {
             $table = $config['table'];
         }
         $config += ['action' => 'index', 'title' => Inflector::humanize($table), 'controller' => Inflector::camelize($table)];
         $normal[$table] = $config;
     }
     return $this->set('tables', $normal);
 }
Esempio n. 20
0
 /**
  * Renders a layout. Returns output from _render(). Returns false on error.
  * Several variables are created for use in layout.
  *
  * @param string $content Content to render in a template, wrapped by the surrounding layout.
  * @param string|null $layout Layout name
  * @return mixed Rendered output, or false on error
  * @throws \Cake\Core\Exception\Exception if there is an error in the view.
  * @triggers View.beforeLayout $this, [$layoutFileName]
  * @triggers View.afterLayout $this, [$layoutFileName]
  */
 public function renderLayout($content, $layout = null)
 {
     $layoutFileName = $this->_getLayoutFileName($layout);
     if (empty($layoutFileName)) {
         return $this->Blocks->get('content');
     }
     if (!empty($content)) {
         $this->Blocks->set('content', $content);
     }
     $this->dispatchEvent('View.beforeLayout', [$layoutFileName]);
     $title = $this->Blocks->get('title');
     if ($title === '') {
         $title = Inflector::humanize($this->templatePath);
         $this->Blocks->set('title', $title);
     }
     $this->_currentType = static::TYPE_LAYOUT;
     $this->Blocks->set('content', $this->_render($layoutFileName));
     $this->dispatchEvent('View.afterLayout', [$layoutFileName]);
     return $this->Blocks->get('content');
 }
Esempio n. 21
0
 /**
  * Returns groupings of action types on the scaffolded view
  *
  * @return array
  */
 protected function _getControllerActions()
 {
     $table = $entity = [];
     $actions = $this->_getAllowedActions();
     foreach ($actions as $actionName) {
         $action = $this->_action($actionName);
         $method = 'GET';
         $class = get_class($action);
         $class = substr($class, strrpos($class, '\\') + 1);
         $scope = $action->scope();
         if ($class === 'DeleteAction') {
             $method = 'DELETE';
         }
         if ($class === 'AddAction') {
             $scope = 'table';
         }
         if ($scope === 'table') {
             $table[$actionName] = ['title' => Inflector::humanize($actionName), 'url' => ['action' => $actionName], 'method' => $method];
         } elseif ($scope === 'entity') {
             $entity[$actionName] = ['title' => Inflector::humanize($actionName), 'url' => ['action' => $actionName], 'method' => $method];
         }
     }
     return compact('table', 'entity');
 }
Esempio n. 22
0
 /**
  * Derive resource name
  *
  * @return string
  */
 protected function _deriveResourceName()
 {
     $inflectionType = $this->config('inflection');
     if ($inflectionType === null) {
         $inflectionType = $this->scope() === 'entity' ? 'singular' : 'plural';
     }
     if ($inflectionType === 'singular') {
         return strtolower(Inflector::humanize(Inflector::singularize(Inflector::underscore($this->_table()->alias()))));
     }
     return strtolower(Inflector::humanize(Inflector::underscore($this->_table()->alias())));
 }
Esempio n. 23
0
 /**
  * Creates the plural human name used in views
  *
  * @param string $name Controller name
  * @return string Plural human name
  */
 protected function _pluralHumanName($name)
 {
     return Inflector::humanize(Inflector::underscore($name));
 }
Esempio n. 24
0
 /**
  * Get the title for the panel.
  *
  * @return string
  */
 public function title()
 {
     list($ns, $name) = namespaceSplit(get_class($this));
     $name = substr($name, 0, strlen('Panel') * -1);
     return Inflector::humanize(Inflector::underscore($name));
 }
Esempio n. 25
0
    ?>
') CakePHPBakeCloseTag></h4>
    <CakePHPBakeOpenTagphp if (!empty($<?php 
    echo $singularVar;
    ?>
-><?php 
    echo $details['property'];
    ?>
)): CakePHPBakeCloseTag>
    <table cellpadding="0" cellspacing="0">
        <tr>
<?php 
    foreach ($details['fields'] as $field) {
        ?>
            <th><CakePHPBakeOpenTag= __('<?php 
        echo Inflector::humanize($field);
        ?>
') CakePHPBakeCloseTag></th>
<?php 
    }
    ?>
            <th class="actions"><CakePHPBakeOpenTag= __('Actions') CakePHPBakeCloseTag></th>
        </tr>
        <CakePHPBakeOpenTagphp foreach ($<?php 
    echo $singularVar;
    ?>
-><?php 
    echo $details['property'];
    ?>
 as $<?php 
    echo $otherSingularVar;
    public function input($fieldName, array $options = [])
    {
        $options += ['type' => null, 'label' => null, 'error' => null, 'required' => null, 'options' => null, 'templates' => []];
        $options = $this->_parseOptions($fieldName, $options);
        $options += ['id' => $this->_domId($fieldName)];
        $finalClasses = 'form-control';
        switch ($options['type']) {
            case 'checkbox':
                $finalClasses = '';
                $options['templates']['checkboxWrapper'] = '<div class="checkbox"><label>{{input}}{{label}}</label></div>';
                $options['templates']['label'] = '{{text}}';
                break;
            case 'radio':
                $options['templates']['radioWrapper'] = '<div class="radio"><label>{{input}}{{label}}</label></div>';
                $options['templates']['label'] = '{{text}}';
                break;
            case 'file':
                $options['templates']['inputContainer'] = '<div class="form-group {{type}}{{required}}">{{content}}</div>';
                $options['templates']['label'] = '<label>{{input}}{{text}}</label>';
                if (!empty($options['value'])) {
                    $label = $options['label'] ? $options['label'] : Inflector::humanize($fieldName);
                    $function_name = "enable_{$fieldName}()";
                    $options['templates']['inputContainer'] = '<div class="form-group {{type}}{{required}}">
                      {{content}}
                      <div>
                        <small>
                            <label>
                            <input type="checkbox" onclick="' . $function_name . '" />
                            ' . __("Click here to change the file.") . '
                            </label>
                        </small>

                        <script type="text/javascript">
                            function ' . $function_name . ' {
                                if (document.getElementById("' . $fieldName . '").disabled) {
                                    document.getElementById("' . $fieldName . '").disabled = false;
                                } else {
                                    document.getElementById("' . $fieldName . '").disabled = true;
                                }
                            }
                        </script>
                      </div>
                    </div>';
                    $options['disabled'] = true;
                }
                break;
            case 'password':
                $options['templates']['inputContainer'] = '<div class="form-group {{type}}{{required}}">{{content}}</div>';
                $options['templates']['label'] = '<label>{{input}}{{text}}</label>';
                if (!empty($options['value'])) {
                    $label = $options['label'] ? $options['label'] : Inflector::humanize($fieldName);
                    $function_name = "enable_{$fieldName}()";
                    $options['templates']['inputContainer'] = '<div class="form-group {{type}}{{required}}">
                      {{content}}
                      <div>
                        <small>
                            <label>
                            <input type="checkbox" onclick="' . $function_name . '" />
                            ' . __("Click here to change the file.") . '
                            </label>
                        </small>

                        <script type="text/javascript">
                            function ' . $function_name . ' {
                                if (document.getElementById("' . $fieldName . '").disabled) {
                                    document.getElementById("' . $fieldName . '").disabled = false;
                                } else {
                                    document.getElementById("' . $fieldName . '").disabled = true;
                                }
                            }
                        </script>
                      </div>
                    </div>';
                    $options['disabled'] = true;
                    $options['value'] = '';
                }
                break;
            default:
        }
        return parent::input($fieldName, $this->_injectStyles($options, $finalClasses));
    }
Esempio n. 27
0
 /**
  * Returns groupings of action types on the scaffolded view
  *
  * @return array
  */
 protected function _getControllerActions()
 {
     $table = $entity = [];
     $actions = $this->_getAllowedActions();
     foreach ($actions as $actionName => $config) {
         if ($this->_crud()->isActionMapped($actionName)) {
             $action = $this->_action($actionName);
             $class = get_class($action);
             $class = substr($class, strrpos($class, '\\') + 1);
             $config['scope'] = $action->scope();
             if ($class === 'DeleteAction') {
                 $config['method'] = 'DELETE';
             }
             if ($class === 'AddAction') {
                 $config['scope'] = 'table';
             }
         }
         // apply defaults if necessary
         $scope = isset($config['scope']) ? $config['scope'] : 'entity';
         $method = isset($config['method']) ? $config['method'] : 'GET';
         ${$scope}[$actionName] = ['title' => Inflector::humanize(Inflector::underscore($actionName)), 'url' => ['action' => $actionName], 'method' => $method, 'options' => array_diff_key($config, array_flip(['method', 'scope', 'className']))];
     }
     return compact('table', 'entity');
 }
Esempio n. 28
0
 /**
  * Process action.
  *
  * @param Table $table
  * @param $action
  * @param array $ids
  * @param array $options
  * @return \Cake\Network\Response|void
  */
 public function process(Table $table, $action, array $ids = [], array $options = [])
 {
     $idsCount = count($ids);
     $options = Hash::merge($this->_config, $options);
     $_options = ['messages' => $this->__setupMessages($idsCount)];
     $options = Hash::merge($_options, $options);
     $redirect = $options['redirect'];
     $messages = $options['messages'];
     if (!$action) {
         $this->Flash->error($messages['noAction']);
         return $this->_controller->redirect($redirect);
     }
     if ($idsCount == 0) {
         $this->Flash->error($messages['noChose']);
         return $this->_controller->redirect($redirect);
     }
     $behaviors = $table->behaviors();
     if (!in_array('BulkProcess', $behaviors->loaded())) {
         $behaviors->load('Union/Core.BulkProcess');
     }
     $event = Event::dispatch($this->_getEventName($action, 'bulkBefore'), $this->_controller, ['ids' => $ids]);
     if (is_array($event->result)) {
         $ids = $event->result;
         if (count($ids) == 0) {
             $this->Flash->error($messages['noChose']);
             return $this->_controller->redirect($redirect);
         }
         $messages = $this->__setupMessages(count($ids));
     }
     $process = $table->processAction($action, $ids);
     if ($process) {
         if (!empty($messages[$action])) {
             $message = $messages[$action];
         } else {
             $message = __d('union', '{0} processed', Inflector::humanize($this->_controller->name));
         }
         Event::dispatch($this->_getEventName($action), $this->_controller, ['ids' => $ids]);
         $this->Flash->success($message);
         return $this->_controller->redirect($redirect);
     }
     $this->Flash->error(__d('union', 'An error occurred'));
     return $this->_controller->redirect($redirect);
 }
Esempio n. 29
0
 /**
  * Wrap a set of inputs in a fieldset
  *
  * @param string $fields the form inputs to wrap in a fieldset
  * @param array $options Options array. Valid keys are:
  * - `fieldset` Set to false to disable the fieldset. You can also pass an array of params to be
  *    applied as HTML attributes to the fieldset tag. If you pass an empty array, the fieldset will
  *    be enabled
  * - `legend` Set to false to disable the legend for the generated input set. Or supply a string
  *    to customize the legend text.
  * @return string Completed form inputs.
  */
 public function fieldset($fields = '', array $options = [])
 {
     $fieldset = $legend = true;
     $context = $this->_getContext();
     $out = $fields;
     if (isset($options['legend'])) {
         $legend = $options['legend'];
     }
     if (isset($options['fieldset'])) {
         $fieldset = $options['fieldset'];
     }
     if ($legend === true) {
         $actionName = __d('cake', 'New %s');
         $isCreate = $context->isCreate();
         if (!$isCreate) {
             $actionName = __d('cake', 'Edit %s');
         }
         $modelName = Inflector::humanize(Inflector::singularize($this->request->params['controller']));
         $legend = sprintf($actionName, $modelName);
     }
     if ($fieldset !== false) {
         if ($legend) {
             $out = $this->formatTemplate('legend', ['text' => $legend]) . $out;
         }
         $fieldsetParams = ['content' => $out, 'attrs' => ''];
         if (is_array($fieldset) && !empty($fieldset)) {
             $fieldsetParams['attrs'] = $this->templater()->formatAttributes($fieldset);
         }
         $out = $this->formatTemplate('fieldset', $fieldsetParams);
     }
     return $out;
 }
 /**
  * Delete method
  *
  * @param string|null $id entity id.
  * @return Response Redirects to index.
  * @throws NotFoundException When record not found.
  */
 public function delete($id = null)
 {
     $table = $this->loadModel();
     $tableAlias = $table->alias();
     $entity = $table->get($id, ['contain' => []]);
     $singular = Inflector::singularize(Inflector::humanize($tableAlias));
     if ($table->delete($entity)) {
         $this->Flash->success(__('The {0} has been deleted', $singular));
     } else {
         $this->Flash->error(__('The {0} could not be deleted', $singular));
     }
     return $this->redirect($this->referer());
 }