示例#1
0
 /**
  * Returns the list of category label / ID pairs for the given node and all children
  *
  * @param MShop_Catalog_Item_Interface $item Catalog item to start from
  * @param unknown_type $level Current level on indention
  * @return array Associative array of category label / ID pairs
  */
 protected function getCategoryList(\Aimeos\MShop\Catalog\Item\Iface $item, $level)
 {
     $result = array();
     $result[] = array(str_repeat('.', $level * 4) . $item->getName(), $item->getId());
     foreach ($item->getChildren() as $child) {
         $result = array_merge($result, $this->getCategoryList($child, $level + 1));
     }
     return $result;
 }
示例#2
0
 /**
  * Returns the list of category label / ID pairs for the given node and all children
  *
  * @param MShop_Catalog_Item_Interface $item Catalog item to start from
  * @param string $breadcrumb Breadcrumb of the parent nodes
  * @return array Associative array of category label / ID pairs
  */
 protected function getCategoryList(\Aimeos\MShop\Catalog\Item\Iface $item, $breadcrumb)
 {
     $result = array();
     $result[] = array($breadcrumb, $item->getId());
     foreach ($item->getChildren() as $child) {
         $result = array_merge($result, $this->getCategoryList($child, $breadcrumb . ' > ' . $child->getName()));
     }
     return $result;
 }
示例#3
0
 /**
  * Get all child nodes.
  *
  * @param \Aimeos\MShop\Catalog\Item\Iface $node
  * @return \Aimeos\MShop\Catalog\Item\Iface[] $nodes List of nodes
  */
 protected function getNodeList(\Aimeos\MShop\Catalog\Item\Iface $node)
 {
     $nodes = array($node);
     foreach ($node->getChildren() as $child) {
         $nodes = array_merge($nodes, $this->getNodeList($child));
     }
     return $nodes;
 }
示例#4
0
 /**
  * Creates a list of nodes with children.
  *
  * @param \Aimeos\MShop\Catalog\Item\Iface $node Catalog node
  */
 protected function createNodeArray(\Aimeos\MShop\Catalog\Item\Iface $node)
 {
     $result = $node->toArray();
     foreach ($node->getChildren() as $child) {
         $result['children'][] = $this->createNodeArray($child);
     }
     return (object) $result;
 }
示例#5
0
 /**
  * Returns the list of catalog IDs for the given catalog tree
  *
  * @param \Aimeos\MShop\Catalog\Item\Iface $item Catalog item with children
  * @return array List of catalog IDs
  */
 protected function getCatalogIdsFromTree(\Aimeos\MShop\Catalog\Item\Iface $item)
 {
     $list = array($item->getId());
     foreach ($item->getChildren() as $child) {
         $list = array_merge($list, $this->getCatalogIdsFromTree($child));
     }
     return $list;
 }
