示例#1
0
 /**
  * Tokenize
  * 
  * @param string $action reset|confirm
  * @param string $field password|email
  * @param array $data CakeRequest::data
  * 
  * @return array $user User::find
  */
 public function tokenize(Model $Model, $action, $field, $data = array())
 {
     if (empty($field) || empty($action) || !in_array($field, array('password', 'email')) || !in_array($action, array('reset', 'confirm'))) {
         throw new InvalidArgumentException('Invalid agruments');
     }
     return $this->dispatchMethod('_' . Inflector::variable(sprintf('tokenize_%s_%s', $action, $field)), array($Model, $data));
 }
示例#2
0
 /**
  * Cette fonction permet l'initialisation de la variable de session
  *
  * @access	static
  * @author	koéZionCMS
  * @version 0.1 - 20/04/2012
  * @version 0.2 - 31/07/2012 - Suppression de la récupération des données de la variable de session par un fichier
  * @version 0.3 - 09/11/2012 - Rajout du test pour savoir si les classes Inflector et Set sont chargées
  */
 static function init()
 {
     if (!class_exists('Inflector')) {
         require_once CAKEPHP . DS . 'inflector.php';
     }
     if (!class_exists('Set')) {
         require_once CAKEPHP . DS . 'set.php';
     }
     $sessionName = Inflector::variable(Inflector::slug('koeZion ' . $_SERVER['HTTP_HOST']));
     //Récupération du nom de la variable de session
     //Récupération des configuration du coeur de l'application pour détermine le mode de stockage des variables de sessions
     //Soit on utilise le comportement natif de PHP
     //Soit on stocke les sessions en local dans le dossier TMP
     require_once LIBS . DS . 'config_magik.php';
     $cfg = new ConfigMagik(CONFIGS . DS . 'files' . DS . 'core.ini', true, false);
     $coreConfs = $cfg->keys_values();
     if (isset($coreConfs['local_storage_session']) && $coreConfs['local_storage_session']) {
         ini_set('session.save_path', TMP . DS . 'sessions');
     }
     ini_set('session.use_trans_sid', 0);
     //Evite de passe l'id de la session dans l'url
     session_name($sessionName);
     //On affecte le nom
     session_start();
     //On démarre la session
 }
 function load($admin, $useDbAssociations = false)
 {
     // Load an instance of the admin model object
     $plugin = Inflector::camelize($admin->plugin);
     $modelObj = ClassRegistry::init(array('class' => "{$plugin}.{$admin->modelName}Admin", 'table' => $admin->useTable, 'ds' => $admin->useDbConfig));
     $adminModelObj = ClassRegistry::init(array('class' => "{$plugin}.{$admin->modelName}Admin", 'table' => $admin->useTable, 'ds' => $admin->useDbConfig));
     $modelClass = $admin->modelName . 'Admin';
     $primaryKey = $adminModelObj->primaryKey;
     $displayField = $adminModelObj->displayField;
     $schema = $adminModelObj->schema(true);
     $fields = array_keys($schema);
     $controllerName = $this->_controllerName($admin->modelName);
     $controllerRoute = $this->_pluralName($admin->modelName);
     $pluginControllerName = $this->_controllerName($admin->modelName . 'Admin');
     $singularVar = Inflector::variable($modelClass);
     $singularName = $this->_singularName($modelClass);
     $singularHumanName = $this->_singularHumanName($this->_controllerName($admin->modelName));
     $pluralVar = Inflector::variable($pluginControllerName);
     $pluralName = $this->_pluralName($modelClass);
     $pluralHumanName = Inflector::humanize($this->_pluralName($controllerName));
     if ($useDbAssociations) {
         $associations = $this->loadAssociations($modelObj, $admin);
     } else {
         $associations = $this->__associations($adminModelObj);
     }
     return compact('admin', 'modelObj', 'adminModelObj', 'modelClass', 'primaryKey', 'displayField', 'schema', 'fields', 'controllerName', 'controllerRoute', 'pluginControllerName', 'singularVar', 'singularName', 'singularHumanName', 'pluralVar', 'pluralName', 'pluralHumanName', 'associations');
 }
 /**
  * Outputs room roles radio
  *
  * @param string $fieldName Name attribute of the RADIO
  * @param array $attributes The HTML attributes of the select element.
  * @return string Formatted RADIO element
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#options-for-select-checkbox-and-radio-inputs
  */
 public function checkboxBlockRolePermission($fieldName, $attributes = array('inline' => true))
 {
     list($model, $permission) = explode('.', $fieldName);
     $html = '';
     if (!isset($this->_View->request->data[$model][$permission])) {
         return $html;
     }
     $html .= '<div class="form-inline">';
     foreach ($this->_View->request->data[$model][$permission] as $roleKey => $role) {
         if (!$role['value'] && $role['fixed']) {
             continue;
         }
         $html .= '<span class="checkbox-separator"></span>';
         $html .= '<div class="form-group">';
         if (!$role['fixed']) {
             $html .= $this->Form->hidden($fieldName . '.' . $roleKey . '.id');
             $html .= $this->Form->hidden($fieldName . '.' . $roleKey . '.roles_room_id');
             $html .= $this->Form->hidden($fieldName . '.' . $roleKey . '.block_key');
             $html .= $this->Form->hidden($fieldName . '.' . $roleKey . '.permission');
         }
         $options = Hash::merge(array('div' => false, 'disabled' => (bool) $role['fixed']), $attributes);
         if (!$options['disabled']) {
             $options['ng-click'] = 'clickRole($event, \'' . $permission . '\', \'' . Inflector::variable($roleKey) . '\')';
         }
         $html .= $this->Form->checkbox($fieldName . '.' . $roleKey . '.value', $options);
         $html .= $this->Form->label($fieldName . '.' . $roleKey . '.value', h($this->_View->viewVars['roles'][$roleKey]['name']));
         $html .= '</div>';
     }
     $html .= '</div>';
     return $html;
 }
