示例#1
0
 /**
  * this method returns an array
  *
  * @return array
  */
 public function buildArray()
 {
     /** @var \Thelia\Core\FileFormat\Formatting\FormatterManager $service */
     $service = $this->container->get("thelia.manager.formatter_manager");
     $rawFormatters = array_change_key_case($service->getAll());
     $exportId = $this->getExport();
     $formatters = [];
     if ($exportId !== null) {
         $export = ExportQuery::create()->findPk($exportId);
         if (null !== $export) {
             $handlerInstance = $export->getHandleClassInstance($this->container);
             $types = $handlerInstance->getHandledTypes();
             if (is_scalar($types)) {
                 $types = [$types];
             }
             /** @var \Thelia\Core\FileFormat\Formatting\AbstractFormatter $formatter */
             foreach ($rawFormatters as $key => $formatter) {
                 if (in_array($formatter->getHandledType(), $types)) {
                     $formatters[$key] = $formatter;
                 }
             }
         }
     } else {
         $formatters = $rawFormatters;
     }
     switch ($this->getOrder()) {
         case "alpha":
             ksort($formatters);
             break;
         case "alpha_reverse":
             krsort($formatters);
             break;
     }
     return $formatters;
 }
示例#2
0
 protected function getExport($id)
 {
     $export = ExportQuery::create()->findPk($id);
     if (null === $export) {
         throw new \ErrorException($this->getTranslator()->trans("There is no id \"%id\" in the exports", ["%id" => $id]));
     }
     return $export;
 }
示例#3
0
 /**
  * Returns the number of related Export objects.
  *
  * @param      Criteria $criteria
  * @param      boolean $distinct
  * @param      ConnectionInterface $con
  * @return int             Count of related Export objects.
  * @throws PropelException
  */
 public function countExports(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null)
 {
     $partial = $this->collExportsPartial && !$this->isNew();
     if (null === $this->collExports || null !== $criteria || $partial) {
         if ($this->isNew() && null === $this->collExports) {
             return 0;
         }
         if ($partial && !$criteria) {
             return count($this->getExports());
         }
         $query = ChildExportQuery::create(null, $criteria);
         if ($distinct) {
             $query->distinct();
         }
         return $query->filterByExportCategory($this)->count($con);
     }
     return count($this->collExports);
 }
示例#4
0
 protected function parseExports(SimpleXMLElement $xml)
 {
     if (false === ($exports = $xml->xpath('//config:exports/config:export'))) {
         return;
     }
     $con = Propel::getWriteConnection(ExportTableMap::DATABASE_NAME);
     $con->beginTransaction();
     try {
         /** @var SimpleXMLElement $export */
         foreach ($exports as $export) {
             $id = (string) $export->getAttributeAsPhp("id");
             $class = (string) $export->getAttributeAsPhp("class");
             $categoryRef = (string) $export->getAttributeAsPhp("category_id");
             if (!class_exists($class)) {
                 throw new \ErrorException("The class \"{$class}\" doesn't exist");
             }
             $category = ExportCategoryQuery::create()->findOneByRef($categoryRef);
             if (null === $category) {
                 throw new \ErrorException("The export category \"{$categoryRef}\" doesn't exist");
             }
             $exportModel = ExportQuery::create()->findOneByRef($id);
             if (null === $exportModel) {
                 $exportModel = new Export();
                 $exportModel->setRef($id);
             }
             $exportModel->setExportCategory($category)->setHandleClass($class)->save($con);
             /** @var SimpleXMLElement $descriptive */
             foreach ($export->children() as $descriptive) {
                 $locale = $descriptive->getAttributeAsPhp("locale");
                 $title = null;
                 $description = null;
                 /** @var SimpleXMLElement $row */
                 foreach ($descriptive->children() as $row) {
                     switch ($row->getName()) {
                         case "title":
                             $title = (string) $row;
                             break;
                         case "description":
                             $description = (string) $row;
                             break;
                     }
                 }
                 $exportModel->setLocale($locale)->setTitle($title)->setDescription($description)->save($con);
             }
         }
         $con->commit();
     } catch (\Exception $e) {
         $con->rollBack();
         Tlog::getInstance()->error($e->getMessage());
     }
 }
示例#5
0
文件: Export.php 项目: margery/thelia
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      ConnectionInterface $con
  * @return void
  * @throws PropelException
  * @see Export::setDeleted()
  * @see Export::isDeleted()
  */
 public function delete(ConnectionInterface $con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("This object has already been deleted.");
     }
     if ($con === null) {
         $con = Propel::getServiceContainer()->getWriteConnection(ExportTableMap::DATABASE_NAME);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = ChildExportQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         if ($ret) {
             $deleteQuery->delete($con);
             $this->postDelete($con);
             $con->commit();
             $this->setDeleted(true);
         } else {
             $con->commit();
         }
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
 }
示例#6
0
 /**
  * Performs an INSERT on the database, given a Export or Criteria object.
  *
  * @param mixed               $criteria Criteria or Export object containing data that is used to create the INSERT statement.
  * @param ConnectionInterface $con the ConnectionInterface connection to use
  * @return mixed           The new primary key.
  * @throws PropelException Any exceptions caught during processing will be
  *         rethrown wrapped into a PropelException.
  */
 public static function doInsert($criteria, ConnectionInterface $con = null)
 {
     if (null === $con) {
         $con = Propel::getServiceContainer()->getWriteConnection(ExportTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from Export object
     }
     if ($criteria->containsKey(ExportTableMap::ID) && $criteria->keyContainsValue(ExportTableMap::ID)) {
         throw new PropelException('Cannot insert a value for auto-increment primary key (' . ExportTableMap::ID . ')');
     }
     // Set the correct dbName
     $query = ExportQuery::create()->mergeWith($criteria);
     try {
         // use transaction because $criteria could contain info
         // for more than one table (I guess, conceivably)
         $con->beginTransaction();
         $pk = $query->doInsert($con);
         $con->commit();
     } catch (PropelException $e) {
         $con->rollBack();
         throw $e;
     }
     return $pk;
 }
示例#7
0
 /**
  * Get the associated ChildExport object
  *
  * @param      ConnectionInterface $con Optional Connection object.
  * @return                 ChildExport The associated ChildExport object.
  * @throws PropelException
  */
 public function getExport(ConnectionInterface $con = null)
 {
     if ($this->aExport === null && $this->id !== null) {
         $this->aExport = ChildExportQuery::create()->findPk($this->id, $con);
         /* The following can be used additionally to
               guarantee the related object contains a reference
               to this object.  This level of coupling may, however, be
               undesirable since it could result in an only partially populated collection
               in the referenced object.
               $this->aExport->addExportI18ns($this);
            */
     }
     return $this->aExport;
 }
示例#8
0
 protected function getQueryModel()
 {
     return ExportQuery::create();
 }