示例#6
0
 /**
  * Updates the usage information of a node.
  *
  * @param integer $id Id of the record
  * @param \Aimeos\MShop\Catalog\Item\Iface $item Catalog item
  * @param boolean $case True if the record shoud be added or false for an update
  *
  */
 private function updateUsage($id, \Aimeos\MShop\Catalog\Item\Iface $item, $case = false)
 {
     $date = date('Y-m-d H:i:s');
     $context = $this->getContext();
     $dbm = $context->getDatabaseManager();
     $dbname = $this->getResourceName();
     $conn = $dbm->acquire($dbname);
     try {
         $siteid = $context->getLocale()->getSiteId();
         if ($case !== true) {
             /** mshop/catalog/manager/standard/update-usage
              * Updates the config, editor and mtime value of an updated record
              *
              * Each record contains some usage information like when it was
              * created, last modified and by whom. These information are part
              * of the catalog items and the generic tree manager doesn't care
              * about this information. Thus, they are updated after the tree
              * manager saved the basic record information.
              *
              * 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 catalog item to the statement before they are
              * sent to the database server. The order of the columns must
              * correspond to the order in the method using this statement,
              * 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 updating records
              * @since 2014.03
              * @category Developer
              * @see mshop/catalog/manager/standard/delete
              * @see mshop/catalog/manager/standard/get
              * @see mshop/catalog/manager/standard/insert
              * @see mshop/catalog/manager/standard/newid
              * @see mshop/catalog/manager/standard/search
              * @see mshop/catalog/manager/standard/search-item
              * @see mshop/catalog/manager/standard/count
              * @see mshop/catalog/manager/standard/move-left
              * @see mshop/catalog/manager/standard/move-right
              * @see mshop/catalog/manager/standard/update-parentid
              * @see mshop/catalog/manager/standard/insert-usage
              */
             $path = 'mshop/catalog/manager/standard/update-usage';
         } else {
             /** mshop/catalog/manager/standard/insert-usage
              * Updates the config, editor, ctime and mtime value of an inserted record
              *
              * Each record contains some usage information like when it was
              * created, last modified and by whom. These information are part
              * of the catalog items and the generic tree manager doesn't care
              * about this information. Thus, they are updated after the tree
              * manager inserted the basic record information.
              *
              * 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 catalog item to the statement before they are
              * sent to the database server. The order of the columns must
              * correspond to the order in the method using this statement,
              * 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 updating records
              * @since 2014.03
              * @category Developer
              * @see mshop/catalog/manager/standard/delete
              * @see mshop/catalog/manager/standard/get
              * @see mshop/catalog/manager/standard/insert
              * @see mshop/catalog/manager/standard/newid
              * @see mshop/catalog/manager/standard/search
              * @see mshop/catalog/manager/standard/search-item
              * @see mshop/catalog/manager/standard/count
              * @see mshop/catalog/manager/standard/move-left
              * @see mshop/catalog/manager/standard/move-right
              * @see mshop/catalog/manager/standard/update-parentid
              * @see mshop/catalog/manager/standard/update-usage
              */
             $path = 'mshop/catalog/manager/standard/insert-usage';
         }
         $stmt = $conn->create($this->getSqlConfig($path));
         $stmt->bind(1, json_encode($item->getConfig()));
         $stmt->bind(2, $date);
         // mtime
         $stmt->bind(3, $context->getEditor());
         if ($case !== true) {
             $stmt->bind(4, $siteid, \Aimeos\MW\DB\Statement\Base::PARAM_INT);
             $stmt->bind(5, $id, \Aimeos\MW\DB\Statement\Base::PARAM_INT);
         } else {
             $stmt->bind(4, $date);
             // ctime
             $stmt->bind(5, $siteid, \Aimeos\MW\DB\Statement\Base::PARAM_INT);
             $stmt->bind(6, $id, \Aimeos\MW\DB\Statement\Base::PARAM_INT);
         }
         $stmt->execute()->finish();
         $dbm->release($conn, $dbname);
     } catch (\Exception $e) {
         $dbm->release($conn, $dbname);
         throw $e;
     }
 }
示例#7
0
 protected function delete(\Aimeos\MShop\Catalog\Item\Iface $catItem)
 {
     $manager = \Aimeos\MShop\Catalog\Manager\Factory::createManager($this->context);
     $listManager = $manager->getSubManager('lists');
     foreach ($catItem->getListItems('product') as $listItem) {
         $listManager->deleteItem($listItem->getId());
     }
     $manager->deleteItem($catItem->getId());
 }
示例#8
0
 /**
  * Returns the category IDs of the given catalog tree.
  *
  * Only the IDs of the children of the current category are returned.
  *
  * @param \Aimeos\MShop\Catalog\Item\Iface $tree Catalog node as entry point of the tree
  * @param array $path Associative list of category IDs as keys and the catalog
  * 	nodes from the currently selected category up to the root node
  * @param string $currentId Currently selected category
  * @return array List of category IDs
  */
 protected function getCatalogIds(\Aimeos\MShop\Catalog\Item\Iface $tree, array $path, $currentId)
 {
     if ($tree->getId() == $currentId) {
         $ids = array();
         foreach ($tree->getChildren() as $item) {
             $ids[] = $item->getId();
         }
         return $ids;
     }
     foreach ($tree->getChildren() as $child) {
         if (isset($path[$child->getId()])) {
             return $this->getCatalogIds($child, $path, $currentId);
         }
     }
     return array();
 }
示例#9
0
 /**
  * Builds the tree of catalog items.
  *
  * @param \Aimeos\MW\Tree\Node\Iface $node Parent tree node
  * @param \Aimeos\MShop\Catalog\Item\Iface $item Parent tree catalog Item
  * @param array $listItemMap Associative list of parent-item-ID / list items for the catalog item
  * @param array $refItemMap Associative list of parent-item-ID/domain/items key/value pairs
  */
 protected function createTree(\Aimeos\MW\Tree\Node\Iface $node, \Aimeos\MShop\Catalog\Item\Iface $item, array $listItemMap, array $refItemMap)
 {
     foreach ($node->getChildren() as $idx => $child) {
         $listItems = array();
         if (array_key_exists($child->getId(), $listItemMap)) {
             $listItems = $listItemMap[$child->getId()];
         }
         $refItems = array();
         if (array_key_exists($child->getId(), $refItemMap)) {
             $refItems = $refItemMap[$child->getId()];
         }
         $newItem = $this->createItemBase(array(), $listItems, $refItems, array(), $child);
         $result = true;
         foreach ($this->filter as $fcn) {
             $result = $result && $fcn($newItem, $idx);
         }
         if ($result === true) {
             $item->addChild($newItem);
             $this->createTree($child, $newItem, $listItemMap, $refItemMap);
         }
     }
 }