PageRenderTime 894ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/Varien/Data/Collection/Db.php

https://bitbucket.org/claudiu_marginean/magento-hg-mirror
PHP | 893 lines | 483 code | 78 blank | 332 comment | 59 complexity | c89674d10a30f83953b2ac2f97688306 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, LGPL-2.1, GPL-2.0, WTFPL
  1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@magentocommerce.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magentocommerce.com for more information.
  20. *
  21. * @category Varien
  22. * @package Varien_Data
  23. * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. /**
  27. * Base items collection class
  28. *
  29. * @category Varien
  30. * @package Varien_Data
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. class Varien_Data_Collection_Db extends Varien_Data_Collection
  34. {
  35. /**
  36. * DB connection
  37. *
  38. * @var Zend_Db_Adapter_Abstract
  39. */
  40. protected $_conn;
  41. /**
  42. * Select oblect
  43. *
  44. * @var Zend_Db_Select
  45. */
  46. protected $_select;
  47. /**
  48. * Cache configuration array
  49. *
  50. * @var array
  51. */
  52. protected $_cacheConf = null;
  53. /**
  54. * Identifier fild name for collection items
  55. *
  56. * Can be used by collections with items without defined
  57. *
  58. * @var string
  59. */
  60. protected $_idFieldName;
  61. /**
  62. * List of binded variables for select
  63. *
  64. * @var array
  65. */
  66. protected $_bindParams = array();
  67. /**
  68. * All collection data array
  69. * Used for getData method
  70. *
  71. * @var array
  72. */
  73. protected $_data = null;
  74. /**
  75. * Fields map for corellation names & real selected fields
  76. *
  77. * @var array
  78. */
  79. protected $_map = null;
  80. /**
  81. * Database's statement for fetch item one by one
  82. *
  83. * @var Zend_Db_Statement_Pdo
  84. */
  85. protected $_fetchStmt = null;
  86. public function __construct($conn=null)
  87. {
  88. parent::__construct();
  89. if (!is_null($conn)) {
  90. $this->setConnection($conn);
  91. }
  92. }
  93. /**
  94. * Add variable to bind list
  95. *
  96. * @param string $name
  97. * @param mixed $value
  98. * @return Varien_Data_Collection_Db
  99. */
  100. public function addBindParam($name, $value)
  101. {
  102. $this->_bindParams[$name] = $value;
  103. return $this;
  104. }
  105. /**
  106. * Initialize collection cache
  107. *
  108. * @param $object
  109. * @param string $idPrefix
  110. * @param array $tags
  111. * @return Varien_Data_Collection_Db
  112. */
  113. public function initCache($object, $idPrefix, $tags)
  114. {
  115. $this->_cacheConf = array(
  116. 'object' => $object,
  117. 'prefix' => $idPrefix,
  118. 'tags' => $tags
  119. );
  120. return $this;
  121. }
  122. /**
  123. * Specify collection objects id field name
  124. *
  125. * @param string $fieldName
  126. * @return Varien_Data_Collection_Db
  127. */
  128. protected function _setIdFieldName($fieldName)
  129. {
  130. $this->_idFieldName = $fieldName;
  131. return $this;
  132. }
  133. /**
  134. * Id field name getter
  135. *
  136. * @return string
  137. */
  138. public function getIdFieldName()
  139. {
  140. return $this->_idFieldName;
  141. }
  142. /**
  143. * Get collection item identifier
  144. *
  145. * @param Varien_Object $item
  146. * @return mixed
  147. */
  148. protected function _getItemId(Varien_Object $item)
  149. {
  150. if ($field = $this->getIdFieldName()) {
  151. return $item->getData($field);
  152. }
  153. return parent::_getItemId($item);
  154. }
  155. /**
  156. * Set database connection adapter
  157. *
  158. * @param Zend_Db_Adapter_Abstract $conn
  159. * @return Varien_Data_Collection_Db
  160. */
  161. public function setConnection($conn)
  162. {
  163. if (!$conn instanceof Zend_Db_Adapter_Abstract) {
  164. throw new Zend_Exception('dbModel read resource does not implement Zend_Db_Adapter_Abstract');
  165. }
  166. $this->_conn = $conn;
  167. $this->_select = $this->_conn->select();
  168. return $this;
  169. }
  170. /**
  171. * Get Zend_Db_Select instance
  172. *
  173. * @return Varien_Db_Select
  174. */
  175. public function getSelect()
  176. {
  177. return $this->_select;
  178. }
  179. /**
  180. * Retrieve connection object
  181. *
  182. * @return Zend_Db_Adapter_Abstract
  183. */
  184. public function getConnection()
  185. {
  186. return $this->_conn;
  187. }
  188. /**
  189. * Get collection size
  190. *
  191. * @return int
  192. */
  193. public function getSize()
  194. {
  195. if (is_null($this->_totalRecords)) {
  196. $sql = $this->getSelectCountSql();
  197. $this->_totalRecords = $this->getConnection()->fetchOne($sql, $this->_bindParams);
  198. }
  199. return intval($this->_totalRecords);
  200. }
  201. /**
  202. * Get SQL for get record count
  203. *
  204. * @return Varien_Db_Select
  205. */
  206. public function getSelectCountSql()
  207. {
  208. $this->_renderFilters();
  209. $countSelect = clone $this->getSelect();
  210. $countSelect->reset(Zend_Db_Select::ORDER);
  211. $countSelect->reset(Zend_Db_Select::LIMIT_COUNT);
  212. $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET);
  213. $countSelect->reset(Zend_Db_Select::COLUMNS);
  214. $countSelect->columns('COUNT(*)');
  215. return $countSelect;
  216. }
  217. /**
  218. * Get sql select string or object
  219. *
  220. * @param bool $stringMode
  221. * @return string || Zend_Db_Select
  222. */
  223. function getSelectSql($stringMode = false)
  224. {
  225. if ($stringMode) {
  226. return $this->_select->__toString();
  227. }
  228. return $this->_select;
  229. }
  230. /**
  231. * Add select order
  232. *
  233. * @param string $field
  234. * @param string $direction
  235. * @return Varien_Data_Collection_Db
  236. */
  237. public function setOrder($field, $direction = self::SORT_ORDER_DESC)
  238. {
  239. return $this->_setOrder($field, $direction);
  240. }
  241. /**
  242. * self::setOrder() alias
  243. *
  244. * @param string $field
  245. * @param string $direction
  246. * @return Varien_Data_Collection_Db
  247. */
  248. public function addOrder($field, $direction = self::SORT_ORDER_DESC)
  249. {
  250. return $this->_setOrder($field, $direction);
  251. }
  252. /**
  253. * Add select order to the beginning
  254. *
  255. * @param string $field
  256. * @param string $direction
  257. * @return Varien_Data_Collection_Db
  258. */
  259. public function unshiftOrder($field, $direction = self::SORT_ORDER_DESC)
  260. {
  261. return $this->_setOrder($field, $direction, true);
  262. }
  263. /**
  264. * Add ORDERBY to the end or to the beginning
  265. *
  266. * @param string $field
  267. * @param string $direction
  268. * @param bool $unshift
  269. * @return Varien_Data_Collection_Db
  270. */
  271. private function _setOrder($field, $direction, $unshift = false)
  272. {
  273. $field = (string)$this->_getMappedField($field);
  274. $direction = (strtoupper($direction) == self::SORT_ORDER_ASC) ? self::SORT_ORDER_ASC : self::SORT_ORDER_DESC;
  275. // emulate associative unshift
  276. if ($unshift) {
  277. $orders = array($field => new Zend_Db_Expr($field . ' ' . $direction));
  278. foreach ($this->_orders as $key => $expression) {
  279. if (!isset($orders[$key])) {
  280. $orders[$key] = $expression;
  281. }
  282. }
  283. $this->_orders = $orders;
  284. }
  285. else {
  286. $this->_orders[$field] = new Zend_Db_Expr($field . ' ' . $direction);
  287. }
  288. return $this;
  289. }
  290. /**
  291. * Render sql select conditions
  292. *
  293. * @return Varien_Data_Collection_Db
  294. */
  295. protected function _renderFilters()
  296. {
  297. if ($this->_isFiltersRendered) {
  298. return $this;
  299. }
  300. $this->_renderFiltersBefore();
  301. foreach ($this->_filters as $filter) {
  302. switch ($filter['type']) {
  303. case 'or' :
  304. $condition = $this->_conn->quoteInto($filter['field'].'=?', $filter['value']);
  305. $this->_select->orWhere($condition);
  306. break;
  307. case 'string' :
  308. $this->_select->where($filter['value']);
  309. break;
  310. case 'public':
  311. $field = $this->_getMappedField($filter['field']);
  312. $condition = $filter['value'];
  313. $this->_select->where(
  314. $this->_getConditionSql($field, $condition), null, Varien_Db_Select::TYPE_CONDITION
  315. );
  316. break;
  317. default:
  318. $condition = $this->_conn->quoteInto($filter['field'].'=?', $filter['value']);
  319. $this->_select->where($condition);
  320. }
  321. }
  322. $this->_isFiltersRendered = true;
  323. return $this;
  324. }
  325. /**
  326. * Hook for operations before rendering filters
  327. */
  328. protected function _renderFiltersBefore()
  329. {
  330. }
  331. /**
  332. * Add field filter to collection
  333. *
  334. * @see self::_getConditionSql for $condition
  335. * @param string $field
  336. * @param null|string|array $condition
  337. * @return Mage_Eav_Model_Entity_Collection_Abstract
  338. */
  339. public function addFieldToFilter($field, $condition=null)
  340. {
  341. $field = $this->_getMappedField($field);
  342. $this->_select->where($this->_getConditionSql($field, $condition), null, Varien_Db_Select::TYPE_CONDITION);
  343. return $this;
  344. }
  345. /**
  346. * Try to get mapped field name for filter to collection
  347. *
  348. * @param string
  349. * @return string
  350. */
  351. protected function _getMappedField($field)
  352. {
  353. $mappedFiled = $field;
  354. $mapper = $this->_getMapper();
  355. if (isset($mapper['fields'][$field])) {
  356. $mappedFiled = $mapper['fields'][$field];
  357. }
  358. return $mappedFiled;
  359. }
  360. protected function _getMapper()
  361. {
  362. if (isset($this->_map)) {
  363. return $this->_map;
  364. }
  365. else {
  366. return false;
  367. }
  368. }
  369. /**
  370. * Build SQL statement for condition
  371. *
  372. * If $condition integer or string - exact value will be filtered
  373. *
  374. * If $condition is array is - one of the following structures is expected:
  375. * - array("from"=>$fromValue, "to"=>$toValue)
  376. * - array("like"=>$likeValue)
  377. * - array("neq"=>$notEqualValue)
  378. * - array("in"=>array($inValues))
  379. * - array("nin"=>array($notInValues))
  380. *
  381. * If non matched - sequential array is expected and OR conditions
  382. * will be built using above mentioned structure
  383. *
  384. * @param string|array $fieldName
  385. * @param integer|string|array $condition
  386. * @return string
  387. */
  388. protected function _getConditionSql($fieldName, $condition) {
  389. if (is_array($fieldName)) {
  390. $orSql = array();
  391. foreach ($fieldName as $key=>$name) {
  392. if (isset($condition[$key])) {
  393. $orSql[] = '('.$this->_getConditionSql($name, $condition[$key]).')';
  394. } else {
  395. //if nothing passed as condition adding empty condition to avoid sql error
  396. $orSql[] = $this->getConnection()->quoteInto("$name = ?", '');
  397. }
  398. }
  399. $sql = '('. join(' or ', $orSql) .')';
  400. return $sql;
  401. }
  402. $sql = '';
  403. $fieldName = $this->_getConditionFieldName($fieldName);
  404. if (is_array($condition) && isset($condition['field_expr'])) {
  405. $fieldName = str_replace(
  406. '#?',
  407. $this->getConnection()->quoteIdentifier($fieldName),
  408. $condition['field_expr']
  409. );
  410. }
  411. if (is_array($condition)) {
  412. if (isset($condition['from']) || isset($condition['to'])) {
  413. if (isset($condition['from'])) {
  414. if (empty($condition['date'])) {
  415. if ( empty($condition['datetime'])) {
  416. $from = $condition['from'];
  417. }
  418. else {
  419. $from = $this->getConnection()->convertDateTime($condition['from']);
  420. }
  421. }
  422. else {
  423. $from = $this->getConnection()->convertDate($condition['from']);
  424. }
  425. $sql.= $this->getConnection()->quoteInto("$fieldName >= ?", $from);
  426. }
  427. if (isset($condition['to'])) {
  428. $sql.= empty($sql) ? '' : ' and ';
  429. if (empty($condition['date'])) {
  430. if ( empty($condition['datetime'])) {
  431. $to = $condition['to'];
  432. }
  433. else {
  434. $to = $this->getConnection()->convertDateTime($condition['to']);
  435. }
  436. }
  437. else {
  438. $to = $this->getConnection()->convertDate($condition['to']);
  439. }
  440. $sql.= $this->getConnection()->quoteInto("$fieldName <= ?", $to);
  441. }
  442. }
  443. elseif (isset($condition['eq'])) {
  444. $sql = $this->getConnection()->quoteInto("$fieldName = ?", $condition['eq']);
  445. }
  446. elseif (isset($condition['neq'])) {
  447. $sql = $this->getConnection()->quoteInto("$fieldName != ?", $condition['neq']);
  448. }
  449. elseif (isset($condition['like'])) {
  450. $sql = $this->getConnection()->quoteInto("$fieldName like ?", $condition['like']);
  451. }
  452. elseif (isset($condition['nlike'])) {
  453. $sql = $this->getConnection()->quoteInto("$fieldName not like ?", $condition['nlike']);
  454. }
  455. elseif (isset($condition['in'])) {
  456. $sql = $this->getConnection()->quoteInto("$fieldName in (?)", $condition['in']);
  457. }
  458. elseif (isset($condition['nin'])) {
  459. $sql = $this->getConnection()->quoteInto("$fieldName not in (?)", $condition['nin']);
  460. }
  461. elseif (isset($condition['is'])) {
  462. $sql = $this->getConnection()->quoteInto("$fieldName is ?", $condition['is']);
  463. }
  464. elseif (isset($condition['notnull'])) {
  465. $sql = "$fieldName is NOT NULL";
  466. }
  467. elseif (isset($condition['null'])) {
  468. $sql = "$fieldName is NULL";
  469. }
  470. elseif (isset($condition['moreq'])) {
  471. $sql = $this->getConnection()->quoteInto("$fieldName >= ?", $condition['moreq']);
  472. }
  473. elseif (isset($condition['gt'])) {
  474. $sql = $this->getConnection()->quoteInto("$fieldName > ?", $condition['gt']);
  475. }
  476. elseif (isset($condition['lt'])) {
  477. $sql = $this->getConnection()->quoteInto("$fieldName < ?", $condition['lt']);
  478. }
  479. elseif (isset($condition['gteq'])) {
  480. $sql = $this->getConnection()->quoteInto("$fieldName >= ?", $condition['gteq']);
  481. }
  482. elseif (isset($condition['lteq'])) {
  483. $sql = $this->getConnection()->quoteInto("$fieldName <= ?", $condition['lteq']);
  484. }
  485. elseif (isset($condition['finset'])) {
  486. $sql = $this->getConnection()->quoteInto("find_in_set(?,$fieldName)", $condition['finset']);
  487. }
  488. else {
  489. $orSql = array();
  490. foreach ($condition as $orCondition) {
  491. $orSql[] = "(".$this->_getConditionSql($fieldName, $orCondition).")";
  492. }
  493. $sql = "(".join(" or ", $orSql).")";
  494. }
  495. } else {
  496. $sql = $this->getConnection()->quoteInto("$fieldName = ?", (string)$condition);
  497. }
  498. return $sql;
  499. }
  500. protected function _getConditionFieldName($fieldName)
  501. {
  502. return $fieldName;
  503. }
  504. /**
  505. * Render sql select orders
  506. *
  507. * @return Varien_Data_Collection_Db
  508. */
  509. protected function _renderOrders()
  510. {
  511. $ordersInSelect = $this->_select->getPart(Zend_Db_Select::ORDER);
  512. foreach ($this->_orders as $orderExpr) {
  513. if (!in_array($orderExpr, $ordersInSelect)) {
  514. $this->_select->order($orderExpr);
  515. }
  516. }
  517. return $this;
  518. }
  519. /**
  520. * Render sql select limit
  521. *
  522. * @return Varien_Data_Collection_Db
  523. */
  524. protected function _renderLimit()
  525. {
  526. if($this->_pageSize){
  527. $this->_select->limitPage($this->getCurPage(), $this->_pageSize);
  528. }
  529. return $this;
  530. }
  531. /**
  532. * Set select distinct
  533. *
  534. * @param bool $flag
  535. */
  536. public function distinct($flag)
  537. {
  538. $this->_select->distinct($flag);
  539. return $this;
  540. }
  541. /**
  542. * Before load action
  543. *
  544. * @return Varien_Data_Collection_Db
  545. */
  546. protected function _beforeLoad()
  547. {
  548. return $this;
  549. }
  550. /**
  551. * Load data
  552. *
  553. * @return Varien_Data_Collection_Db
  554. */
  555. public function load($printQuery = false, $logQuery = false)
  556. {
  557. if ($this->isLoaded()) {
  558. return $this;
  559. }
  560. $this->_beforeLoad();
  561. $this->_renderFilters()
  562. ->_renderOrders()
  563. ->_renderLimit();
  564. $this->printLogQuery($printQuery, $logQuery);
  565. $data = $this->getData();
  566. $this->resetData();
  567. if (is_array($data)) {
  568. foreach ($data as $row) {
  569. $item = $this->getNewEmptyItem();
  570. if ($this->getIdFieldName()) {
  571. $item->setIdFieldName($this->getIdFieldName());
  572. }
  573. $item->addData($row);
  574. $this->addItem($item);
  575. }
  576. }
  577. $this->_setIsLoaded();
  578. $this->_afterLoad();
  579. return $this;
  580. }
  581. /**
  582. * Returns a collection item that corresponds to the fetched row
  583. * and moves the internal data pointer ahead
  584. *
  585. * return Varien_Object|bool
  586. */
  587. public function fetchItem()
  588. {
  589. if (null === $this->_fetchStmt) {
  590. $this->_fetchStmt = $this->getConnection()
  591. ->query($this->getSelect());
  592. }
  593. $data = $this->_fetchStmt->fetch();
  594. if (!empty($data) && is_array($data)) {
  595. $item = $this->getNewEmptyItem();
  596. if ($this->getIdFieldName()) {
  597. $item->setIdFieldName($this->getIdFieldName());
  598. }
  599. $item->setData($data);
  600. return $item;
  601. }
  602. return false;
  603. }
  604. /**
  605. * Convert items array to hash for select options
  606. * unsing fetchItem method
  607. *
  608. * The difference between _toOptionHash() and this one is that this
  609. * method fetch items one by one and does not load all collection items at once
  610. * return items hash
  611. * array($value => $label)
  612. *
  613. * @see fetchItem()
  614. *
  615. * @param string $valueField
  616. * @param string $labelField
  617. * @return array
  618. */
  619. protected function _toOptionHashOptimized($valueField='id', $labelField='name')
  620. {
  621. $result = array();
  622. while ($item = $this->fetchItem()) {
  623. $result[$item->getData($valueField)] = $item->getData($labelField);
  624. }
  625. return $result;
  626. }
  627. /**
  628. * Get all data array for collection
  629. *
  630. * @return array
  631. */
  632. public function getData()
  633. {
  634. if ($this->_data === null) {
  635. $this->_renderFilters()
  636. ->_renderOrders()
  637. ->_renderLimit();
  638. $this->_data = $this->_fetchAll($this->_select);
  639. $this->_afterLoadData();
  640. }
  641. return $this->_data;
  642. }
  643. /**
  644. * Proces loaded collection data
  645. *
  646. * @return Varien_Data_Collection_Db
  647. */
  648. protected function _afterLoadData()
  649. {
  650. return $this;
  651. }
  652. /**
  653. * Reset loaded for collection data array
  654. *
  655. * @return Varien_Data_Collection_Db
  656. */
  657. public function resetData()
  658. {
  659. $this->_data = null;
  660. return $this;
  661. }
  662. protected function _afterLoad()
  663. {
  664. return $this;
  665. }
  666. public function loadData($printQuery = false, $logQuery = false)
  667. {
  668. return $this->load($printQuery, $logQuery);
  669. }
  670. /**
  671. * Print and/or log query
  672. *
  673. * @param boolean $printQuery
  674. * @param boolean $logQuery
  675. * @return Varien_Data_Collection_Db
  676. */
  677. public function printLogQuery($printQuery = false, $logQuery = false, $sql = null) {
  678. if ($printQuery) {
  679. echo is_null($sql) ? $this->getSelect()->__toString() : $sql;
  680. }
  681. if ($logQuery){
  682. Mage::log(is_null($sql) ? $this->getSelect()->__toString() : $sql);
  683. }
  684. return $this;
  685. }
  686. /**
  687. * Reset collection
  688. *
  689. * @return Varien_Data_Collection_Db
  690. */
  691. protected function _reset()
  692. {
  693. $this->getSelect()->reset();
  694. $this->_initSelect();
  695. $this->_setIsLoaded(false);
  696. $this->_items = array();
  697. $this->_data = null;
  698. return $this;
  699. }
  700. /**
  701. * Fetch collection data
  702. *
  703. * @param Zend_Db_Select $select
  704. * @return array
  705. */
  706. protected function _fetchAll($select)
  707. {
  708. if ($this->_canUseCache()) {
  709. $data = $this->_loadCache($select);
  710. if ($data) {
  711. $data = unserialize($data);
  712. } else {
  713. $data = $this->getConnection()->fetchAll($select, $this->_bindParams);
  714. $this->_saveCache($data, $select);
  715. }
  716. } else {
  717. $data = $this->getConnection()->fetchAll($select, $this->_bindParams);
  718. }
  719. return $data;
  720. }
  721. /**
  722. * Load cached data for select
  723. *
  724. * @param Zend_Db_Select $select
  725. * @return string | false
  726. */
  727. protected function _loadCache($select)
  728. {
  729. $data = false;
  730. $object = $this->_getCacheInstance();
  731. if ($object) {
  732. $data = $object->load($this->_getSelectCacheId($select));
  733. }
  734. return $data;
  735. }
  736. /**
  737. * Save collection data to cache
  738. *
  739. * @param array $data
  740. * @param Zend_Db_Select $select
  741. * @return unknown_type
  742. */
  743. protected function _saveCache($data, $select)
  744. {
  745. $object = $this->_getCacheInstance();
  746. $object->save(serialize($data), $this->_getSelectCacheId($select), $this->_getCacheTags());
  747. return $this;
  748. }
  749. /**
  750. * Check if cache can be used for collection data
  751. *
  752. * @return bool
  753. */
  754. protected function _canUseCache()
  755. {
  756. return $this->_getCacheInstance();
  757. }
  758. /**
  759. * Get cache identifier base on select
  760. *
  761. * @param Zend_Db_Select $select
  762. * @return string
  763. */
  764. protected function _getSelectCacheId($select)
  765. {
  766. $id = md5($select->__toString());
  767. if (isset($this->_cacheConf['prefix'])) {
  768. $id = $this->_cacheConf['prefix'].'_'.$id;
  769. }
  770. return $id;
  771. }
  772. /**
  773. * Retrieve cache instance
  774. *
  775. * @return Zend_Cache_Core
  776. */
  777. protected function _getCacheInstance()
  778. {
  779. if (isset($this->_cacheConf['object'])) {
  780. return $this->_cacheConf['object'];
  781. }
  782. return false;
  783. }
  784. /**
  785. * Get cache tags list
  786. *
  787. * @return array
  788. */
  789. protected function _getCacheTags()
  790. {
  791. if (isset($this->_cacheConf['tags'])) {
  792. return $this->_cacheConf['tags'];
  793. }
  794. return array();
  795. }
  796. /**
  797. * Add filter to Map
  798. *
  799. * @param string $filter
  800. * @param string $alias
  801. * @param string $group default 'fields'
  802. *
  803. * @return Varien_Data_Collection_Db
  804. */
  805. public function addFilterToMap($filter, $alias, $group = 'fields')
  806. {
  807. if (is_null($this->_map)) {
  808. $this->_map = array($group => array());
  809. } else if(is_null($this->_map[$group])) {
  810. $this->_map[$group] = array();
  811. }
  812. $this->_map[$group][$filter] = $alias;
  813. return $this;
  814. }
  815. }