function mode($mode = 'full')
 {
     if (in_array($mode, array('full', 'lite'))) {
         $this->Session->write("Acl.Mode", low($mode));
     }
     $this->redirect($this->referer('/' . $this->PluginName . '/acos'));
 }
Esempio n. 2
0
 function beforeFilter()
 {
     /*
     
     if ( !isset($this->params['lang']) && !$this->Session->check('langSes') ) {
     	
     	$this->params['lang'] = $defaultLang;
     	$this->Session->write('langSes',$defaultLang);
     
     } elseif ( !isset($this->params['lang']) && $this->Session->check('langSes') ) {
     	$this->params['lang'] = $this->Session->read('langSes');
     } 
     
     Configure::write('Config.language', $this->params['lang']);
     $this->Session->write('langSes',$this->params['lang']);
     */
     if (isset($this->Auth)) {
         if ($this->viewPath == 'pages' && $this->params['action'] != 'admin_index') {
             $this->Auth->allow('*');
         } else {
             $this->Auth->authorize = 'controller';
             if (in_array(low($this->params['controller']), $this->publicControllers)) {
                 //$this->Auth->allow('*');
                 $this->Auth->deny('pages/admin_index');
             }
         }
         $this->Auth->loginAction = array('admin' => false, 'controller' => 'users', 'action' => 'login');
     }
 }
Esempio n. 3
0
 /**
  * This function can be thought of as a hybrid between PHP's array_merge and array_merge_recursive. The difference
  * to the two is that if an array key contains another array then the function behaves recursive (unlike array_merge)
  * but does not do if for keys containing strings (unlike array_merge_recursive). See the unit test for more information.
  *
  * Note: This function will work with an unlimited amount of arguments and typecasts non-array parameters into arrays.
  *
  * @param array $arr1 Array to be merged
  * @param array $arr2 Array to merge with
  * @return array Merged array
  * @access public
  */
 function merge($arr1, $arr2 = null)
 {
     $args = func_get_args();
     if (is_a($this, 'set')) {
         $backtrace = debug_backtrace();
         $previousCall = low($backtrace[1]['class'] . '::' . $backtrace[1]['function']);
         if ($previousCall != 'set::merge') {
             $r =& $this->value;
             array_unshift($args, null);
         }
     }
     if (!isset($r)) {
         $r = (array) current($args);
     }
     while (($arg = next($args)) !== false) {
         if (is_a($arg, 'set')) {
             $arg = $arg->get();
         }
         foreach ((array) $arg as $key => $val) {
             if (is_array($val) && isset($r[$key]) && is_array($r[$key])) {
                 $r[$key] = Set::merge($r[$key], $val);
             } elseif (is_int($key)) {
                 $r[] = $val;
             } else {
                 $r[$key] = $val;
             }
         }
     }
     return $r;
 }
Esempio n. 4
0
 function afterFind(&$Model, $results, $primary)
 {
     if ($this->__settings[$Model->name]['countchild_enabled'] === false) {
         return $results;
     }
     foreach ($results as $key => $val) {
         /* Loop results */
         if (!is_array($val)) {
             continue;
             /* Should never happen */
         }
         foreach ($val as $k => $v) {
             if ($k == $Model->name) {
                 /* This is the parent dataset to populate, so skip */
                 continue;
             }
             if (empty($v)) {
                 $results[$key][$Model->name][low($k) . $this->__settings[$Model->name]['count_field_suffix']] = 0;
             } elseif (!isset($v[0])) {
                 /* HasOne relationship */
                 $results[$key][$Model->name][low($k) . $this->__settings[$Model->name]['count_field_suffix']] = 1;
             } else {
                 /* HasMany relationship */
                 $results[$key][$Model->name][low($k) . $this->__settings[$Model->name]['count_field_suffix']] = count($v);
             }
         }
     }
     $this->__settings[$Model->name]['countchild_enabled'] = false;
     return $results;
 }
