Inheritance: extends Gc\Db\AbstractTable
コード例 #1
0
ファイル: Collection.php プロジェクト: gotcms/gotcms
 /**
  * Get scripts
  *
  * @param boolean $forceReload to initiliaze scripts
  *
  * @return array
  */
 public function getScripts($forceReload = false)
 {
     if ($forceReload or $this->getData('scripts') === null) {
         $rows = $this->fetchAll($this->select(function (Select $select) {
             $select->order('name ASC');
         }));
         $scripts = array();
         foreach ($rows as $row) {
             $scripts[] = Model::fromArray((array) $row);
         }
         $this->setData('scripts', $scripts);
     }
     return $this->getData('scripts');
 }
コード例 #2
0
ファイル: ContentTest.php プロジェクト: gotcms/gotcms
 protected function removeContent()
 {
     $this->documentType->delete();
     $this->property->delete();
     $this->tabModel->delete();
     $this->view->delete();
     $this->layout->delete();
     $this->script->delete();
     $this->datatype->delete();
     $this->document->delete();
     unset($this->documentType);
     unset($this->property);
     unset($this->tabModel);
     unset($this->view);
     unset($this->layout);
     unset($this->script);
     unset($this->datatype);
     unset($this->document);
 }
コード例 #3
0
ファイル: ScriptTest.php プロジェクト: gotcms/gotcms
 /**
  * Tears down the fixture, for example, closes a network connection.
  * This method is called after a test is executed.
  *
  * @return void
  */
 protected function tearDown()
 {
     unset($this->object);
     $this->script->delete();
     unset($this->script);
 }
コード例 #4
0
 /**
  * Test
  *
  * @return void
  */
 public function testDownloadActionWithoutId()
 {
     $scriptModel = ScriptModel::fromArray(array('name' => 'ScriptName', 'identifier' => 'ScriptIdentifier', 'content' => 'Content'));
     $scriptModel->save();
     $this->dispatch('/admin/development/script/download');
     $this->assertResponseStatusCode(200);
     $this->assertModuleName('GcDevelopment');
     $this->assertControllerName('ScriptController');
     $this->assertControllerClass('ScriptController');
     $this->assertMatchedRouteName('development/script/download');
     $scriptModel->delete();
 }
コード例 #5
0
ファイル: Script.php プロジェクト: gotcms/gotcms
 /**
  * Returns script from identifier.
  *
  * @param string $identifier Identifier
  * @param array  $params     Parameters
  *
  * @return mixed
  */
 public function __invoke($identifier, $params = array())
 {
     $script = ScriptModel::fromIdentifier($identifier);
     if (empty($script)) {
         return false;
     }
     $this->helperScriptParameters = $params;
     return include GC_TEMPLATE_PATH . '/script/' . $identifier . '.phtml';
 }
コード例 #6
0
ファイル: Model.php プロジェクト: gotcms/gotcms
 /**
  * Initiliaze from id
  *
  * @param integer $identifier Identifier
  *
  * @return \Gc\Script\Model
  */
 public static function fromIdentifier($identifier)
 {
     $scriptTable = new Model();
     $row = $scriptTable->fetchRow($scriptTable->select(array('identifier' => $identifier)));
     $scriptTable->events()->trigger(__CLASS__, 'before.load', $scriptTable);
     if (!empty($row)) {
         $scriptTable->setData((array) $row);
         $scriptTable->setOrigData();
         $scriptTable->events()->trigger(__CLASS__, 'after.load', $scriptTable);
         return $scriptTable;
     } else {
         $scriptTable->events()->trigger(__CLASS__, 'after.load.failed', $scriptTable);
         return false;
     }
 }
コード例 #7
0
ファイル: ModelTest.php プロジェクト: gotcms/gotcms
 /**
  * Test
  *
  * @return void
  */
 public function testDeleteWithWrongId()
 {
     $configuration = Registry::get('Application')->getConfig();
     if ($configuration['db']['driver'] == 'pdo_mysql') {
         $this->markTestSkipped('Mysql does not thrown exception.');
     }
     $this->setExpectedException('Gc\\Exception');
     $model = new Model();
     $model->setId('undefined');
     $this->assertFalse($model->delete());
 }
コード例 #8
0
ファイル: ScriptController.php プロジェクト: gotcms/gotcms
 /**
  * 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;
 }