示例#5
0
 function defID()
 {
     if (!empty($this->params['id'])) {
         return $options['id'] = $this->params['id'];
     } else {
         if (!empty($this->params['named']['id'])) {
             return $options['id'] = $this->params['named']['id'];
         } else {
             if (!empty($this->params['pass'][0]) && is_numeric($this->params['pass'][0])) {
                 return $options['id'] = $this->params['pass'][0];
             }
         }
     }
     $model = $this->defModel();
     if ($model) {
         if (!empty($this->data[$model]['id'])) {
             return $this->data[$model]['id'];
         }
         $view =& ClassRegistry::getObject('view');
         if (!empty($view->viewVars[Inflector::variable($model)][$model]['id'])) {
             return $view->viewVars[Inflector::variable($model)][$model]['id'];
         }
     }
     return null;
 }
示例#6
0
 /**
  * implementedEvents
  * 
  * @return array
  */
 public function implementedEvents()
 {
     $events = array();
     if ($this->events) {
         foreach ($this->events as $key => $registerEvent) {
             $options = array();
             if (is_array($registerEvent)) {
                 $options = $registerEvent;
                 $registerEvent = $key;
             }
             $eventName = $this->layer . '.' . $registerEvent;
             if (strpos($registerEvent, '.') !== false) {
                 $aryRegisterEvent = explode('.', $registerEvent);
                 $registerEvent = Inflector::variable(implode('_', $aryRegisterEvent));
             }
             if ($options) {
                 $options = array_merge(array('callable' => $registerEvent), $options);
             } else {
                 $options = array('callable' => $registerEvent);
             }
             $events[$eventName] = $options;
         }
     }
     return $events;
 }
示例#7
0
 /**
  * Change the name of the view variable name
  * of the data when its sent to the view
  *
  * @param mixed $name
  * @return mixed
  */
 public function viewVar($name = null)
 {
     if (empty($name)) {
         return $this->config('viewVar') ?: Inflector::variable($this->_model()->name);
     }
     return $this->config('viewVar', $name);
 }
示例#8
0
 public function convert($from, $to, $data, $options = array())
 {
     $function1 = Inflector::variable("{$from}_to_array");
     $function2 = Inflector::variable("array_to_{$to}");
     if (method_exists($this, $function1) && method_exists($this, $function2)) {
         return $this->{$function2}($this->{$function1}($data, $options), $options);
     }
 }
