コード例 #1
0
ファイル: csv.php プロジェクト: daodaoliang/nooku-framework
 /**
  * Return the views output
  *
  * @param KViewContext  $context A view context object
  * @return string   The output of the view
  */
 protected function _actionRender(KViewContext $context)
 {
     $rows = '';
     $columns = array();
     $entities = $this->getModel()->fetch();
     // Get the columns
     foreach ($entities as $entity) {
         $data = $entity->toArray();
         $columns = array_merge($columns + array_flip(array_keys($data)));
     }
     // Empty the column values
     foreach ($columns as $key => $value) {
         $columns[$key] = '';
     }
     //Create the rows
     foreach ($entities as $entity) {
         $data = $entity->toArray();
         $data = array_merge($columns, $data);
         $rows .= $this->_arrayToString(array_values($data)) . $this->eol;
     }
     // Create the header
     $header = $this->_arrayToString(array_keys($columns)) . $this->eol;
     // Set the content
     $this->setContent($header . $rows);
     return parent::_actionRender($context);
 }
コード例 #2
0
ファイル: vcard.php プロジェクト: daodaoliang/nooku-framework
 /**
  * Return the views output
  *
  * @param KViewContext	$context A view context object
  * @return string  The output of the view
  */
 protected function _actionRender(KViewContext $context)
 {
     //Set the filename
     $filename = $this->getObject('lib:filter.filename')->sanitize($this->_properties['FN']);
     $this->filename = $filename . '.vcf';
     //Render the vcard
     $data = 'BEGIN:VCARD';
     $data .= "\r\n";
     $data .= 'VERSION:2.1';
     $data .= "\r\n";
     foreach ($this->_properties as $key => $value) {
         $data .= "{$key}:{$value}";
         $data .= "\r\n";
     }
     $data .= 'REV:' . date('Y-m-d') . 'T' . date('H:i:s') . 'Z';
     $data .= "\r\n";
     $data .= 'END:VCARD';
     $data .= "\r\n";
     $this->setContent($data);
     parent::_actionRender($context);
 }
コード例 #3
0
ファイル: json.php プロジェクト: daodaoliang/nooku-framework
 /**
  * Render and return the views output
  *
  * If the view 'content'  is empty the output will be generated based on the model data, if it set it will
  * be returned instead.
  *
  * @param KViewContext  $context A view context object
  * @return string A RFC4627-compliant JSON string, which may also be embedded into HTML.
  */
 protected function _actionRender(KViewContext $context)
 {
     if (empty($this->_content)) {
         $this->_content = $this->_renderData();
         $this->_processLinks($this->_content);
     }
     //Serialise
     if (!is_string($this->_content)) {
         // Root should be JSON object, not array
         if (is_array($this->_content) && count($this->_content) === 0) {
             $this->_content = new ArrayObject();
         }
         // Encode <, >, ', &, and " for RFC4627-compliant JSON, which may also be embedded into HTML.
         $this->_content = json_encode($this->_content, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT);
     }
     return parent::_actionRender($context);
 }
コード例 #4
0
 /**
  * Return the views output
  *
  * @param KViewContext  $context A view context object
  * @return string  The output of the view
  */
 protected function _actionRender(KViewContext $context)
 {
     $format = $this->getFormat();
     //format cannot be changed through context
     $layout = $context->layout;
     if (!parse_url($layout, PHP_URL_SCHEME)) {
         //Handle partial layout paths
         if (is_string($layout) && strpos($layout, '.') === false) {
             $identifier = $this->getIdentifier()->toArray();
             $identifier['name'] = $layout;
             unset($identifier['path'][0]);
             $layout = (string) $this->getIdentifier($identifier);
         }
     }
     $data = KObjectConfig::unbox($context->data);
     //Render the template
     $this->_content = $this->getTemplate()->loadFile((string) $layout . '.' . $format)->setParameters($context->parameters)->render($data);
     return parent::_actionRender($context);
 }