/**
  * Gets recursive all sub-sites of a site sorted on their level.
  *
  * @param \Aimeos\MShop\Locale\Item\Site\Iface $site Site which can contain sub-sites
  * @return \Aimeos\MShop\Locale\Item\Site\Iface[] $sites List with sites
  */
 private function getSites(\Aimeos\MShop\Locale\Item\Site\Iface $site)
 {
     $sites = array($site);
     foreach ($site->getChildren() as $child) {
         $sites = array_merge($sites, $this->getSites($child));
     }
     return $sites;
 }
Exemple #2
0
 /**
  * Returns the list of site IDs of the whole tree.
  *
  * @param \Aimeos\MShop\Locale\Item\Site\Iface $item Locale item, maybe with children
  * @return array List of site IDs
  */
 private function getSiteIdsFromTree(\Aimeos\MShop\Locale\Item\Site\Iface $item)
 {
     $list = array($item->getId());
     foreach ($item->getChildren() as $child) {
         $list = array_merge($list, $this->getSiteIdsFromTree($child));
     }
     return $list;
 }
Exemple #3
0
 /**
  * Returns the locale item for the given site code, language code and currency code.
  *
  * If the locale item is inherited from a parent site, the site ID of this locale item
  * is changed to the site ID of the actual site. This ensures that items assigned to
  * the same site as the site item are still used.
  *
  * @param string $site Site code
  * @param string $lang Language code
  * @param string $currency Currency code
  * @param boolean $active Flag to get only active items
  * @param \Aimeos\MShop\Locale\Item\Site\Iface Site item
  * @param array $sitePath List of site IDs up to the root site
  * @param array $siteSubTree List of site IDs below and including the current site
  * @return \Aimeos\MShop\Locale\Item\Iface Locale item for the given parameters
  * @throws \Aimeos\MShop\Locale\Exception If no locale item is found
  */
 protected function bootstrapBase($site, $lang, $currency, $active, \Aimeos\MShop\Locale\Item\Site\Iface $siteItem, array $sitePath, array $siteSubTree)
 {
     $siteId = $siteItem->getId();
     $result = $this->bootstrapMatch($siteId, $lang, $currency, $active, $siteItem, $sitePath, $siteSubTree);
     if ($result !== false) {
         return $result;
     }
     $result = $this->bootstrapClosest($siteId, $lang, $active, $siteItem, $sitePath, $siteSubTree);
     if ($result !== false) {
         return $result;
     }
     throw new \Aimeos\MShop\Locale\Exception(sprintf('Locale item for site "%1$s" not found', $site));
 }
Exemple #4
0
 /**
  * Creates a list of items with children.
  *
  * @param \Aimeos\MShop\Locale\Item\Site\Iface $item Locale site item
  */
 protected function createNodeArray(\Aimeos\MShop\Locale\Item\Site\Iface $item)
 {
     $result = $item->toArray();
     if (method_exists($item, 'getChildren')) {
         foreach ($item->getChildren() as $child) {
             $result['children'][] = $this->createNodeArray($child);
         }
     }
     return (object) $result;
 }
Exemple #5
0
 /**
  * Adds a new item object.
  *
  * @param \Aimeos\MShop\Locale\Item\Site\Iface $item Item which should be inserted
  * @param integer $parentId ID of the parent item where the item should be inserted into
  * @param integer $refId ID of the item where the item should be inserted before (null to append)
  */
 public function insertItem(\Aimeos\MShop\Locale\Item\Site\Iface $item, $parentId = null, $refId = null)
 {
     $context = $this->getContext();
     $dbm = $context->getDatabaseManager();
     $dbname = $this->getResourceName();
     $conn = $dbm->acquire($dbname);
     try {
         $date = date('Y-m-d H:i:s');
         /** mshop/locale/manager/site/standard/insert
          * Inserts a new currency record into the database table
          *
          * The SQL statement must be a string suitable for being used as
          * prepared statement. It must include question marks for binding
          * the values from the log item to the statement before they are
          * sent to the database server. The number of question marks must
          * be the same as the number of columns listed in the INSERT
          * statement. The order of the columns must correspond to the
          * order in the saveItems() method, so the correct values are
          * bound to the columns.
          *
          * The SQL statement should conform to the ANSI standard to be
          * compatible with most relational database systems. This also
          * includes using double quotes for table and column names.
          *
          * @param string SQL statement for inserting records
          * @since 2014.03
          * @category Developer
          * @see mshop/locale/manager/site/standard/update
          * @see mshop/locale/manager/site/standard/delete
          * @see mshop/locale/manager/site/standard/search
          * @see mshop/locale/manager/site/standard/count
          * @see mshop/locale/manager/site/standard/newid
          */
         $path = 'mshop/locale/manager/site/standard/insert';
         $stmt = $this->getCachedStatement($conn, $path);
         $stmt->bind(1, $item->getCode());
         $stmt->bind(2, $item->getLabel());
         $stmt->bind(3, json_encode($item->getConfig()));
         $stmt->bind(4, $item->getStatus(), \Aimeos\MW\DB\Statement\Base::PARAM_INT);
         $stmt->bind(5, 0, \Aimeos\MW\DB\Statement\Base::PARAM_INT);
         $stmt->bind(6, $context->getEditor());
         $stmt->bind(7, $date);
         // mtime
         $stmt->bind(8, $date);
         // ctime
         $stmt->execute()->finish();
         /** mshop/locale/manager/site/standard/newid
          * Retrieves the ID generated by the database when inserting a new record
          *
          * As soon as a new record is inserted into the database table,
          * the database server generates a new and unique identifier for
          * that record. This ID can be used for retrieving, updating and
          * deleting that specific record from the table again.
          *
          * For MySQL:
          *  SELECT LAST_INSERT_ID()
          * For PostgreSQL:
          *  SELECT currval('seq_matt_id')
          * For SQL Server:
          *  SELECT SCOPE_IDENTITY()
          * For Oracle:
          *  SELECT "seq_matt_id".CURRVAL FROM DUAL
          *
          * There's no way to retrive the new ID by a SQL statements that
          * fits for most database servers as they implement their own
          * specific way.
          *
          * @param string SQL statement for retrieving the last inserted record ID
          * @since 2014.03
          * @category Developer
          * @see mshop/locale/manager/site/standard/insert
          * @see mshop/locale/manager/site/standard/update
          * @see mshop/locale/manager/site/standard/delete
          * @see mshop/locale/manager/site/standard/search
          * @see mshop/locale/manager/site/standard/count
          */
         $path = 'mshop/locale/manager/standard/newid';
         $item->setId($this->newId($conn, $this->getSqlConfig($path)));
         $dbm->release($conn, $dbname);
     } catch (\Exception $e) {
         $dbm->release($conn, $dbname);
         throw $e;
     }
 }