示例#9
0
 /**
  * @param AppModel $model
  * @param array $config Defaults:
  *        'collection' => 'global',
  *        'name' => "Mirrored.variableStyleModelName",
  *        'findType' => 'all' or 'threaded',
  *        'findOptions' => array('recursive' => -1),
  */
 public function setup($model, $config = array())
 {
     $config = (array) $config;
     $config += array('collection' => 'global', 'name' => "Mirror." . Inflector::variable($model->alias), 'findType' => $model->Behaviors->enabled('Tree') ? 'threaded' : 'all', 'findOptions' => array(), 'collectionField' => null, 'groupField' => null, 'indexField' => null, 'valueField' => null, 'valueFields' => array(), 'autoRefresh' => true);
     $config['findOptions'] += array('recursive' => -1);
     $config += array('noModelName' => $config['findOptions']['recursive'] == -1);
     $this->_pending[$model->alias] = $config['autoRefresh'] ? 0 : 100000;
     $this->settings[$model->alias] = $config;
 }
 public function getPrototypes()
 {
     $searchdirs['App'] = APP . 'View';
     $searchdirs['Basic'] = CakePlugin::path('Muffin');
     foreach (CakePlugin::loaded() as $plugin) {
         if ($plugin != 'Muffin') {
             $searchdirs[$plugin] = CakePlugin::path($plugin) . 'View';
         }
     }
     $configs = array();
     foreach ($searchdirs as $plugin => $searchdir) {
         $dir = new Folder($searchdir, false);
         if ($files = $dir->findRecursive('config.xml')) {
             $configs = Hash::merge($configs, array($plugin => $files));
         }
     }
     $prototypes = array();
     foreach ($configs as $plugin => $configFiles) {
         $i = 0;
         foreach ($configFiles as $configFile) {
             $xml = Xml::build($configFile);
             $items = $xml->xpath('menu/item');
             if (!is_array($items) || empty($items)) {
                 continue;
             }
             foreach ($items as $item) {
                 $item = Xml::toArray($item);
                 if (empty($item['item']['@label'])) {
                     continue;
                 }
                 if (!isset($item['item']['@id']) || empty($item['item']['@id'])) {
                     $id = ucfirst(Inflector::variable($item['item']['@label']));
                 } else {
                     $id = $item['item']['@id'];
                 }
                 $fields = array();
                 foreach ($item['item']['field'] as $key => $field) {
                     foreach ($field as $name => $value) {
                         $name = str_replace('@', '', $name);
                         $fields[$key][$name] = $value;
                     }
                 }
                 $prototypes[$plugin][$i]['Link']['id'] = $id;
                 $prototypes[$plugin][$i]['Link']['priority'] = !empty($item['item']['@priority']) ? $item['item']['@priority'] : '10';
                 $prototypes[$plugin][$i]['Link']['model'] = !empty($item['item']['@model']) ? $item['item']['@model'] : '';
                 $prototypes[$plugin][$i]['Link']['label'] = $item['item']['@label'];
                 $prototypes[$plugin][$i]['Field'] = $fields;
                 $i++;
             }
         }
     }
     foreach ($prototypes as $plugin => $section) {
         $prototypes[$plugin] = Hash::sort($section, '{n}.Link.priority', 'asc');
     }
     return $prototypes;
 }
 /**
  * @param array $shortcodes
  * @return void
  */
 private function addShortcodes($shortcodes)
 {
     foreach ($shortcodes as $shortcode) {
         $method = '__initShortcode_' . Inflector::variable(Inflector::slug($shortcode['id'], '_'));
         add_shortcode($shortcode['id'], array(&$this, $method));
         if (isset($shortcode['shortcodes'])) {
             $this->addShortcodes($shortcode['shortcodes']);
         }
     }
 }
示例#12
0
 public function beforeSave($options = array())
 {
     $parent = parent::beforeSave($options);
     if (empty($this->data[$this->alias]['name'])) {
         return $parent;
     }
     $name = $this->data[$this->alias]['name'];
     $name_slug = strtolower(Inflector::slug($name));
     $name_variable = Inflector::variable($name_slug);
     $this->data[$this->alias] += compact('name_variable', 'name_slug');
     return $parent;
 }
