/** * Gets recursive all sub-sites of a site sorted on their level. * * @param MShop_Locale_Item_Site_Interface $site Site which can contain sub-sites * @return MShop_Locale_Item_Site_Interface[] $sites List with sites */ private function _getSites(MShop_Locale_Item_Site_Interface $site) { $sites = array($site); foreach ($site->getChildren() as $child) { $sites = array_merge($sites, $this->_getSites($child)); } return $sites; }
/** * 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 MShop_Locale_Item_Site_Interface 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 MShop_Locale_Item_Interface Locale item for the given parameters * @throws MShop_Locale_Exception If no locale item is found */ protected function _bootstrap($site, $lang, $currency, $active, MShop_Locale_Item_Site_Interface $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 MShop_Locale_Exception(sprintf('Locale item for site "%1$s" not found', $site)); }
/** * Creates a list of items with children. * * @param MShop_Locale_Item_Site_Interface $item Locale site item */ protected function _createNodeArray(MShop_Locale_Item_Site_Interface $item) { $result = $item->toArray(); if (method_exists($item, 'getChildren')) { foreach ($item->getChildren() as $child) { $result['children'][] = $this->_createNodeArray($child); } } return (object) $result; }
/** * Adds a new item object. * * @param MShop_Locale_Item_Site_Interface $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(MShop_Locale_Item_Site_Interface $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/default/item/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/default/item/update * @see mshop/locale/manager/site/default/item/delete * @see mshop/locale/manager/site/default/item/search * @see mshop/locale/manager/site/default/item/count * @see mshop/locale/manager/site/default/item/newid */ $path = 'mshop/locale/manager/site/default/item/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(), MW_DB_Statement_Abstract::PARAM_INT); $stmt->bind(5, 0, MW_DB_Statement_Abstract::PARAM_INT); $stmt->bind(6, $context->getEditor()); $stmt->bind(7, $date); // mtime $stmt->bind(8, $date); // ctime $stmt->execute()->finish(); /** mshop/locale/manager/site/default/item/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/default/item/insert * @see mshop/locale/manager/site/default/item/update * @see mshop/locale/manager/site/default/item/delete * @see mshop/locale/manager/site/default/item/search * @see mshop/locale/manager/site/default/item/count */ $path = 'mshop/locale/manager/default/item/newid'; $item->setId($this->_newId($conn, $context->getConfig()->get($path, $path))); $dbm->release($conn, $dbname); } catch (Exception $e) { $dbm->release($conn, $dbname); throw $e; } }
/** * Adds a new item object. * * @param MShop_Locale_Item_Site_Interface $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(MShop_Locale_Item_Site_Interface $item, $parentId = null, $refId = null) { $context = $this->_getContext(); $dbm = $context->getDatabaseManager(); $dbname = $this->_getResourceName(); $conn = $dbm->acquire($dbname); try { $curdate = date('Y-m-d H:i:s'); $path = 'mshop/locale/manager/site/default/item/insert'; $stmt = $this->_getCachedStatement($conn, $path); $stmt->bind(1, $item->getCode(), MW_DB_Statement_Abstract::PARAM_STR); $stmt->bind(2, $item->getLabel(), MW_DB_Statement_Abstract::PARAM_STR); $stmt->bind(3, json_encode($item->getConfig()), MW_DB_Statement_Abstract::PARAM_STR); $stmt->bind(4, $item->getStatus(), MW_DB_Statement_Abstract::PARAM_INT); $stmt->bind(5, 0, MW_DB_Statement_Abstract::PARAM_INT); $stmt->bind(6, $context->getEditor()); $stmt->bind(7, $curdate); // mtime $stmt->bind(8, $curdate); // ctime $stmt->execute()->finish(); $path = 'mshop/locale/manager/default/item/newid'; $item->setId($this->_newId($conn, $context->getConfig()->get($path, $path))); $dbm->release($conn, $dbname); } catch (Exception $e) { $dbm->release($conn, $dbname); throw $e; } }
/** * Returns the list of site IDs of the whole tree. * * @param MShop_Locale_Item_Site_Interface $item Locale item, maybe with children * @return array List of site IDs */ private function _getSiteIdsFromTree(MShop_Locale_Item_Site_Interface $item) { $list = array($item->getId()); foreach ($item->getChildren() as $child) { $list = array_merge($list, $this->_getSiteIdsFromTree($child)); } return $list; }