Esempio n. 5
0
 /**
  * Returns a string with all spaces converted to $replacement and non word characters removed.
  *
  * @param string $string
  * @param string $replacement
  * @return string
  * @static
  */
 static function slug($string, $replacement = '-')
 {
     $string = trim($string);
     $map = array('/à|á|å|â|ä/' => 'a', '/è|é|ê|ẽ|ë/' => 'e', '/ì|í|î/' => 'i', '/ò|ó|ô|ø/' => 'o', '/ù|ú|ů|û/' => 'u', '/ç|č/' => 'c', '/ñ|ň/' => 'n', '/ľ/' => 'l', '/ý/' => 'y', '/ť/' => 't', '/ž/' => 'z', '/š/' => 's', '/æ/' => 'ae', '/ö/' => 'oe', '/ü/' => 'ue', '/Ä/' => 'Ae', '/Ü/' => 'Ue', '/Ö/' => 'Oe', '/ß/' => 'ss', '/[^\\w\\s]/' => ' ', '/\\s+/' => $replacement, String::insert('/^[:replacement]+|[:replacement]+$/', array('replacement' => preg_quote($replacement, '/'))) => '');
     $string = preg_replace(array_keys($map), array_values($map), $string);
     return low($string);
 }
Esempio n. 6
0
 function beforeFilter()
 {
     $defaultLang = Configure::read('Languages.default');
     //debug(env('HTTP_ACCEPT_LANGUAGE'));
     if (!isset($this->params['lang']) && !$this->Session->check('langSes')) {
         $this->params['lang'] = $defaultLang;
         $this->Session->write('langSes', $defaultLang);
     } elseif (!isset($this->params['lang']) && $this->Session->check('langSes')) {
         $this->params['lang'] = $this->Session->read('langSes');
         //$this->Session->write('testSes', 'case2');
     }
     //debug(Configure::read('Config.language'));
     //debug(Configure::version());
     Configure::write('Config.language', $this->params['lang']);
     $this->Session->write('langSes', $this->params['lang']);
     if ($this->name != 'App' && !in_array($this->params['lang'], Configure::read('Languages.all'))) {
         unset($this->params['lang']);
         $this->Session->del('langSes');
         $this->Session->setFlash(__('Whoops, not a valid language.', true));
         $this->redirect('/', 301, true);
     }
     if (isset($this->Auth)) {
         if ($this->viewPath == 'pages' && $this->params['action'] != 'admin_index') {
             $this->Auth->allow('*');
         } else {
             $this->Auth->authorize = 'controller';
             if (in_array(low($this->params['controller']), $this->publicControllers)) {
                 //$this->Auth->allow('*');
                 $this->Auth->deny('pages/admin_index');
             }
         }
         $this->Auth->loginAction = array('admin' => false, 'controller' => 'users', 'action' => 'login');
     }
 }
Esempio n. 7
0
 function validateTitle($value)
 {
     if (!empty($value) && strpos(low($value['title']), 'title-') === 0) {
         return true;
     }
     return false;
 }
 function beforeFilter()
 {
     // Do not continue if there is an indication of a previous successful installation
     if (file_exists(APP . 'do_not_remove')) {
         $this->redirect(array('controller' => 'home', 'action' => 'index'));
     }
     $this->checkPreReqs();
     if (!empty($this->data)) {
         $this->Installer->data = $this->data;
     }
     // auto-calculate the total number of steps using some convention magic
     $steps = count(array_filter(get_class_methods('InstallerController'), array($this, "__getSteps")));
     $this->action = low($this->action);
     switch ($this->action) {
         case 'setup_db':
             $this->pageTitle = "Database Setup";
             $step = 1;
             break;
         case 'setup_auth':
             $this->pageTitle = "Authentication";
             $step = 2;
             break;
         case 'thanks':
             $this->pageTitle = "Installation Complete!";
             return;
         case $this->redirect(array('action' => 'setup_db')):
     }
     // set the right set of form validation rules for the current step
     $this->Installer->step($step);
     $this->pageTitle .= " [{$step}/{$steps}]";
     $this->set('submit', $step < $steps ? 'Next >>' : 'Finish');
     $this->set('url', array('url' => array('controller' => 'installer', 'action' => $this->action)));
     $this->set(compact('step', 'steps'));
 }
