public function setUp() { Time::setToStringFormat('yyyy-MM-dd HH:mm:ss'); $this->request = new Request(); $this->response = new Response(); $this->view = new CsvView($this->request, $this->response); }
public function beforeFilter(Event $event) { parent::beforeFilter($event); Time::$defaultLocale = 'en-CA'; Time::setToStringFormat('YYYY-MM-dd'); $this->Session = $this->request->session(); $this->set('Session', $this->Session); $this->_icons = $this->Utilities->setIcons(); $this->set('icons', $this->_icons); $title = $this->Utilities->setDefaultTitle(); $breadcrumbs = $this->Utilities->setDefaultBreadcrumbs(); $this->set(compact('title', 'breadcrumbs')); if (empty($this->request->params['prefix'])) { $this->Auth->allow(); $this->viewBuilder()->layout('public'); } // Set the user logged in if (!is_null($this->Auth->user('id'))) { $Users = TableRegistry::get('Users'); $this->_user = $Users->get($this->Auth->user('id')); $this->set('authUser', $this->_user); } else { $this->set('authUser', false); } // $this->set(compact($authUser)); $nav = $this->_setNav(); $this->set(compact('nav')); }
public function beforeFilter(Event $event) { parent::beforeFilter($event); $session = $this->request->session(); $lang = 'en'; if (isset($this->request->params['lang'])) { $lang = $this->request->params['lang']; } else { if ($session->check('Config.language')) { $lang = $session->read('Config.language'); } } $session->write('Config.language', $lang); // Change current language by post request if ($this->request->is('post') && isset($this->request->data['language'])) { $newLang = $this->request->data['language']; $transUrl = $this->translateUrl($newLang); $this->redirect($transUrl); } $this->set('lang', $lang); $this->set('controller', $this->name); I18n::locale($lang); Time::setToStringFormat('YYYY-MM-dd HH:mm:ss'); Type::build('datetime')->useLocaleParser(); $this->Auth->config(['unauthorizedRedirect' => false]); $this->Auth->allow(['login', 'init']); $user = $this->Auth->user(); if (isset($user)) { $username = $user['username']; $this->set(['is_authorized' => true, 'username' => $username]); } else { $this->set('is_authorized', false); } }
/** * Initialization hook method. * * Use this method to add common initialization code like loading components. * * @return void */ public function initialize() { parent::initialize(); $this->loadComponent('Flash'); $this->loadComponent('Paginator'); Time::$defaultLocale = 'es-ES'; Time::setToStringFormat('dd-MM-YYYY HH:mm'); }
/** * Initialization hook method. * * Use this method to add common initialization code like loading components. * * e.g. `$this->loadComponent('Security');` * * @return void */ public function initialize() { $this->loadComponent('Flash'); $this->loadComponent('RequestHandler'); // added in line to format date correctly Time::$defaultLocale = 'en-AU'; Time::setToStringFormat('dd/MM/YYYY'); $this->loadComponent('Auth', ['authorize' => ['Controller'], 'authenticate' => ['Form' => ['fields' => ['username' => 'email', 'password' => 'password']]], 'loginRedirect' => ['controller' => 'pages', 'action' => 'home'], 'logoutRedirect' => ['controller' => 'Pages', 'action' => 'display', 'home']]); }
/** * Before render callback. * * @param \Cake\Event\Event $event The beforeRender event. * @return void */ public function beforeRender(Event $event) { if (!array_key_exists('_serialize', $this->viewVars) && in_array($this->response->type(), ['application/json', 'application/xml'])) { $this->set('_serialize', true); } Time::setToStringFormat('dd/MM/yy, HH:MM'); Time::setJsonEncodeFormat('dd/MM/yy, HH:MM'); $this->set('renderLayoutTitle', $this->renderLayoutTitle); $this->set('userLoggedIn', $this->Auth->user()); }
/** * Initialization hook method. * * Use this method to add common initialization code like loading components. * * @return void */ public function initialize() { parent::initialize(); //Time::$defaultLocale = 'es-ES'; Time::setToStringFormat('dd-MM-YYYY'); $this->set('myTemplates', Configure::read('Templates')); $this->primerRecibo = Configure::read('primerRecibo'); $this->set('primerRecibo', $this->primerRecibo); $this->loadComponent('Flash'); }
protected function _getNextTurn() { if ($this->hostinterval != 0) { Time::setToStringFormat('yyyy-MM-dd HH:mm:ss'); $clone = clone $this->lastturn; return $clone->addMinutes($this->hostinterval); } else { if ($this->hour != 0) { return false; } } return false; }
/** * Initialization hook method. * * Use this method to add common initialization code like loading components. * * @return void */ public function initialize() { parent::initialize(); Time::setToStringFormat('YYYY-MM-dd HH:mm:ss'); $this->loadComponent('Csrf'); $this->loadComponent('RequestHandler'); //for json data $this->loadComponent('Flash'); $this->loadComponent('Auth', ['authenticate' => ['Form' => ['fields' => ['username' => 'username', 'password' => 'password']]], 'loginAction' => ['controller' => 'Users', 'action' => 'login']]); // Allow the display action so our pages controller // continues to work. We don't actually use the pages controller //so disable this for now //$this->Auth->allow(['display']); }
/** * Initialization hook method. * * Use this method to add common initialization code like loading components. * * @return void */ public function initialize() { parent::initialize(); //configure the date to australian format globally . Time::setToStringFormat('dd/MM/YYYY'); Configure::write('orderRecievedEmail', '*****@*****.**'); //set up the AUTH componant to facilitate login. $this->loadComponent('Auth', ['authenticate' => ['Form' => ['fields' => ['username' => 'username', 'password' => 'password']]], 'loginAction' => ['controller' => 'Users', 'action' => 'login'], 'loginRedirect' => ['controller' => 'Users', 'action' => 'index'], 'logoutRedirect' => ['controller' => 'Pages', 'action' => 'display', 'home']]); // Allow the display action so our pages controller // continues to work. $this->Auth->allow(['display']); //set the user role in the session for security check later on. $session = $this->request->session(); $session->write('userRole', $this->Auth->user('role')); //this loads the nice tooltip messages for errors, confirms etc. $this->loadComponent('Flash'); $this->loadComponent('Cookie', ['expiry' => '+2 days']); }
/** * Before render callback. * * @param \Cake\Event\Event $event The beforeRender event. * @return void */ public function beforeRender(Event $event) { Time::setToStringFormat('dd/MM/YYYY'); if (!array_key_exists('_serialize', $this->viewVars) && in_array($this->response->type(), ['application/json', 'application/xml'])) { $this->set('_serialize', true); } $login = $this->request->session()->read("Auth.User.username"); $foto = $this->request->session()->read("Auth.User.foto"); $this->set('fotoUsuario', $foto); $this->set('login', $login); $this->loadModel('Logs'); $logs = $this->Logs->find('all', ['fields' => ['Logs.id', 'Logs.descricao', 'Acao.nome', 'Acao.icone'], 'order' => ['Logs.id' => 'desc'], 'join' => [['table' => 'acoes', 'alias' => 'Acao', 'type' => 'INNER', 'conditions' => ['Acao.id = Logs.acao_id']]], 'limit' => 4])->toArray(); $this->set('logs', $logs); $this->loadModel('Metas'); $progresso_metas = $this->Metas->find('all', ['fields' => ['nome' => 'Metas.nome', 'percentual' => '(SUM(Lancamentos.valor) * 100 / Metas.vl_meta)', 'Metas.tp_controle'], 'order' => ['Metas.nome' => 'asc'], 'join' => [['table' => 'lancamentos', 'alias' => 'Lancamentos', 'type' => 'INNER', 'conditions' => ['Lancamentos.categoria_id = Metas.categoria_id']]], 'conditions' => ['Lancamentos.dt_cadastro BETWEEN Metas.dt_inicial and Metas.dt_final'], 'group' => ['Lancamentos.categoria_id']])->toArray(); $this->set('progresso_metas', $progresso_metas); // Contas a pagar e contas a receber $this->loadModel('Lancamentos'); $dtCadastro = new \DateTime('now'); $lancamentos = $this->Lancamentos->find('all', ['fields' => ['Lancamentos.descricao', 'Lancamentos.valor'], 'order' => ['Lancamentos.data' => 'asc'], 'conditions' => ['Lancamentos.data >=' => new \DateTime('now'), 'Lancamentos.data <=' => $dtCadastro->modify('+30 days'), 'Lancamentos.consolidado' => 'N']])->toArray(); $this->set('lancamentos', $lancamentos); }
public function scheduleFutureJobs($ignoreId = null) { Time::setToStringFormat('y-MM-dd HH:mm:ss'); $thisTaskName = preg_replace('/^Queue/', '', $this->name); $existingJobsQuery = $this->QueuedTasks->find()->where(['jobtype' => $thisTaskName]); $existingJobs = []; foreach ($existingJobsQuery as $job) { $existingJobs[(string) $job->notbefore] = $job->id == $ignoreId; } //All future jobs should run on September 1 //Scheduling five years out, just because $currentYear = intval(date('Y')); $now = new Time(); for ($year = $currentYear; $year <= $currentYear + 5; $year++) { $date = new Time("{$year}-09-01"); if ($date <= $now) { //Running this sometime after September 1, so do not //re-schedule for the past continue; } //This date is already scheduled if (array_key_exists((string) $date, $existingJobs)) { $existingJobs[(string) $date] = true; continue; } $this->QueuedTasks->createJob($thisTaskName, null, $date); } //Clean out any previously-set "future" dates that have been removed //(e.g. if "September 1" default date is changed) foreach ($existingJobs as $notBefore => $matched) { if ($matched) { continue; } $this->QueuedTasks->deleteAll(['notbefore' => $notBefore]); } }
/** * Tests that __toString uses the i18n formatter * * @return void */ public function testToString() { $time = new Time('2014-04-20 22:10'); Time::$defaultLocale = 'fr-FR'; Time::setToStringFormat(\IntlDateFormatter::FULL); $this->assertTimeFormat('dimanche 20 avril 2014 22:10:00 UTC', (string) $time); }
<?php namespace App\Controller; use App\Controller\AppController; use Cake\I18n\Time; use Cake\ORM\TableRegistry; use Cake\Database\Type\DateTimeTyp; Time::setToStringFormat('YYYY-MM-dd'); /** * BrandDiscounts Controller * * @property \App\Model\Table\BrandDiscountsTable $BrandDiscounts */ class BrandDiscountsController extends AppController { /** * Index method * * @return void */ public function index() { $this->paginate = ['contain' => ['Vendors']]; $this->set('brandDiscounts', $this->paginate($this->BrandDiscounts)); $this->set('_serialize', ['brandDiscounts']); } /** * View method * * @param string|null $id Brand Discount id.
* Licensed under The MIT License * For full copyright and license information, please see the LICENSE.txt * Redistributions of files must retain the above copyright notice. * * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project * @since 0.2.9 * @license http://www.opensource.org/licenses/mit-license.php MIT License */ namespace App\Controller; use Cake\Controller\Controller; use Cake\Event\Event; use Cake\I18n\Time; Time::$defaultLocale = 'es-ES'; Time::setToStringFormat('dd-MM-YYYY'); /** * Application Controller * * Add your application-wide methods in the class below, your controllers * will inherit them. * * @link http://book.cakephp.org/3.0/en/controllers.html#the-app-controller */ class AppController extends Controller { /** * Initialization hook method. * * Use this method to add common initialization code like loading components. *
/** * Edit method * * @param string|null $id Order id. * @return void Redirects on successful edit, renders view otherwise. * @throws \Cake\Network\Exception\NotFoundException When record not found. */ public function edit($id = null) { //configure the date for this method only . Time::setToStringFormat('YYYY-MM-dd'); $order = $this->Orders->get($id, ['contain' => []]); //hard code the result for the courier since we ran out of time. //pre set the ordered_dates //$order->ordered_date = date("Y-m-d"); $order->courier_id = "1"; if ($this->request->is(['patch', 'post', 'put'])) { $order = $this->Orders->patchEntity($order, $this->request->data); if ($this->Orders->save($order)) { //show the user that the order was updated $this->Flash->success('The order has been saved.'); //send email to rick to let him know an order has been changed, one line email call. return $this->redirect(['action' => 'index']); } else { $this->Flash->error('The order could not be saved. Please, try again.'); } } $couriers = $this->Orders->Couriers->find('list', ['limit' => 200]); $customers = $this->Orders->Customers->find('list', ['limit' => 200]); $this->set(compact('order', 'couriers', 'customers')); $this->set('_serialize', ['order']); }
* Redistributions of files must retain the above copyright notice. * * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project * @since 0.2.9 * @license http://www.opensource.org/licenses/mit-license.php MIT License */ namespace App\Controller; use Cake\Controller\Controller; use Cake\Database\Type; use Cake\Event\Event; use Cake\I18n\Time; use Cake\Utility\Text; Time::$defaultLocale = 'en_US'; Time::setToStringFormat('MMM d, Y h:mm a'); Type::build('datetime')->useLocaleParser(); /** * Application Controller * * Add your application-wide methods in the class below, your controllers * will inherit them. * * @link http://book.cakephp.org/3.0/en/controllers.html#the-app-controller */ class AppController extends Controller { /** * Initialization hook method. * * Use this method to add common initialization code like loading components.
* Set server timezone to UTC. You can change it to another timezone of your * choice but using UTC makes time calculations / conversions easier. */ date_default_timezone_set('America/Sao_Paulo'); /** * Configure the mbstring extension to use the correct encoding. */ mb_internal_encoding(Configure::read('App.encoding')); /** * Set the default locale. This controls how dates, number and currency is * formatted and sets the default language to use for translations. */ ini_set('intl.default_locale', 'pt_BR'); setlocale(LC_ALL, 'pt_BR'); Time::$defaultLocale = 'pt-BR'; Time::setToStringFormat('dd/MM/YYYY'); /** * Register application error and exception handlers. */ $isCli = php_sapi_name() === 'cli'; if ($isCli) { (new ConsoleErrorHandler(Configure::read('Error')))->register(); } else { (new ErrorHandler(Configure::read('Error')))->register(); } // Include the CLI bootstrap overrides. if ($isCli) { require __DIR__ . '/bootstrap_cli.php'; } /** * Set the full base URL.