Example #1
0
 /**
  * Renders the given content within the layout
  *
  * @param string $content
  * @return string
  */
 public function renderLayout($content)
 {
     $layout = new View();
     $layout->setScriptPath($this->auth->getLayoutScriptPath());
     $layout->assign(array('content' => $content, 'title' => $this->auth->getTitle(), 'view' => $this->view));
     return $layout->render($this->auth->getLayoutScript());
 }
 public function addPimpleResources()
 {
     $this->silex['paths'] = $this->silex->share(function () {
         return new Paths();
     });
     $this->silex['application-env'] = getenv('APPLICATION_ENV');
     $this->silex['debug'] = 'development' === $this->silex['application-env'] ? true : false;
     $this->silex->register(new MonologServiceProvider(), ['monolog.logfile' => $this->silex['paths']->getAppRoot() . '/logs/' . $this->silex['application-env'] . '.log', 'monolog.level' => Logger::WARNING]);
     $this->silex['view'] = function () {
         $view = new View();
         $view->registerHelper('inputtext', '\\Dewdrop\\View\\Helper\\BootstrapInputText')->registerHelper('select', '\\Dewdrop\\View\\Helper\\BootstrapSelect')->registerHelper('textarea', '\\Dewdrop\\View\\Helper\\BootstrapTextarea');
         return $view;
     };
     $this->silex['admin'] = $this->silex->share(function () {
         $admin = new SilexAdmin($this->silex);
         return $admin;
     });
     $this->silex['config'] = $this->silex->share(function () {
         $config = new Config();
         if (!$config->has($this->silex['application-env'])) {
             return $config->get('development');
         }
         return $config->get($this->silex['application-env']);
     });
     $this->silex['db'] = $this->silex->share(function () {
         $config = $this->silex['config'];
         $pdo = new PDO('pgsql:dbname=' . $config['db']['name'] . ';host=' . $config['db']['host'], $config['db']['username'], $config['db']['password']);
         $adapter = new DbAdapter();
         new Pgsql($adapter, $pdo);
         return $adapter;
     });
 }
 public function testNotExplicitlySettingDetectorWillCreateOne()
 {
     $view = new \Dewdrop\View\View();
     $field = $this->getTestField();
     $view->detectEditHelper()->customize($field, 'wpInputCheckbox');
     $output = $view->detectEditHelper()->render($field);
     $this->assertMatchesDomQuery('input[type="checkbox"]', $output);
 }
Example #4
0
 public function testCanOptionallySupplyCustomRenderer()
 {
     $fields = new Fields();
     $fields->add('custom')->setVisible(true)->setLabel('Custom')->assignHelperCallback('CsvCell.Content', function ($helper, $rowData) {
         return 'shouldnotberendered';
     })->add('not_visible')->setVisible(false)->setLabel('Unseen')->assignHelperCallback('CsvCell.Content', function ($helper, $rowData) {
         return 'content.unseen';
     });
     $renderer = $this->view->csvCellRenderer();
     $renderer->getContentRenderer()->assign('custom', function ($helper, $rowData) {
         return 'customrendering';
     });
     $output = $this->csvExportViewHelper->direct($fields, array(array('test_field' => 'FAFAFAFA')), $renderer);
     $this->assertContains('customrendering', $output);
     $this->assertNotContains('shouldnotberenderered', $output);
 }