Esempio n. 9
0
function season($indoor)
{
    // The configuration settings values have "0" for the year, to facilitate form input
    $today = date('0-m-d');
    $today_wrap = date('1-m-d');
    // Build the list of applicable seasons
    $seasons = Configure::read('options.season');
    unset($seasons['None']);
    if (empty($seasons)) {
        return 'None';
    }
    foreach (array_keys($seasons) as $season) {
        $season_indoor = Configure::read("season_is_indoor.{$season}");
        if ($indoor != $season_indoor) {
            unset($seasons[$season]);
        }
    }
    // Create array of which season follows which
    $seasons = array_values($seasons);
    $seasons_shift = $seasons;
    array_push($seasons_shift, array_shift($seasons_shift));
    $next = array_combine($seasons, $seasons_shift);
    // Look for the season that has started without the next one starting
    foreach ($next as $a => $b) {
        $start = Configure::read('organization.' . Inflector::slug(low($a)) . '_start');
        $end = Configure::read('organization.' . Inflector::slug(low($b)) . '_start');
        // Check for a season that wraps past the end of the year
        if ($start > $end) {
            $end[0] = '1';
        }
        if ($today >= $start && $today < $end || $today_wrap >= $start && $today_wrap < $end) {
            return $a;
        }
    }
}
Esempio n. 10
0
 function beforeFilter()
 {
     if (isset($this->Auth)) {
         if (is_null($this->Auth->User())) {
             $cookie = $this->Cookie->read('Auth.User');
             if (!is_null($cookie)) {
                 //debug($cookie);
                 if ($this->Auth->login($cookie)) {
                     //  Clear auth message, just in case we use it.
                     $this->Session->del('Message.auth');
                     $this->redirect('/users/index');
                 } else {
                     // Delete invalid Cookie
                     $this->Cookie->del('Auth.User');
                 }
             }
         }
         if ($this->viewPath == 'pages') {
             $this->Auth->allow('*');
         } else {
             $this->Auth->authorize = 'controller';
             if (in_array(low($this->params['controller']), $this->publicControllers)) {
                 $this->Auth->allow('*');
             }
         }
     }
 }
Esempio n. 11
0
 /**
  * Controllers initialize function.
  */
 function initialize(&$controller, $settings = array())
 {
     $this->Controller =& $controller;
     $settings = array_merge(array(), (array) $settings);
     $this->modelName = $this->Controller->modelClass;
     $this->prettyModelName = low(Inflector::humanize(Inflector::underscore(Inflector::pluralize($this->modelName))));
 }
Esempio n. 12
0
 function hiddenField($name, $type, $value)
 {
     $output = '';
     if ($name && $type) {
         $output = $this->html->input($type, array('type' => 'hidden', 'id' => low($name), 'value' => $value)) . '<br/>';
     }
     return $this->output($output);
 }
Esempio n. 13
0
 function _getMainMenu()
 {
     $conditions = array('Group.name' => low($this->auth['User']['TYPE']));
     $this->loadModel('Group');
     $this->Group->Behaviors->attach('Containable');
     $this->Group->contain('Link.parent_id IS NULL');
     $group = $this->Group->find('first', array('conditions' => $conditions));
     return $group['Link'];
 }
 function _checkAccess($aro, $aco)
 {
     $access = $this->Acl->check($aro, low($aco), $action = "*");
     if ($access === false) {
         return false;
     } else {
         return true;
     }
 }
