_getFromImageCountSelect() . ')'); $columns['categories'] = $this->_getCategoriesExpr(); return $columns; } protected function _getCategoriesExpr() { $select = $this->_db->select(); $select->from($this->_getPair($this->_tableAlias . '2Category', 'pc'), 'GROUP_CONCAT(`pc`.`categoryId`)') ->where('`pc`.`productId` = `' . $this->_tableAlias . '`.`id`'); return new Zend_Db_Expr('(' . $select . ')'); } protected function _getFromImageCountSelect() { $select = $this->_db->select(); $select->from($this->_getPair($this->_tableAlias . 'Image'), 'COUNT(*)'); $select->where('`productId` = `' . $this->_tableAlias . '`.`id`'); return $select; } protected function _insertDependency() { $this->_saveDependency(); return $this; } protected function _updateDependency() { $this->_saveDependency(); return $this; } /** * Save dependency for insert and update * * @return App_ECommerce_Product_Admin_Obj */ protected function _saveDependency() { $categories = $this->getData('categories'); if (!empty($categories)) { $this->_updateIds($this->_tableAlias . '2Category', 'productId', 'categoryId', $categories); } return $this; } protected function _deleteDependency() { $this->_deleteImages(); return $this; } protected function _deleteImages() { $imagesObj = new App_ECommerce_Product_Image_Admin_Obj(); $imagesObj->setProductId($this->_primaryKey); $this->_dependedFields = $this->_db->fetchCol( $imagesObj->getListSelect()->reset(Zend_Db_Select::COLUMNS)->columns('image') ); return $this; } protected function _prepareList(&$list) { parent::_prepareList($list); $categories = $this->getCategories4Select(true); foreach ($list as &$row) { $rowCategories = array_reverse(explode(',', $row['categories'])); $row['categories'] = array(); foreach ($rowCategories as $category) { $row['categories'][$category] = $categories[$category]; } } return parent::_prepareList($list); } protected function _filter(Zend_Db_Select $select) { parent::_filter($select); foreach ($this->_getCleanedFilter($this->_filter) as $field => $value) { switch ($field) { case 'category': $this->_filterByCategory($select, $value); break; } } return $this; } }