Example #5
0
 /**
  * Provide some Pimple resources on top of what's available in the Standalone
  * bootstrap.
  */
 public function init()
 {
     $this->pimple['debug'] = $this->pimple->share(function () {
         /* @var $config Config */
         $config = $this->pimple['config'];
         return $config->has('debug') && $config->get('debug');
     });
     $this->pimple['db'] = $this->pimple->share(function () {
         /* @var $pdo \PDO */
         $pdo = Zend_Db_Table_Abstract::getDefaultAdapter()->getConnection();
         $adapter = new Adapter();
         $driver = new PgsqlDriver($adapter, $pdo);
         return $adapter;
     });
     $this->pimple['config'] = $this->pimple->share(function () {
         return new Config();
     });
     $this->pimple['view'] = $this->pimple->share(function () {
         $view = new View();
         $view->registerHelper('inputtext', '\\Dewdrop\\View\\Helper\\BootstrapInputText')->registerHelper('select', '\\Dewdrop\\View\\Helper\\BootstrapSelect')->registerHelper('textarea', '\\Dewdrop\\View\\Helper\\BootstrapTextarea');
         return $view;
     });
 }
Example #6
0
 /**
  * A fall back method for timestamp fields.  Will convert the DB value to a
  * Unix timestamp and then format it with PHP's date() function.  (How
  * retro!)  You can customize the format with setDateFormat().
  *
  * @param FieldInterface $field
  * @param array $rowData
  * @return string
  */
 protected function renderDbTimestamp(DbField $field, array $rowData)
 {
     $value = $rowData[$field->getName()];
     $timestamp = strtotime($value);
     // Hack for handling GMT offsets in WordPress.
     if ($timestamp && function_exists('get_option')) {
         $timezoneString = get_option('timezone_string');
         if ($timezoneString) {
             $offset = timezone_offset_get(new DateTimeZone($timezoneString), date_create($value));
             $timestamp += $offset;
         }
     }
     if ($timestamp) {
         return $this->view->escapeHtml(date($this->dateFormat . ' ' . $this->timeFormat, $timestamp));
     } else {
         return '';
     }
 }
 public function getExamples()
 {
     $view = new View();
     $view->setScriptPath(__DIR__ . '/view-scripts');
     return $view->render('group-column-not-set-examples.phtml');
 }
Example #8
0
 /**
  * Render the submit button for this action.
  *
  * @param View $view
  * @return string
  */
 public function render(View $view)
 {
     foreach ($this->stylesheets as $stylesheet) {
         $view->headLink()->appendStylesheet($stylesheet);
     }
     foreach ($this->scriptFiles as $file) {
         $view->headScript()->appendFile($file);
     }
     return sprintf('<input id="%s" name="%s" type="submit" class="%s" value="%s" />', $view->escapeHtmlAttr($this->id), $view->escapeHtmlAttr($this->id), $view->escapeHtmlAttr($this->buttonClassName), $view->escapeHtmlAttr($this->buttonTitle));
 }
Example #9
0
 /**
  * A fall back method for timestamp fields.  Will convert the DB value to a
  * Unix timestamp and then format it with PHP's date() function.  (How
  * retro!)  You can customize the format with setDateFormat().
  *
  * @param FieldInterface $field
  * @param array $rowData
  * @return string
  */
 protected function renderDbTimestamp(DbField $field, array $rowData)
 {
     $value = $rowData[$field->getName()];
     $timestamp = strtotime($value);
     return $this->view->escapeHtml(date($this->dateFormat . ' ' . $this->timeFormat, $timestamp));
 }
 /**
  * @return void
  */
 public function testGetHeadstyleFromView()
 {
     $headStyle = $this->view->headStyle();
     $this->assertInstanceOf('\\Zend\\View\\Helper\\HeadStyle', $headStyle);
 }
Example #11
0
 /**
  * Render a partial view.  By default, the same script path used by this
  * view is passed along.  This escaper from this view is also passed to
  * the partial.
  *
  * @param string $template
  * @param array $data
  * @param string $scriptPath
  * @return string
  */
 public function partial($template, array $data, $scriptPath = null)
 {
     $partial = new View($this->escaper);
     $partial->assignInstance('headscript', $this->headScript());
     $partial->assignInstance('headlink', $this->headLink());
     // Pass along any custom helper class assignments to the newly created partial
     foreach ($this->helperClasses as $name => $className) {
         $partial->registerHelper($name, $className);
     }
     foreach ($this->helpers as $name => $helper) {
         if ($helper instanceof PageDelegateInterface) {
             /* @var $partialHelper PageDelegateInterface */
             $partialHelper = $partial->helper($name);
             $partialHelper->setPage($helper->getPage());
         }
     }
     $partial->setScriptPath($scriptPath ?: $this->scriptPath)->assign($data);
     return $partial->render($template);
 }
