Retrieve the user.
public getUser ( ) : sfUser | ||
리턴 | sfUser | The current sfUser implementation instance. |
/** * Attempts to return the theme for the current request * * This first throws a sympal.theme.set_theme_from_request event, giving * anyone the opportunity to determine the theme. If this event is not * handled, we continue with some default rules for setting themes. * * @param sfContext $context * @param array An array of valid themes, to be used for user-entered themes * * @return string The theme (defaults to the default theme) */ public function getThemeForRequest(sfContext $context, $validThemes) { $event = $context->getEventDispatcher()->notifyUntil(new sfEvent($this, 'theme.set_theme_from_request', array('context' => $context))); if ($event->isProcessed()) { return $event->getReturnValue(); } if ($this->getOption('allow_changing_theme_by_url', true)) { $user = $context->getUser(); $request = $context->getRequest(); if ($theme = $request->getParameter($this->getOption('theme_request_parameter_name', 'sf_theme'))) { // make sure the theme is valid if (in_array($theme, $validThemes)) { $user->setCurrentTheme($theme); return $theme; } else { // unset the user attribute $user->setCurrentTheme(false); } } if ($theme = $user->getCurrentTheme()) { return $theme; } } // Get the theme from module/route. False is a valid response (don't set theme) $module = $context->getModuleName(); $route = $context->getRouting()->getCurrentRouteName(); $theme = $this->getThemeFromConfig($module, $route); if ($theme || $theme === false) { return $theme; } return $this->getOption('default_theme'); }
/** * Initializes this Filter. * * @param sfContext $context The current application context * @param array $parameters An associative array of initialization parameters * * @return boolean true */ public function initialize($context, $parameters = array()) { $this->request = $context->getRequest(); $this->response = $context->getResponse(); $this->user = $context->getUser(); return parent::initialize($context, $parameters); }
<?php /* * This file is part of the symfony package. * (c) 2004-2006 Fabien Potencier <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require_once dirname(__FILE__) . '/../../bootstrap/unit.php'; require_once $_test_dir . '/unit/sfContextMock.class.php'; $t = new lime_test(48, new lime_output_color()); $context = new sfContext(); $context->getUser()->setCulture('en_US'); $v = new sfDateValidator(); $v->initialize($context); // ->execute() $t->diag('->execute()'); $validDates = array('2/21/2008', '02/01/1990', '12/31/2001', '2/29/2004'); $invalidDates = array('2/21', '2/29/2005', '3/32/2001', '13/1/2001', '2007ghgre7-1-120', 'foobar'); $validCompareDates = array(array('2/21/2008', '==', '2/21/2008'), array('2/21/2008', '>', '2/20/2007'), array('2/21/2008', '>=', '2/21/2008'), array('2/21/2008', '>=', '2/20/2007'), array('2/21/2008', '<', '3/22/2009'), array('2/21/2008', '<=', '3/22/2009'), array('2/21/2008', '<=', '2/21/2008')); $invalidCompareDates = array(array('2/1/2008', '==', '2/2/2008'), array('2/1/2008', '>', '2/2/2008'), array('2/1/2008', '>', '2/1/2008'), array('2/1/2008', '>=', '2/2/2008'), array('2/1/2008', '<', '1/31/2008'), array('2/1/2008', '<', '2/1/2008'), array('2/1/2008', '<=', '1/31/2008')); $v->initialize($context); foreach ($validDates as $value) { $error = null; $t->ok($v->execute($value, $error), sprintf('->execute() returns true for a valid date "%s"', $value)); $t->is($error, null, '->execute() doesn\'t change "$error" if it returns true'); } foreach ($invalidDates as $value) { $error = null; $t->ok(!$v->execute($value, $error), sprintf('->execute() returns false for an invalid date "%s"', $value));
protected function doGeneratePdf(sfContext $context, $chartBuilder, $file) { // definition of chart builder class $this->setChartBuilder($chartBuilder); // creation of a context $context->getConfiguration()->loadHelpers('Partial'); $context->getRequest()->setRequestFormat('html'); $config = sfTCPDFPluginConfigHandler::loadConfig(); sfTCPDFPluginConfigHandler::includeLangFile($context->getUser()->getCulture()); $doc_title = $this->getName() . " Report"; $doc_subject = $this->getName() . " Report generated by Otokou"; $doc_keywords = "report, otokou"; //create new PDF document (document units are set by default to millimeters) $pdf = new sfTCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true); // set document information $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor(PDF_AUTHOR); $pdf->SetTitle($doc_title); $pdf->SetSubject($doc_subject); $pdf->SetKeywords($doc_keywords); $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING); //set margins $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); //set auto page breaks $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); //set image scale factor $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); //initialize document $pdf->AliasNbPages(); // report informations $pdf->AddPage(); $html = get_partial('report/general_info', array('report' => $this)); $pdf->writeHTML($html, true, false, true, false, ''); // vehicles overall performances $html = '<h1>Vehicles performances</h1>' . '<p>The values presented below are calculated overall the entire life period of the vehicle(s).</p>' . get_partial('report/vehicles_performances', array('vehicles' => $this->getVehicles())); $pdf->writeHTML($html, true, false, true, false, ''); // charts $pdf->AddPage(); $html = '<h1>Costs</h1>'; $pdf->writeHTML($html, true, false, true, false, ''); $counter = 0; $options = array(); $attributes = array('absolute' => true); $charts = $this->defineCharts($options, $attributes); $nc = count($charts); foreach ($charts as $c) { $counter++; //$html = get_partial('report/chart', array('chart' => $c)); //$pdf->writeHTML($html, true, false, true, false, ''); $html = '<h2>' . $c['title'] . '</h2><p>' . $c['comment'] . '</p>'; $pdf->writeHTML($html); $c['chart']->generate(); $pdf->Image($c['chart']->getChartFileSystemPath()); if ($counter < $nc) { $pdf->AddPage(); } } // Close and output PDF document $pdf->Output($file, 'F'); }