コード例 #1
0
ファイル: IcalRenderer.php プロジェクト: bix0r/Stjornvisi
 /**
  * Processes a view script and returns the output.
  *
  * @param  string|ModelInterface $nameOrModel The script/resource process, or a view model
  * @param  null|array|\ArrayAccess $values Values to use during rendering
  * @return string The script output.
  */
 public function render($nameOrModel, $values = null)
 {
     $string = "BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:-//hacksw/handcal//NONSGML v1.0//EN\n";
     foreach ($nameOrModel->getVariable('events') as $event) {
         $string .= "BEGIN:VEVENT\n";
         $string .= "UID:{$event->id}@stjornvisi.is\n";
         $string .= "DTSTART:{$event->event_time->format('Ymd\\THis')}\n";
         $string .= "DTEND:{$event->event_end->format('Ymd\\THis')}\n";
         if ($event->lat && $event->lng) {
             $string .= "GEO:{$event->lat};{$event->lng}\n";
         }
         $string .= "LOCATION:{$event->location}\n";
         $string .= "ORGANIZER;CN=\"" . ($event->groups ? implode(', ', array_map(function ($g) {
             return $g->name;
         }, $event->groups)) : 'Stjónvísisviðburður') . "\":no-reply@stjornvisi.is\n";
         $string .= "LOCATION:{$event->location}\n";
         $string .= "URL:http://{$_SERVER['SERVER_NAME']}/vidburdir/{$event->id}\n";
         $string .= "SUMMARY:{$event->subject}\n";
         $string .= "END:VEVENT\n";
     }
     $string .= "END:VCALENDAR";
     return $string;
 }
コード例 #2
0
ファイル: Layout.php プロジェクト: adamdyson/ConLayout
 /**
  *
  * @param ViewModel $block
  * @return string
  */
 protected function determineAnonymousBlockId(ModelInterface $block)
 {
     $blockId = $block->getVariable(self::BLOCK_ID_VAR);
     if (!$blockId) {
         $blockId = sprintf(self::ANONYMOUS_ID_PATTERN, $block->captureTo(), self::$anonymousSuffix++);
         $block->setVariable(self::BLOCK_ID_VAR, $blockId);
     }
     return $blockId;
 }
 /**
  * Prepare the layout, if any.
  *
  * Injects the view model in the layout view model, if present.
  *
  * If the view model contains a non-empty 'layout' variable, that value
  * will be used to seed a layout view model, if:
  *
  * - it is a string layout template name
  * - it is a ModelInterface instance
  *
  * If a layout is discovered in this way, it will override the one set in
  * the constructor, if any.
  *
  * Returns the provided $viewModel unchanged if no layout is discovered;
  * otherwise, a view model representing the layout, with the provided
  * view model as a child, is returned.
  *
  * @param ModelInterface $viewModel
  * @return ModelInterface
  */
 private function prepareLayout(ModelInterface $viewModel)
 {
     $layout = $this->layout ? clone $this->layout : null;
     $providedLayout = $viewModel->getVariable('layout', false);
     if (is_string($providedLayout) && !empty($providedLayout)) {
         $layout = new ViewModel();
         $layout->setTemplate($providedLayout);
         $viewModel->setVariable('layout', null);
     } elseif ($providedLayout instanceof ModelInterface) {
         $layout = $providedLayout;
         $viewModel->setVariable('layout', null);
     }
     if ($layout) {
         $layout->addChild($viewModel);
         $viewModel = $layout;
     }
     return $viewModel;
 }