Esempio n. 15
0
 function main()
 {
     $this->imagePath = WWW_ROOT . 'img' . DS . 'blog' . DS;
     $fileListContent = '';
     $posts = $this->Blogpost->find('all');
     foreach ($posts as $post) {
         //$this->Blogpost->id = $post['Blogpost']['id'];
         unset($post['Blogpost']['slug']);
         unset($post['Blogpost']['title']);
         unset($post['Blogpost']['user_id']);
         unset($post['Blogpost']['created']);
         unset($post['Blogpost']['deleted']);
         $subject = $post['Blogpost']['description'];
         preg_match_all('@<img[^>]*src="([^"]*)"[^>]*>@Usi', $subject, $matches);
         if (!empty($matches[1])) {
             foreach ($matches[1] as $img) {
                 $oldPath = $img;
                 $newPath = $this->imagePath . basename($img);
                 $wwwPath = '/img/blog/' . basename($img);
                 if (preg_match('/img/blog/', $img)) {
                     //that link already fixed
                     continue;
                 }
                 if (!preg_match('bpong.com', $img) && !preg_match('http://', $img)) {
                     //it's relative path. Let's deal with it separetely
                     if ($img[0] == '.') {
                         $img = $this->bpongPath . ltrim($img, '.');
                     } elseif ($img[0] == '/') {
                         $img = $this->bpongPath . $img;
                     } else {
                         $img = $this->bpongPath . '/' . $img;
                     }
                 }
                 if (!@copy($img, $newPath)) {
                     $errors = error_get_last();
                     $this->out("COPY ERROR: " . $errors['message']);
                     $this->out("FILE:" . $oldPath);
                     $key = $this->in('Change dp path anyway?', array('y', 'n', 'q'), 'y');
                     if (low($key) == 'y') {
                         $post['Blogpost']['description'] = str_replace($oldPath, $wwwPath, $post['Blogpost']['description']);
                         $fileListContent .= $oldPath . "\n\r";
                     } elseif (low($key) == 'q') {
                         exit;
                     }
                 } else {
                     $this->out($img . "\n\r COPY TO \n\r" . $newPath);
                     $post['Blogpost']['description'] = str_replace($oldPath, $wwwPath, $post['Blogpost']['description']);
                 }
             }
             $this->Blogpost->save($post);
         }
         //$this->out(pr($matches));
         //$this->Blogpost->save($post);
     }
     $this->createFile(WWW_ROOT . 'files.txt', $fileListContent);
 }
Esempio n. 16
0
 /**
  * Allows an anchor to be declared for a page block. Populates a $viewVars['sections'], which can be used to generate a navigation element such as jump_menu.ctp.
  *
  * @param  string  $title The title text, such a "Details"
  * @param  string  $url A custom anchor. If none is provided, a slugified version of $title will be used instead.
  * @return string
  */
 function anchor($title, $url = null)
 {
     if (empty($url)) {
         $url = low(Inflector::slug($title)) . '_jump';
     }
     // Put the details in a view variable so they can be output elsewhere.
     $view =& ClassRegistry::getObject('view');
     $view->viewVars['sections'][$title] = '#' . $url;
     return '<a name="' . $url . '" class="jump_anchor"></a>';
 }
Esempio n. 17
0
 function admin_add()
 {
     if (!empty($this->data)) {
         $this->data['Page']['file_name'] = low(Inflector::slug($this->data['Page']['name']));
         if ($this->Page->save($this->data)) {
             $this->Session->setFlash(__('Your page has been saved.', true));
             $this->redirect(array('action' => 'index'));
         }
         $this->Session->setFlash(__('Your page could not be saved.', true));
     }
 }
Esempio n. 18
0
 /**
  * When object is initialized
  *
  * @param $model Model object reference
  * @param $versionedFields Array of field names to keep under version control
  * @return void
  */
 function setup($model, $versionedFields = array())
 {
     if (empty($versionedFields)) {
         trigger_error($this->_noFieldsError);
         // @TODO add all model fields automaticaly
     }
     $this->Revision = ClassRegistry::init('Revision');
     $this->_model = $model;
     $this->_type = low($this->_model->name);
     $this->_versionedFields = $versionedFields;
 }
 function setup(&$model, $config = array())
 {
     static $utf8Enabled = array();
     if (!isset($utf8Enabled[$model->useDbConfig])) {
         $db =& ConnectionManager::getDataSource($model->useDbConfig);
         if (low(get_class($db)) == 'dbomysql' || low(get_class($db)) == 'dbomysqlex') {
             $db->execute('SET NAMES utf8');
         }
         $utf8Enabled[$model->useDbConfig] = true;
     }
 }
Esempio n. 20
0
 public static function username($options = array())
 {
     if (isset($options['variable'])) {
         $name = explode(' ', $options['variable']);
         $name = low($name[0]);
         return $name . self::generate_random_alphanumeric_str('xx');
     }
     $f = new Faker();
     $Name = $f->Name;
     $fname = strtolower($Name->first_name(array('single' => true)));
     return $fname . self::generate_random_alphanumeric_str('xx');
 }
 function __construct($id = false, $table = null, $ds = null)
 {
     //$this->useDbConfig = 'test';
     static $utf8Enabled = array();
     if (!isset($utf8Enabled[$this->useDbConfig])) {
         $db =& ConnectionManager::getDataSource($this->useDbConfig);
         if (low(get_class($db)) == 'dbomysql') {
             //$db->execute('SET CHARACTER SET utf8');
         }
         $utf8Enabled[$this->useDbConfig] = true;
     }
     parent::__construct($id, $table, $ds);
 }