示例#13
0
 /**
  * Drop in replacement for FormHelper::input which adds additional logic for
  * determining whether to display certain fields, what type to use, and
  * setting additional CSS class names
  *
  * @param string $fieldName
  * @param array $options
  * @return string
  */
 function input($fieldName, $options = array())
 {
     // Do not display TreeBehavior lft and rght fields
     if (in_array($fieldName, array('lft', 'rght'))) {
         return;
     }
     // Do not display counter cache fields
     $isCount = substr($fieldName, -6) === '_count';
     if ($isCount) {
         return;
     }
     // Determine if this field is a key
     $isKey = substr($fieldName, -3) === '_id';
     // Determine if this field is a HABTM
     $this->Form->setEntity($fieldName);
     $isHabtm = $this->Form->model() === $this->Form->field();
     // If field is a key or habtm and options are not specified in options array
     if (($isKey || $isHabtm) && !isset($options['options'])) {
         // Try and get the options from the view vars
         $view =& ClassRegistry::getObject('view');
         $varName = Inflector::variable(Inflector::pluralize(preg_replace('/_id$/', '', $fieldName)));
         $varOptions = $view->getVar($varName);
         // If options is not an array, or empty, don't display the field
         if (!is_array($varOptions) || empty($varOptions)) {
             return;
         }
     }
     // Set default options required by CSS
     $defaults = array('label' => array('class' => 'label'));
     // If HABTM, set multiple type and various classnames
     if ($isHabtm) {
         $defaults['multiple'] = $defaults['class'] = $defaults['label']['class'] = 'checkbox';
     }
     // Set classnames depending to field type required by CSS
     $model =& ClassRegistry::getObject($this->model());
     $type = $model->getColumnType($fieldName);
     switch ($type) {
         case 'string':
             $defaults['class'] = 'text';
             break;
         case 'boolean':
             $defaults['class'] = $defaults['label']['class'] = 'checkbox';
             break;
     }
     // Add empty option
     if ($isKey) {
         $defaults['empty'] = __('Please select', true);
     }
     // Merge defaults with options
     $options = Set::merge($defaults, $options);
     // Return the form input markup
     return $this->Form->input($fieldName, $options);
 }
示例#14
0
 /**
  * implementedEvents
  * 
  * @return array
  */
 public function implementedEvents()
 {
     $events = array();
     if ($this->events) {
         foreach ($this->events as $registerEvent) {
             $eventName = $this->layer . '.' . $registerEvent;
             if (strpos($registerEvent, '.') !== false) {
                 $aryRegisterEvent = explode('.', $registerEvent);
                 $registerEvent = Inflector::variable(implode('_', $aryRegisterEvent));
             }
             $events[$eventName] = array('callable' => $registerEvent);
         }
     }
     return $events;
 }
示例#15
0
 public function loadHelpers()
 {
     parent::loadHelpers();
     $helpers = HelperCollection::normalizeObjectArray($this->helpers);
     foreach ($helpers as $properties) {
         list(, $class) = pluginSplit($properties['class']);
         $helper = $this->{$class};
         $class = Inflector::variable($class);
         if (!isset($this->viewVars[$class])) {
             $this->viewVars[$class] = $helper;
         }
         $this->Phptal->set($class, $helper);
         $this->_createHelperModifier($class);
     }
     unset($class, $helpers, $helper);
 }
 /**
  * After save callback
  *
  * @param object $model Model using this behavior
  * @param boolean $created True if this save created a new record
  * @access public
  * @return boolean True if the operation succeeded, false otherwise
  */
 public function afterSave(&$model, $created)
 {
     $return = parent::afterSave($model, $created);
     if ($this->settings[$model->alias]['mode'] == 'create' and isset($model->id) and !empty($model->id)) {
         $field = $this->settings[$model->alias]['field'];
         if ($model->hasField($field)) {
             //Build the URL...
             $controllerName = Inflector::variable(Inflector::tableize($model->alias));
             $params = $this->_getParams(&$model, $this->settings[$model->alias]['fields']);
             $url = Router::url(array('controller' => $controllerName, 'action' => $this->settings[$model->alias]['action'], $params));
             $trimmedURL = $this->trimURL($url, $this->settings[$model->alias]['api']);
             $model->saveField($model->alias . $field, $trimmedURL, true);
         }
     }
     return $return;
 }
示例#17
0
 function _replace($from, $alias)
 {
     list($to, $settings) = each(Set::normalize((array) $alias));
     $loadedHelpers = array();
     $this->view->_loadHelpers($loadedHelpers, array($to => $settings));
     list($plugin, $to) = pluginSplit($to);
     if (!isset($loadedHelpers[$to])) {
         return false;
     }
     $loaded =& $loadedHelpers[$to];
     list($plugin, $from) = pluginSplit($from);
     $key = Inflector::variable($from);
     $from = Inflector::classify($from);
     $this->view->loaded[$key] = $loaded;
     $this->view->{$from} =& $loaded;
     return true;
 }
