Exemplo n.º 1
0
 protected function execute()
 {
     switch ($this->mode) {
         case self::MODE_DQL:
             $this->result = '';
             $strQuery = trim($this->code);
             $lister = new \Cx\Core_Modules\Listing\Controller\ListingController(function (&$offset, &$count, &$criteria, &$order) use($strQuery) {
                 return \Env::get('em')->createQuery($strQuery);
             });
             try {
                 $table = new \BackendTable($lister->getData());
                 $this->result = $table->toHtml() . $lister;
             } catch (\Exception $e) {
                 $this->result = 'Could not execute query (' . $e->getMessage() . ')!';
             }
             break;
         case self::MODE_PHP:
             $dbgMode = \DBG::getMode();
             try {
                 // This error handler catches all Warnings and Notices and some Strict errors
                 \DBG::activate(DBG_PHP);
                 set_error_handler(array($this, 'phpErrorsAsExceptionsHandler'));
                 $this->errrorHandlerActive = true;
                 // Since DBG catches the rest (E_PARSE) let's use that
                 ob_start();
                 $function = create_function('$em, $cx', '' . $this->code . ';');
                 $dbgContents = ob_get_clean();
                 \DBG::activate($dbgMode);
                 if (!is_callable($function)) {
                     // parse exception
                     throw new SandboxException($dbgContents);
                 }
                 $this->result = var_export($function(\Env::get('em'), \Env::get('cx')), true);
                 restore_error_handler();
                 $this->errrorHandlerActive = false;
             } catch (\Exception $e) {
                 \DBG::activate($dbgMode);
                 restore_error_handler();
                 $this->errrorHandlerActive = false;
                 $this->result = get_class($e) . ': ' . $e->getMessage();
             }
             break;
         default:
             break;
     }
 }
Exemplo n.º 2
0
 /**
  * This function finds out what we want to render and then renders the form
  *
  * @param boolean $isSingle if we only render one entry
  * @access public
  * @return string rendered view
  */
 public function render(&$isSingle = false)
 {
     global $_ARRAYLANG;
     // this case is used to generate the add entry form, where we can create an new entry
     if (!empty($_GET['add']) && !empty($this->options['functions']['add'])) {
         $isSingle = true;
         return $this->renderFormForEntry(null);
     }
     $renderObject = $this->object;
     $entityId = $this->getEntryId();
     // this case is used to get the right entry if we edit a existing one
     if ($this->object instanceof \Cx\Core_Modules\Listing\Model\Entity\DataSet && $entityId != 0) {
         if ($this->object->entryExists($entityId)) {
             $renderObject = $this->object->getEntry($entityId);
         }
     }
     // this case is used for the overview off all entities
     if ($renderObject instanceof \Cx\Core_Modules\Listing\Model\Entity\DataSet) {
         if (!empty($this->options['order']['overview'])) {
             $renderObject->sortColumns($this->options['order']['overview']);
         }
         $addBtn = '';
         $actionUrl = clone \Env::get('cx')->getRequest()->getUrl();
         if (!empty($this->options['functions']['add'])) {
             $actionUrl->setParam('add', 1);
             //remove the parameter 'vg_increment_number' from actionUrl
             //if the baseUrl contains the parameter 'vg_increment_number'
             $params = $actionUrl->getParamArray();
             if (isset($params['vg_increment_number'])) {
                 \Html::stripUriParam($actionUrl, 'vg_increment_number');
             }
             $addBtn = '<br /><br /><input type="button" name="addEtity" value="' . $_ARRAYLANG['TXT_ADD'] . '" onclick="location.href=' . "'" . $actionUrl . "&csrf=" . \Cx\Core\Csrf\Controller\Csrf::code() . "'" . '" />';
         }
         if (!count($renderObject) || !count(current($renderObject))) {
             // make this configurable
             $tpl = new \Cx\Core\Html\Sigma(\Env::get('cx')->getCodeBaseCorePath() . '/Html/View/Template/Generic');
             $tpl->loadTemplateFile('NoEntries.html');
             return $tpl->get() . $addBtn;
         }
         $listingController = new \Cx\Core_Modules\Listing\Controller\ListingController($renderObject, array(), $this->options['functions']);
         $renderObject = $listingController->getData();
         $this->options['functions']['vg_increment_number'] = $this->viewId;
         $backendTable = new \BackendTable($renderObject, $this->options) . '<br />' . $listingController;
         return $backendTable . $addBtn;
     }
     // render form for single entry view like editEntry
     $isSingle = true;
     return $this->renderFormForEntry($entityId);
 }
Exemplo n.º 3
0
 public function render(&$isSingle = false)
 {
     global $_ARRAYLANG;
     if (!empty($_GET['add']) && !empty($this->options['functions']['add'])) {
         $isSingle = true;
         return $this->renderFormForEntry(null);
     }
     $renderObject = $this->object;
     $entityClass = get_class($this->object);
     $entityId = '';
     if ($this->object instanceof \Cx\Core_Modules\Listing\Model\Entity\DataSet && $this->isInEditMode()) {
         $entityClass = $this->object->getDataType();
         $entityId = contrexx_input2raw($this->isInEditMode());
         if ($this->object->entryExists($entityId)) {
             $renderObject = $this->object->getEntry($entityId);
         }
     }
     if ($renderObject instanceof \Cx\Core_Modules\Listing\Model\Entity\DataSet) {
         if (!empty($this->options['order']['overview'])) {
             $renderObject->sortColumns($this->options['order']['overview']);
         }
         $addBtn = '';
         $actionUrl = clone \Env::get('cx')->getRequest()->getUrl();
         if (!empty($this->options['functions']['add'])) {
             $actionUrl->setParam('add', 1);
             $addBtn = '<br /><br /><input type="button" name="addEtity" value="' . $_ARRAYLANG['TXT_ADD'] . '" onclick="location.href=' . "'" . $actionUrl . "&csrf=" . \Cx\Core\Csrf\Controller\Csrf::code() . "'" . '" />';
         }
         if (!count($renderObject) || !count(current($renderObject))) {
             // make this configurable
             $tpl = new \Cx\Core\Html\Sigma(\Env::get('cx')->getCodeBaseCorePath() . '/Html/View/Template/Generic');
             $tpl->loadTemplateFile('NoEntries.html');
             return $tpl->get() . $addBtn;
         }
         $listingController = new \Cx\Core_Modules\Listing\Controller\ListingController($renderObject, array(), $this->options['functions']);
         $renderObject = $listingController->getData();
         $this->options['functions']['vg_increment_number'] = $this->number;
         $backendTable = new \BackendTable($renderObject, $this->options) . '<br />' . $listingController;
         return $backendTable . $addBtn;
     } else {
         $isSingle = true;
         return $this->renderFormForEntry($entityId);
     }
 }