Esempio n. 22
0
 function parse($config)
 {
     $config = str_replace(array('"', "'"), '', low($config));
     $this->config = array('leagues' => array_map('trim', explode(',', $config)));
     $sub_key = array_search('include_subs', $this->config['leagues']);
     if ($sub_key !== false) {
         $this->config['roles'] = Configure::read('extended_playing_roster_roles');
         unset($this->config['leagues'][$sub_key]);
     } else {
         $this->config['roles'] = Configure::read('playing_roster_roles');
     }
     return true;
 }
Esempio n. 23
0
 /**
  * generate SEO url
  *
  * @param $data
  * @param $controller
  * @param $action
  */
 public function url($data, $controller = 'products', $action = 'show', $plugin = '')
 {
     $myvar = low(Inflector::slug($data['name'], '-'));
     $myvar = '/' . $myvar;
     $link = $this->Html->url(array_merge(compact('plugin', 'myvar', 'controller', 'action'), array($data['id'])));
     /*
     $splitter = Router::url('/');
     $linkArray = explode($splitter, $link);
     unset($linkArray[0]);
     $linkText = implode('/', $linkArray);
     return Router::url('/') . low(Inflector::slug($linkText, '-')) . '.html';
     */
     return $link;
 }
 function __inheritVars($className)
 {
     if (low($className) != 'appcontroller') {
         $ParentClass = get_parent_class($className);
         $ParentVars = get_class_vars($ParentClass);
         foreach (array('components', 'helpers', 'uses') as $var) {
             if (isset($ParentVars[$var]) && !empty($ParentVars[$var]) && is_array($this->{$var})) {
                 $diff = array_diff($ParentVars[$var], $this->{$var});
                 $this->{$var} = array_merge($this->{$var}, $diff);
             }
         }
         $this->__inheritVars($ParentClass);
     }
 }
Esempio n. 25
0
 function beforeFilter()
 {
     if (isset($this->Auth)) {
         if ($this->viewPath == 'pages' && $this->params['action'] != 'admin_index') {
             $this->Auth->allow('*');
         } else {
             $this->Auth->authorize = 'controller';
             if (in_array(low($this->params['controller']), $this->publicControllers)) {
                 //$this->Auth->allow('*');
                 $this->Auth->deny('pages/admin_index');
             }
         }
         $this->Auth->loginAction = array('admin' => false, 'controller' => 'users', 'action' => 'login');
     }
 }
Esempio n. 26
0
 /**
  * undocumented function
  *
  * @param string $id 
  * @return void
  * @access public
  */
 function admin_delete($id = null, $model = false)
 {
     $userId = User::get('id');
     $favorite = $this->Favorite->find('first', array('conditions' => array('user_id' => $userId, 'foreign_id' => $id)));
     $adj = Configure::read('Favorites.adjective');
     $model = empty($model) ? 'object' : low($model);
     if (empty($favorite)) {
         $msg = __('This ' . $model . ' was not ' . $adj . ' in the first place.', true);
         return $this->Message->add($msg, 'error', true, $this->referer());
     }
     $this->Favorite->del($favorite['Favorite']['id']);
     $this->Favorite->load(User::get('id'));
     $subject = Configure::read('Favorites.subject');
     $msg = __('This ' . $model . ' was successfully removed from your ' . Inflector::pluralize($subject) . '.', true);
     $this->Message->add($msg, 'ok', true, $this->referer());
 }
