예제 #1
0
 /**
  * Parses a rudimentary system log backend page
  * @param \Cx\Core\Html\Sigma $template Backend template for this page
  * @param array $cmd Supplied CMD
  */
 public function parsePage(\Cx\Core\Html\Sigma $template, array $cmd)
 {
     $em = $this->cx->getDb()->getEntityManager();
     $logRepo = $em->getRepository('Cx\\Core_Modules\\SysLog\\Model\\Entity\\Log');
     // @todo: parse message if no entries (template block exists already)
     $parseObject = $this->getNamespace() . '\\Model\\Entity\\Log';
     // set default sorting
     if (!isset($_GET['order'])) {
         $_GET['order'] = 'timestamp/DESC';
     }
     $parseObject = new \Cx\Core_Modules\Listing\Model\Entity\DataSet(array());
     // setDataType is used to make the ViewGenerator load the proper options if $parseObject is empty
     $parseObject->setDataType('Cx\\Core_Modules\\SysLog\\Model\\Entity\\Log');
     // configure view
     $viewGenerator = new \Cx\Core\Html\Controller\ViewGenerator($parseObject, $this->getAllViewGeneratorOptions());
     $template->setVariable('ENTITY_VIEW', $viewGenerator);
 }
예제 #2
0
 public function testSortColumns()
 {
     $testSet = new \Cx\Core_Modules\Listing\Model\Entity\DataSet($this->testArray);
     $testSet->sortColumns(array('field2', 'field1'));
     $this->assertEquals($this->sortedColumnsArray, $testSet->toArray());
 }
 public function showSubscriptions()
 {
     global $_ARRAYLANG;
     $term = isset($_GET['term']) ? contrexx_input2raw($_GET['term']) : '';
     $filterProduct = isset($_GET['filter_product']) ? contrexx_input2raw($_GET['filter_product']) : array();
     $filterState = isset($_GET['filter_state']) ? contrexx_input2raw($_GET['filter_state']) : array();
     if (!empty($term) || !empty($filterProduct) || !empty($filterState)) {
         $filter = array('term' => $term, 'filterProduct' => $filterProduct, 'filterState' => $filterState);
         $subscriptions = $this->subscriptionRepo->findSubscriptionsBySearchTerm($filter);
     } else {
         $subscriptions = $this->subscriptionRepo->getSubscriptionsByCriteria(null, array('s.id' => 'DESC'));
     }
     $subscriptions = new \Cx\Core_Modules\Listing\Model\Entity\DataSet($subscriptions);
     // setDataType is used to make the ViewGenerator load the proper options if $subscriptions is empty
     $subscriptions->setDataType('Cx\\Modules\\Order\\Model\\Entity\\Subscription');
     $products = \Env::get('em')->getRepository('Cx\\Modules\\Pim\\Model\\Entity\\Product')->findAll();
     $this->getSearchFilterDropDown($products, $filterProduct, 'product');
     $subscriptionStates = array(\Cx\Modules\Order\Model\Entity\Subscription::STATE_ACTIVE, \Cx\Modules\Order\Model\Entity\Subscription::STATE_INACTIVE, \Cx\Modules\Order\Model\Entity\Subscription::STATE_TERMINATED, \Cx\Modules\Order\Model\Entity\Subscription::STATE_CANCELLED);
     $this->getSearchFilterDropDown($subscriptionStates, $filterState, 'state');
     $options = $this->getController('Backend')->getAllViewGeneratorOptions();
     $view = new \Cx\Core\Html\Controller\ViewGenerator($subscriptions, $options);
     $this->template->setVariable(array('TXT_ORDER_SUBSCRIPTIONS_FILTER' => $_ARRAYLANG['TXT_MODULE_ORDER_FILTER'], 'TXT_ORDER_SUBSCRIPTIONS_SEARCH' => $_ARRAYLANG['TXT_MODULE_ORDER_SEARCH'], 'TXT_ORDER_SUBSCRIPTIONS_SEARCH_TERM' => $_ARRAYLANG['TXT_MODULE_ORDER_SEARCH_TERM'], 'ORDER_SUBSCRIPTIONS_SEARCH_VALUE' => contrexx_raw2xhtml($term)));
     if (isset($_GET['editid']) && !empty($_GET['editid']) || isset($_GET['add']) && !empty($_GET['add'])) {
         $this->template->hideBlock("subscription_filter");
     }
     $this->template->setVariable('SUBSCRIPTIONS_CONTENT', $view->render());
 }