示例#18
0
 protected function _loadController()
 {
     if (!$this->controllerName) {
         $this->err(__d('cake_console', 'Controller not found'));
     }
     $plugin = null;
     if ($this->plugin) {
         $plugin = $this->plugin . '.';
     }
     $controllerClassName = $this->controllerName . 'Controller';
     App::uses($controllerClassName, $plugin . 'Controller');
     if (!class_exists($controllerClassName)) {
         $file = $controllerClassName . '.php';
         $this->err(__d('cake_console', "The file '%s' could not be found.\nIn order to bake a view, you'll need to first create the controller.", $file));
         return $this->_stop();
     }
     $controllerObj = new $controllerClassName();
     $controllerObj->plugin = $this->plugin;
     $controllerObj->constructClasses();
     $modelClass = $controllerObj->modelClass;
     $modelObj = $controllerObj->{$controllerObj->modelClass};
     if ($modelObj) {
         $primaryKey = $modelObj->primaryKey;
         $displayField = $modelObj->displayField;
         $singularVar = Inflector::variable($modelClass);
         $singularHumanName = $this->_singularHumanName($this->controllerName);
         $schema = $modelObj->schema(true);
         $fields = array_keys($schema);
         $associations = $this->_associations($modelObj);
     } else {
         $primaryKey = $displayField = null;
         $singularVar = Inflector::variable(Inflector::singularize($this->controllerName));
         $singularHumanName = $this->_singularHumanName($this->controllerName);
         $fields = $schema = $associations = array();
     }
     $pluralVar = Inflector::variable($this->controllerName);
     $pluralHumanName = $this->_pluralHumanName($this->controllerName);
     $artigo = $info = null;
     if (isset($modelObj->genero)) {
         $artigo = $modelObj->genero == 'm' ? 'o' : 'a';
     }
     if (isset($modelObj->info)) {
         $info = $modelObj->info;
     }
     return compact('artigo', 'info', 'modelClass', 'schema', 'primaryKey', 'displayField', 'singularVar', 'pluralVar', 'singularHumanName', 'pluralHumanName', 'fields', 'associations');
 }
示例#19
0
 /**
  * setEnums
  *
  */
 public function setEnums()
 {
     if (empty($this->controller->modelClass) || empty($this->controller->uses)) {
         return;
     }
     $model = ClassRegistry::init($this->controller->modelClass);
     if (empty($model->enums)) {
         return;
     }
     foreach ($model->enums as $fieldName => $values) {
         if (!is_array($values)) {
             $values = Configure::read($values);
         }
         $varName = Inflector::variable(Inflector::pluralize(preg_replace('/_id$/', '', $fieldName)));
         $this->controller->set($varName, $values);
     }
 }
 function beforeRender()
 {
     $model = $this->modelClass;
     foreach ($this->{$model}->_schema as $var => $field) {
         if (strpos($field['type'], 'enum') === FALSE) {
             continue;
         }
         preg_match_all("/\\'([^\\']+)\\'/", $field['type'], $strEnum);
         if (is_array($strEnum[1])) {
             $varName = Inflector::variable(Inflector::pluralize($var));
             $options = array();
             foreach ($strEnum[1] as $value) {
                 $options[$value] = __($value, true);
             }
             $this->set($varName, $options);
         }
     }
 }
示例#21
0
 function _replace($from, $to)
 {
     $unset = $this->unset;
     if (is_array($to)) {
         extract($to);
     }
     $from = Inflector::variable($from);
     $to = Inflector::variable($to);
     $this->view->_loadHelpers($this->view->_loaded, array($to));
     list($plugin, $to) = pluginSplit($to);
     if (isset($this->view->loaded[$from]) && isset($this->view->loaded[$to])) {
         $this->view->loaded[$from] = $this->view->loaded[$to];
         if ($unset) {
             unset($this->view->loaded[$to]);
         }
         return true;
     }
     return false;
 }
 /**
  * afterFind
  */
 public function afterFind(Model $model, $results, $primary = true)
 {
     $node = array();
     foreach ($results as $result) {
         $row = array();
         if (isset($result[$model->alias])) {
             $row = array_merge($row, $result[$model->alias]);
         }
         $keys = array_keys($result);
         foreach ($keys as $key) {
             if ($key == $model->alias) {
                 continue;
             }
             $row[Inflector::variable($key)] = $result[$key];
         }
         $node[] = $row;
     }
     return $node;
 }
