fromId() public static method

Initiliaze from id
public static fromId ( integer $scriptId ) : Model
$scriptId integer Script id
return Model
Exemplo n.º 1
0
 /**
  * Test
  *
  * @return void
  */
 public function testFromFakeId()
 {
     $model = $this->object->fromId(10000);
     $this->assertFalse($model);
 }
Exemplo n.º 2
0
 /**
  * Send a file to the browser
  *
  * @return \Zend\Stdlib\ResponseInterface
  */
 public function downloadAction()
 {
     $scriptId = $this->getRouteMatch()->getParam('id', null);
     if (!empty($scriptId)) {
         $script = Script\Model::fromId($scriptId);
         if (empty($script)) {
             $this->flashMessenger()->addErrorMessage('This script can not be download');
             return $this->redirect()->toRoute('development/script/edit', array('id' => $scriptId));
         }
         $content = $script->getContent();
         $filename = $script->getIdentifier() . '.phtml';
     } else {
         $scripts = new Script\Collection();
         $children = $scripts->getScripts();
         $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 = 'scripts.zip';
             unlink($tmpFilename);
         }
     }
     if (empty($content) or empty($filename)) {
         $this->flashMessenger()->addErrorMessage('Can not save scripts');
         return $this->redirect()->toRoute('development/script');
     }
     $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;
 }