예제 #4
0
 /**
  * Delete one or more records from the File   
  *
  * For maintenance/update purposes only.
  * At least one of the parameter values must be non-empty.
  * It will fail if both are empty.  Mind that in this case,
  * no records will be deleted.
  * Does {@see flush()} the currently loaded settings on success.
  * @param   string    $name     The optional setting name.
  *                              Defaults to null
  * @param   string    $group      The optional group.
  *                              Defaults to null
  * @return  boolean             True on success, false otherwise
  */
 function delete($name = null, $group = null)
 {
     // Fail if both parameter values are empty
     if (empty($name) && empty($group) && empty($this->section)) {
         return false;
     }
     $arrSetting = array();
     $objDataSet = \Cx\Core_Modules\Listing\Model\Entity\DataSet::load($this->filename);
     // if get blank or invalid file
     if (empty($objDataSet)) {
         return false;
     }
     foreach ($objDataSet as $value) {
         if ($value['group'] != $group && $value['name'] != $name) {
             $arrSetting[$value['name']] = $value;
         }
     }
     // if get blank array
     if (empty($arrSetting)) {
         return false;
     }
     $objDataSet = new \Cx\Core_Modules\Listing\Model\Entity\DataSet($arrSetting);
     $objDataSet->exportToFile(new \Cx\Core_Modules\Listing\Model\Entity\YamlInterface(), $this->filename);
     return true;
 }
 /**
  * Gets one or more entries from this DataSource
  *
  * If an argument is not provided, no restriction is made for this argument.
  * So if this is called without any arguments, all entries of this
  * DataSource are returned.
  * If no entry is found, an empty array is returned.
  * @param string $elementId (optional) ID of the element if only one is to be returned
  * @param array $filter (optional) field=>value-type condition array, only supports = for now
  * @param array $order (optional) field=>order-type array, order is either "ASC" or "DESC"
  * @param int $limit (optional) If set, no more than $limit results are returned
  * @param int $offset (optional) Entry to start with
  * @param array $fieldList (optional) Limits the result to the values for the fields in this list
  * @throws \Exception If doctrine repository for this DataSource could not be found
  * @return array Two dimensional array (/table) of results (array($row=>array($fieldName=>$value)))
  */
 public function get($elementId = null, $filter = array(), $order = array(), $limit = 0, $offset = 0, $fieldList = array())
 {
     $repo = $this->getRepository();
     $em = $this->cx->getDb()->getEntityManager();
     $criteria = array();
     // $filter
     if (count($fieldList)) {
         foreach ($filter as $field => $value) {
             if (!in_array($field, $fieldList)) {
                 continue;
             }
             $criteria[$field] = $value;
         }
     }
     // $elementId
     if (isset($elementId)) {
         $meta = $em->getClassMetadata($this->getIdentifier());
         $identifierField = $meta->getSingleIdentifierFieldName();
         $criteria[$identifierField] = $elementId;
     }
     // $order
     foreach ($order as $field => $ascdesc) {
         if (!in_array($field, $fieldList) || !in_array($ascdesc, array('ASC', 'DESC'))) {
             unset($order[$field]);
         }
     }
     // order, limit and offset are not supported by our doctrine version
     // yet! This would be the nice way to solve this:
     /*$result = $repo->findBy(
           $criteria,
           $order,
           (int) $limit,
           (int) $offset
       );//*/
     // but for now we'll have to:
     $qb = $em->createQueryBuilder();
     $qb->select('x')->from($this->getIdentifier(), 'x');
     // $filter
     $i = 1;
     foreach ($criteria as $field => $value) {
         $qb->andWhere($qb->expr()->eq('x.' . $field, '?' . $i));
         $qb->setParameter($i, $value);
         $i++;
     }
     // $order, $limit, $offset
     foreach ($order as $field => $ascdesc) {
         $qb->orderBy('x.' . $field, $ascdesc);
     }
     // $limit, $offset
     if ($limit) {
         $qb->setMaxResults($limit);
         if ($offset) {
             $qb->setFirstResult($offset);
         }
     }
     $result = $qb->getQuery()->getResult(\Doctrine\ORM\AbstractQuery::HYDRATE_ARRAY);
     // $fieldList
     $dataSet = new \Cx\Core_Modules\Listing\Model\Entity\DataSet($result);
     if (count($fieldList)) {
         $dataFlipped = $dataSet->flip()->toArray();
         foreach ($dataFlipped as $key => $value) {
             if (!in_array($key, $fieldList)) {
                 unset($dataFlipped[$key]);
             }
         }
         $dataSetFlipped = new \Cx\Core_Modules\Listing\Model\Entity\DataSet($dataFlipped);
         $dataSet = $dataSetFlipped->flip();
     }
     return $dataSet->toArray();
 }
