_albumDefaultColumns; $columns['photoCount'] = new Zend_Db_Expr('(' . $this->_getVisibleImagesCountSelect() . ')'); $select = $this->_getAlbumSelect($columns); $select->having('photoCount > 0'); $albums = $this->_db->fetchAssoc($select); $noImage = []; foreach ($albums as $album) { if (empty($album['image'])) { $noImage[] = $album['id']; } } if ($noImage) { $columns = ['id', 'image' => new Zend_Db_Expr('(' . $this->_getDefaultAlbumImageSelect() . ')')]; $select = $this->_db->select(); $select->from($this->_getPair(), $columns); $select->where('`g`.`id` IN (?)', $noImage, Qs_Db::INT_TYPE); $images = $this->_db->fetchPairs($select); foreach ($images as $galleryId => $image) { $albums[$galleryId]['image'] = $image; } } return $albums; } protected function _getAlbumSelect($columns = null) { if (null === $columns) { $columns = $this->_albumDefaultColumns; } $select = $this->_db->select(); $select->from($this->_getPair(), $columns); $select->where("`g`.`enabled` = 'y'"); $select->order("g.sorter"); return $select; } protected function _getDefaultAlbumImageSelect() { $select = $this->_db->select(); $select->from($this->_getPair('GalleryImage', 'gi'), ['image']); $select->where('`gi`.`galleryId` = `g`.`id`'); $select->where('`gi`.`enabled` = "y"'); $select->order('gi.sorter'); $select->limit('1'); return $select; } public function getAlbumItems($id = null) { if (null === $id) { $id = $this->getPrimaryKey(); } $select = $this->_db->select(); $select->from($this->_getPair('GalleryImage', 'gi')); $select->where('`galleryId` = ?', $id, Qs_Db::INT_TYPE); $select->where('`enabled` = "y"'); $select->order('sorter'); return $this->_db->fetchAssoc($select); } protected function _getFromDbSelect($primaryKey) { $select = parent::_getFromDbSelect($primaryKey); $select->where('`g`.`enabled` = "y"'); return $select; } public function getListStatement4XmlSitemap($columns = ['alias']) { $select = $this->_getAlbumSelect($columns); $select->where(new Zend_Db_Expr('(' . $this->_getVisibleImagesCountSelect() . ') > 0')); return $select->query(); } }