Gc\View\Collection::getViews PHP Method

getViews() public method

Get views
public getViews ( boolean $forceReload = false ) : array
$forceReload boolean To initiliaze views
return array
    public function getViews($forceReload = false)
    {
        if ($forceReload) {
            $select = new Select();
            $select->order(array('name'));
            $select->from('view');
            if ($this->getDocumentTypeId() !== null) {
                $select->join('document_type_view', 'document_type_view.view_id = view.id', array());
                $select->where->equalTo('document_type_view.document_type_id', $this->getDocumentTypeId());
            }
            $rows = $this->fetchAll($select);
            $views = array();
            foreach ($rows as $row) {
                $views[] = Model::fromArray((array) $row);
            }
            $this->setData('views', $views);
        }
        return $this->getData('views');
    }

Usage Example

Example #1
0
 /**
  * Send a file to the browser
  *
  * @return \Zend\Stdlib\ResponseInterface
  */
 public function downloadAction()
 {
     $viewId = $this->getRouteMatch()->getParam('id', null);
     if (!empty($viewId)) {
         $view = View\Model::fromId($viewId);
         if (empty($view)) {
             $this->flashMessenger()->addErrorMessage('This view can not be download');
             return $this->redirect()->toRoute('development/view/edit', array('id' => $viewId));
         }
         $content = $view->getContent();
         $filename = $view->getIdentifier() . '.phtml';
     } else {
         $views = new View\Collection();
         $children = $views->getViews();
         $zip = new ZipArchive();
         $tmpFilename = tempnam(sys_get_temp_dir(), 'zip');
         $res = $zip->open($tmpFilename, ZipArchive::CREATE);
         if ($res === true) {
             foreach ($children as $child) {
                 $zip->addFromString($child->getIdentifier() . '.phtml', $child->getContent());
             }
             $zip->close();
             $content = file_get_contents($tmpFilename);
             $filename = 'views.zip';
             unlink($tmpFilename);
         }
     }
     if (empty($content) or empty($filename)) {
         $this->flashMessenger()->addErrorMessage('Can not save views');
         return $this->redirect()->toRoute('development/view');
     }
     $headers = new Headers();
     $headers->addHeaderLine('Pragma', 'public')->addHeaderLine('Cache-control', 'must-revalidate, post-check=0, pre-check=0')->addHeaderLine('Cache-control', 'private')->addHeaderLine('Expires', -1)->addHeaderLine('Content-Type', 'application/octet-stream')->addHeaderLine('Content-Transfer-Encoding', 'binary')->addHeaderLine('Content-Length', strlen($content))->addHeaderLine('Content-Disposition', 'attachment; filename=' . $filename);
     $response = $this->getResponse();
     $response->setHeaders($headers);
     $response->setContent($content);
     return $response;
 }
All Usage Examples Of Gc\View\Collection::getViews