예제 #6
0
 /**
  * Flush the current state of the repository into the file system.
  */
 public function flush()
 {
     if (\Env::get('cx')->getMode() == \Cx\Core\Core\Controller\Cx::MODE_MINIMAL) {
         \DBG::msg('WARNING: ' . __METHOD__ . '() initialized in Cx mode "' . \Cx\Core\Core\Controller\Cx::MODE_MINIMAL . '". EventListeners have not yet been registered. This might break the system! Flushing a repository at this point is highly unadvisable!');
     }
     $entitiesToPersist = array();
     foreach ($this->entities as $entity) {
         // Validation must be done before checking for virtual entities.
         // As even virtual entities must comply with the unique-key restrictions.
         $this->validate($entity);
         if ($entity->isVirtual()) {
             if (!isset($this->originalEntitiesFromRepository[$this->getIdentifierOfEntity($entity)])) {
                 continue;
             }
         }
         if (isset($this->originalEntitiesFromRepository[$this->getIdentifierOfEntity($entity)])) {
             if ($this->originalEntitiesFromRepository[$this->getIdentifierOfEntity($entity)] != $entity) {
                 $this->updatedEntities[] = $entity;
             }
         }
         $entitiesToPersist[$this->getIdentifierOfEntity($entity)] = $entity;
     }
     foreach ($this->updatedEntities as $entity) {
         \Env::get('cx')->getEvents()->triggerEvent('model/preUpdate', array(new \Doctrine\ORM\Event\LifecycleEventArgs($entity, \Env::get('em'))));
     }
     $this->prepareFile($this->repositoryPath, $this->entityUniqueKeys, $this->entityIdentifier);
     $dataSet = new \Cx\Core_Modules\Listing\Model\Entity\DataSet();
     $dataSet->add('data', $entitiesToPersist);
     $dataSet->add('meta', $this->getMetaDefinition());
     $dataSet->save($this->repositoryPath);
     // triger post-events
     // apply the same order of event-triggers as doctrine does:
     // 1. postPersist
     // 2. postUpdate
     // 3. postRemove
     foreach ($this->addedEntities as $entity) {
         \Env::get('cx')->getEvents()->triggerEvent('model/postPersist', array(new \Doctrine\ORM\Event\LifecycleEventArgs($entity, \Env::get('em'))));
     }
     foreach ($this->updatedEntities as $entity) {
         \Env::get('cx')->getEvents()->triggerEvent('model/postUpdate', array(new \Doctrine\ORM\Event\LifecycleEventArgs($entity, \Env::get('em'))));
     }
     foreach ($this->removedEntities as $entity) {
         \Env::get('cx')->getEvents()->triggerEvent('model/postRemove', array(new \Doctrine\ORM\Event\LifecycleEventArgs($entity, \Env::get('em'))));
     }
     //truncate the variables
     $this->addedEntities = array();
     $this->updatedEntities = array();
     $this->removedEntities = array();
     \Env::get('cx')->getEvents()->triggerEvent('model/postFlush', array(new \Doctrine\ORM\Event\OnFlushEventArgs(\Env::get('em')), $this->repositoryPath));
 }
예제 #7
0
 public function showOrders()
 {
     global $_ARRAYLANG;
     $term = isset($_GET['filter-term']) ? contrexx_input2raw($_GET['filter-term']) : '';
     $filterUserId = isset($_GET['filter-user-id']) ? contrexx_input2raw($_GET['filter-user-id']) : 0;
     $objFilterUser = null;
     if (!empty($term) || !empty($filterUserId)) {
         if ($filterUserId) {
             $objFilterUser = \FWUser::getFWUserObject()->objUser->getUser($filterUserId);
         }
         $orders = $this->orderRepository->findOrdersBySearchTerm($term, $objFilterUser);
     } else {
         $orders = $this->orderRepository->getAllByDesc();
     }
     $orders = new \Cx\Core_Modules\Listing\Model\Entity\DataSet($orders);
     // setDataType is used to make the ViewGenerator load the proper options if $orders is empty
     $orders->setDataType('Cx\\Modules\\Order\\Model\\Entity\\Order');
     $options = $this->getController('Backend')->getAllViewGeneratorOptions();
     $view = new \Cx\Core\Html\Controller\ViewGenerator($orders, $options);
     if (isset($_GET['editid']) && !empty($_GET['editid']) || isset($_GET['add']) && !empty($_GET['add'])) {
         $this->template->hideBlock("order_filter");
     } else {
         \FWUser::getUserLiveSearch(array('minLength' => 1, 'canCancel' => true, 'canClear' => true));
         $this->template->setVariable(array('TXT_MODULE_ORDER_SEARCH' => $_ARRAYLANG['TXT_MODULE_ORDER_SEARCH'], 'TXT_MODULE_ORDER_FILTER' => $_ARRAYLANG['TXT_MODULE_ORDER_FILTER'], 'TXT_MODULE_ORDER_SEARCH_TERM' => $_ARRAYLANG['TXT_MODULE_ORDER_SEARCH_TERM'], 'ORDER_SEARCH_VALUE' => isset($_GET['filter-term']) ? contrexx_input2xhtml($_GET['filter-term']) : '', 'ORDER_USER_ID' => contrexx_raw2xhtml($filterUserId), 'ORDER_USER_NAME' => $objFilterUser ? contrexx_raw2xhtml(\FWUser::getParsedUserTitle($objFilterUser)) : ''));
     }
     $this->template->setVariable('ORDERS_CONTENT', $view->render());
 }