示例#23
0
 public function edit($id = null)
 {
     if (parent::edit($id, false, false)) {
         $Model = ClassRegistry::init($this->data['Comment']['class']);
         $item = $Model->findById($this->data['Comment']['foreign_id']);
         switch ($this->data['Comment']['class']) {
             case 'Task':
                 if ($item['Task']['assigned_to_id'] != User::get('id')) {
                     $Model->notify($item['Task']['assigned_to_id'], $this->data['Comment']['foreign_id'], $this->Tools->keyToId('commented_on', 'NotificationType'));
                 }
                 break;
         }
         $this->Redirect->flash(null, $this->referer);
     }
     foreach ($this->params['named'] as $class => $foreign_id) {
         $this->data['Comment']['class'] = ucfirst(Inflector::variable($class));
         $this->data['Comment']['foreign_id'] = $foreign_id;
     }
     $this->render('edit');
 }
示例#24
0
 /**
  * Model::beforeFilter() callback
  *
  * Used to override Acl permissions for this controller.
  */
 public function beforeFilter()
 {
     parent::beforeFilter();
     // for accessing the model
     $this->set('model', $this->modelClass);
     // for printing it out all friendly-like
     $this->set('modelKey', $this->modelKey);
     // give the views the schema, too, so they can
     // create forms with slight differences
     $schema = $this->{$this->modelClass}->schema();
     $this->set('schema', $schema);
     // check for dependent lists to add (i.e., ministries as a dropdown)
     foreach ($schema as $field => $attrs) {
         if (substr($field, -3) == '_id') {
             $dependentModel = Inflector::camelize(preg_replace('/_id$/', '', $field));
             $dependentListVar = Inflector::variable(Inflector::pluralize(preg_replace('/_id$/', '', $field)));
             $this->set($dependentListVar, $this->{$this->modelClass}->{$dependentModel}->find('list', array('fields' => array($dependentModel . '.' . $this->{$this->modelClass}->{$dependentModel}->displayField))));
         }
     }
     $this->set('title_for_layout', Inflector::pluralize(Inflector::humanize($this->modelKey)));
 }
 /**
  * Find and publish all related models to the view
  * for an action
  *
  * @param NULL|string $action If NULL the current action will be used
  * @return void
  */
 public function publishRelatedModels($action = null)
 {
     $models = $this->models($action);
     if (empty($models)) {
         return;
     }
     $Controller = $this->_controller();
     foreach ($models as $modelName) {
         $associationType = $this->_getAssociationType($modelName);
         $associatedModel = $this->_getModelInstance($modelName, $associationType);
         $viewVar = Inflector::variable(Inflector::pluralize($associatedModel->alias));
         if (array_key_exists($viewVar, $Controller->viewVars)) {
             continue;
         }
         $query = $this->_getBaseQuery($associatedModel, $associationType);
         $subject = $this->_trigger('beforeRelatedModel', compact('modelName', 'query', 'viewVar', 'associationType', 'associatedModel'));
         $items = $this->_findRelatedItems($associatedModel, $subject->query);
         $subject = $this->_trigger('afterRelatedModel', compact('modelName', 'items', 'viewVar', 'associationType', 'associatedModel'));
         $Controller->set($subject->viewVar, $subject->items);
     }
 }
示例#26
0
 public function parse($url)
 {
     /*
      * parse url
      */
     $params = parent::parse($url);
     if (!$params || empty($params)) {
         return false;
     }
     //get all registered modules
     $registeredModules = Configure::read('Cloggy.modules');
     /*
      * only active at module request
      */
     if (isset($params['name'])) {
         /*
          * setup module name
          */
         $moduleName = Inflector::variable($params['name']);
         $moduleName = ucfirst($moduleName);
         /*
          * check if requested module listed on registered modules
          */
         if (!in_array($moduleName, $registeredModules)) {
             return false;
         } else {
             /*
              * if empty controller it means go to module home controller
              */
             if (!isset($params['controller']) || empty($params['controller'])) {
                 $params['controller'] = $params['name'] . '_home';
             }
             //set flag that current request is module base
             $params['isCloggyModule'] = 1;
         }
     }
     return $params;
 }