Esempio n. 27
0
 /**
  * Constructeur de la classe
  *
  * @param 	varchar $view 			Nom de la vue à charger
  * @param 	object 	$controller 	Contrôleur faisant appel à la vue
  * @access	public
  * @author	koéZionCMS
  * @version 0.1 - 13/06/2012 by FI
  * @version 0.2 - 05/06/2013 by FI - Mise en place du chargement des helpers template
  * @version 0.2 - 05/06/2013 by FI - Modification de la gestion des Helpers, par défaut on charge de façon distincte les helpers du backoffice et du frontoffice pour plus de souplesse dans la gestion des templates
  * @version 0.3 - 07/07/2014 by FI - Rajout de $this->request = new stdClass(); pour corriger l'erreur suivante Warning: Creating default object from empty value in /core/Koezion/view.php on line 342 
  * @version 0.4 - 08/01/2015 by FI - Mise en place des hooks pour les helpers 
  */
 public function __construct($view, $controller)
 {
     $this->view = $view;
     $this->controller = $controller;
     $this->layout = $controller->layout;
     $this->vars = $controller->get('vars');
     $this->vars['components'] = $controller->components;
     $this->params = $controller->params;
     $this->request = new stdClass();
     //Si on a des helpers à charger
     //Il s'agit ici de helpers commun à l'ensemble des templates backoffice et frontoffice uniquement
     //S'il s'agit de helpers spécifiques il faut mettre les fichiers dans les dossiers correspondants
     if ($this->helpers) {
         foreach ($this->helpers as $k => $v) {
             $helper = low($v);
             require_once HELPERS . DS . $helper . '_helper.php';
             unset($this->helpers[$k]);
             $helperObjectName = $v . 'Helper';
             $this->vars['helpers'][$v] = new $helperObjectName($this);
         }
     }
     //INSERTION DES EVENTUELS HELPERS DU TEMPLATE (BACK OU FRONT)//
     if (defined('LAYOUT_VIEWS')) {
         $moreHelpers = LAYOUT_VIEWS . DS . 'helpers';
     } else {
         $moreHelpers = HELPERS . DS . 'backoffice';
     }
     //Backoffice
     if (is_dir($moreHelpers)) {
         foreach (FileAndDir::directoryContent($moreHelpers) as $moreHelper) {
             $helperPath = $moreHelpers . DS . $moreHelper;
             //On va effectuer un contrôle pour vérifier si un hook n'est pas en place pour le helper concerné
             if (defined('LAYOUT_VIEWS')) {
                 $websiteHooks = $this->vars['websiteParams'];
                 $helpersHooks = $this->_load_hooks_files('HELPERS', $websiteHooks);
                 if (isset($helpersHooks[$moreHelper])) {
                     $helperPath = $helpersHooks[$moreHelper];
                 }
             }
             require_once $helperPath;
             $helperClass = Inflector::camelize(str_replace('_helper.php', '', $moreHelper));
             $helperObjectName = $helperClass . 'Helper';
             $this->vars['helpers'][$helperClass] = new $helperObjectName($this);
         }
     }
     $this->rendered = false;
 }
Esempio n. 28
0
 /**
  * Show help screen.
  *
  * @access public
  */
 function help()
 {
     $head = __("Usage: cake acl_extras <command>", true) . "\n";
     $head .= "-----------------------------------------------\n";
     $head .= __("Commands:", true) . "\n\n";
     $commands = array('sync' => "\tcake coderz_profiles_sync sync\n" . "\t\t" . __("Synchronize UserProfile table", true) . "\n" . "\t\t" . __("Will only synch linked (profiles with a valid user)", true) . "\n" . "\t\t" . __("Will unlink non-existant user's profiles", true), 'report' => "\tcake coderz_profiles_sync report\n" . "\t\t" . __("Reports unsynched linked UserProfiles and some other reports (see output)", true), 'news_slugs_sync' => "\tcake coderz_profiles_sync news_slugs_sync\n" . "\t\t" . __('Create slugs for all news in database', true), 'help' => "\thelp [<command>]\n" . "\t\t" . __("Displays this help message, or a message on a specific command.", true) . "\n");
     $this->out($head);
     if (!isset($this->args[0])) {
         foreach ($commands as $cmd) {
             $this->out("{$cmd}\n\n");
         }
     } elseif (isset($commands[low($this->args[0])])) {
         $this->out($commands[low($this->args[0])] . "\n");
     } else {
         $this->out(sprintf(__("Command '%s' not found", true), $this->args[0]));
     }
 }