Example #12
0
 /**
  * Render a partial view script.
  *
  * Generally, your helper should render HTML with partial view scripts
  * rather than generating the markup in the helper class directly.  This
  * makes it easier for frontend developers to make modifications to the HTML.
  *
  * The $data parameter should contain key-value pairs for each variable you'd
  * like available in your partial view.
  *
  * @param string $name
  * @param array $data
  * @return string The rendered output
  */
 public function partial($name, array $data)
 {
     return $this->view->partial($name, $data, __DIR__ . '/partials');
 }
Example #13
0
 /**
  * You can call renderView() directly from your render() method.  Or, if
  * your render method produces no output itself, the component will call
  * this method itself to automatically render your view script.
  *
  * @return string
  */
 public function renderView()
 {
     return $this->view->render($this->inflectViewScriptName());
 }
Example #14
0
 /**
  * If no custom callback is defined for a field, it will fall back to this
  * method to find a suitable callback.  In the case of the Header helper,
  * we fall back to all field's just returning their label.
  *
  * @param FieldInterface $field
  * @return callable
  */
 public function detectCallableForField(FieldInterface $field)
 {
     return function () use($field) {
         return $this->view->escapeHtml($field->getLabel());
     };
 }
 public function testCustomizeMethodCallsRelatedMethodOnDetectorObject()
 {
     $view = new View();
     $this->detector->expects($this->once())->method('customizeField')->with('model:field_name', 'wpSelect');
     $view->detectEditHelper()->setDetector($this->detector)->customize('model:field_name', 'wpSelect');
 }
Example #16
0
 /**
  * Enqueue the core Dewdrop client-side dependencies early in the process,
  * before the page is dispatched, so that they come before the page-specific
  * scripts.
  *
  * @param View $view
  * @return void
  */
 protected function enqueueClientSideDependencies(View $view)
 {
     global $wp_version;
     // Use jQuery and Backbone from WP core
     wp_enqueue_script('jquery-core');
     wp_enqueue_script('wp-backbone');
     $wpCoreScripts = array('jquery', 'backbone');
     // Enqueue non-WP core scripts
     foreach ($this->coreClientSideDependencies['js'] as $name => $script) {
         if (!in_array($name, $wpCoreScripts)) {
             wp_enqueue_script($name, $view->bowerUrl($script), ['jquery', 'wp-backbone'], $wp_version, true);
         }
     }
     wp_enqueue_style('bootstrap', $view->bowerUrl('/dewdrop/www/css/bootstrap-wp.css'));
     foreach ($this->coreClientSideDependencies['css'] as $name => $css) {
         // We need to use a special, prefixed version of the Bootstrap CSS for WP
         if ('bootstrap' !== $name) {
             wp_enqueue_style($name, $view->bowerUrl($css));
         }
     }
     wp_enqueue_style('dewdrop-admin-wp', $view->bowerUrl('/dewdrop/www/css/admin-wp.css'));
 }
 public function testUsage()
 {
     /* @var $csvCellFieldHelper \Dewdrop\Fields\Helper\CsvCell */
     $csvCellFieldHelper = $this->view->csvCellRenderer();
     $this->assertInstanceOf('\\Dewdrop\\Fields\\Helper\\CsvCell', $csvCellFieldHelper);
 }
 public function getExamples()
 {
     $view = new View();
     $view->setScriptPath(__DIR__ . '/view-scripts');
     return $view->render('group-key-not-present-in-resultset-examples.phtml');
 }