示例#27
0
/**
 * Generates list of options for multiple select
 *
 * @param type $options
 * @return array
 */
	protected function _optionsOptions($options) {
		if (isset($options['options'])) {
			return $options;
		}
		$varName = Inflector::variable(
			Inflector::pluralize(preg_replace('/_id$/', '', $this->field()))
		);
		$varOptions = $this->_View->getVar($varName);
		if (!is_array($varOptions)) {
			return $options;
		}
		if ($options['type'] !== 'radio') {
			$options['type'] = 'select';
		}
		$options['options'] = $varOptions;
		return $options;
	}
示例#28
0
 /**
  * Creates the plural name for views
  *
  * @param string $name Name to use
  * @return string Plural name for views
  */
 protected function _pluralName($name)
 {
     return Inflector::variable(Inflector::pluralize($name));
 }
 /**
  * Loads Controller and sets variables for the template
  * Available template variables
  * 'modelClass', 'primaryKey', 'displayField', 'singularVar', 'pluralVar',
  * 'singularHumanName', 'pluralHumanName', 'fields', 'foreignKeys',
  * 'belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany'
  *
  * @return array Returns an variables to be made available to a view template
  * @access private
  */
 function __loadController()
 {
     if (!$this->controllerName) {
         $this->err(__('Controller not found', true));
     }
     $import = $this->controllerName;
     if ($this->plugin) {
         $import = $this->plugin . '.' . $this->controllerName;
     }
     if (!App::import('Controller', $import)) {
         $file = $this->controllerPath . '_controller.php';
         $this->err(sprintf(__("The file '%s' could not be found.\nIn order to bake a view, you'll need to first create the controller.", true), $file));
         $this->_stop();
     }
     $controllerClassName = $this->controllerName . 'Controller';
     $controllerObj =& new $controllerClassName();
     $controllerObj->plugin = $this->plugin;
     $controllerObj->constructClasses();
     $modelClass = $controllerObj->modelClass;
     $modelObj =& $controllerObj->{$controllerObj->modelClass};
     if ($modelObj) {
         $primaryKey = $modelObj->primaryKey;
         $displayField = $modelObj->displayField;
         $singularVar = Inflector::variable($modelClass);
         $singularHumanName = $this->_singularHumanName($this->controllerName);
         $schema = $modelObj->schema(true);
         $fields = array_keys($schema);
         $associations = $this->__associations($modelObj);
     } else {
         $primaryKey = $displayField = null;
         $singularVar = Inflector::variable(Inflector::singularize($this->controllerName));
         $singularHumanName = $this->_singularHumanName($this->controllerName);
         $fields = $schema = $associations = array();
     }
     $pluralVar = Inflector::variable($this->controllerName);
     $pluralHumanName = $this->_pluralHumanName($this->controllerName);
     return compact('modelClass', 'schema', 'primaryKey', 'displayField', 'singularVar', 'pluralVar', 'singularHumanName', 'pluralHumanName', 'fields', 'associations');
 }
示例#30
0
 /**
  * Render the view
  *
  * @param string $_viewFn 
  * @param string $_dataForView 
  * @return void
  */
 protected function _render($_viewFn, $_dataForView = array())
 {
     $isCtpFile = substr($_viewFn, -3) === 'ctp';
     if (empty($_dataForView)) {
         $_dataForView = $this->viewVars;
     }
     if ($isCtpFile) {
         return parent::_render($_viewFn, $_dataForView);
     }
     ob_start();
     // Setup the helpers from the new Helper Collection
     $helpers = array();
     $loaded_helpers = $this->Helpers->attached();
     foreach ($loaded_helpers as $helper) {
         $name = Inflector::variable($helper);
         $helpers[$name] = $this->loadHelper($helper);
     }
     if (!isset($_dataForView['cakeDebug'])) {
         $_dataForView['cakeDebug'] = null;
     }
     $data = array_merge($_dataForView, $helpers);
     $data['_this'] = $this;
     $relativeFn = str_replace($this->templatePaths, '', $_viewFn);
     $template = $this->Twig->loadTemplate($relativeFn);
     echo $template->render($data);
     return ob_get_clean();
 }