Esempio n. 29
0
 /**
  * undocumented function
  *
  * @param string $model 
  * @param string $contain 
  * @return void
  * @access public
  */
 function _process($model, $contain = array())
 {
     Assert::true(User::allowed($this->name, $this->action), '403');
     Assert::true($this->isPost() || $this->Session->read($this->sessKeyModel) == $model, '404');
     if (isset($this->data[$model]) && !isset($this->data[$model]['process'])) {
         $this->saveModel($model);
         return $this->saveSelection($model);
     }
     $plural = low(Inflector::pluralize($model));
     $conditions = $this->Session->read($plural . '_filter_conditions');
     $selection = $this->loadSelection();
     if (!empty($selection)) {
         $conditions[$model . '.id'] = $selection;
     }
     // remove gift id from csv fields, although cake fetched it to do joins
     $addedGiftId = false;
     if (!in_array($model . '.id', (array) $this->data[$model]['fields'])) {
         $addedGiftId = true;
         $this->data[$model]['fields'][] = $model . '.id';
     }
     $items = $this->{$model}->find('all', array('conditions' => $conditions, 'contain' => $contain, 'fields' => am($this->data[$model]['fields'], array('Currency.iso_code'))));
     // remove the gift id from fields list now if needed
     if ($addedGiftId) {
         $key = array_search($model . '.id', $this->data[$model]['fields']);
         unset($this->data[$model]['fields'][$key]);
     }
     if ($this->data[$model]['softdelete']) {
         $this->{$model}->softdelete($items);
     }
     $items = $this->filterFields($model, $items, $contain);
     foreach ($items as $i => $item) {
         $items[$i][$model]['amount'] .= ' ' . $items[$i]['Currency']['iso_code'];
         unset($items[$i]['Currency']);
     }
     if (isset($this->data[$model]['download']) && $this->data[$model]['download']) {
         $name = $plural . '_export_' . date('Y_m_d_H_i');
         $path = '/admin/exports/' . $plural . '.' . $this->data[$model]['format'];
         $this->ForceDownload->forceDownload($path, $name);
     }
     $Export = ClassRegistry::init('Export');
     $Export->create(array('user_id' => User::get('id'), 'nb_exported' => count($items), 'model' => $model));
     $Export->save();
     $this->set(compact('items'));
     $this->RequestHandler->renderAs($this, $this->data[$model]['format']);
 }
Esempio n. 30
0
 /**
  * undocumented function
  *
  * @param string $data 
  * @return void
  * @access public
  */
 function events($data, $options = array())
 {
     $defaults = array('showIds' => true, 'ids' => array());
     $options = am($defaults, $options);
     $result = array();
     foreach ($data as $key => $row) {
         $one = $row['Log'];
         $result[$key]['Log']['id'] = $one['id'];
         $result[$key]['Log']['continuous_id'] = $one['continuous_id'];
         $event = $row['User']['name'];
         $model = low($one['model']);
         if (isset($one['model']) && isset($one['action']) && isset($one['change'])) {
             if ($one['action'] == 'edit') {
                 $event .= ' edited ' . $one['change'] . ' of ' . $model;
             } elseif ($one['action'] == 'add') {
                 $event .= ' added a ' . $model;
             } elseif ($one['action'] == 'delete') {
                 $event .= ' deleted the ' . $model;
             }
         } elseif (isset($one['model']) && isset($one['action'])) {
             if ($one['action'] == 'edit') {
                 $event .= ' edited ' . $model;
             } elseif ($one['action'] == 'add') {
                 $event .= ' added a ' . $model;
             } elseif ($one['action'] == 'delete') {
                 $event .= ' deleted the ' . $model;
             }
         } else {
             $event = $one['description'];
         }
         if ($options['showIds']) {
             $id = 'id';
             if (isset($options['ids'][$one['model']])) {
                 $id = $options['ids'][$one['model']];
             }
             $event .= '(' . $id . ' ' . $row[$one['model']][$id] . ')';
         }
         $result[$key]['Log']['event'] = $event;
         if ($options['showData'] && isset($one['change'])) {
             $result[$key]['Log']['change'] = explode(',', $one['change']);
         }
         $result[$key]['Log']['created'] = $one['created'];
     }
     return $result;
 }