00001 <?php
00002
00012 class Account_Wishlist extends Account
00013 {
00019 protected $_sThisTemplate = 'account_wishlist.tpl';
00020
00026 protected $_blShowSuggest = null;
00027
00033 protected $_oWishList = null;
00034
00040 protected $_aRecommList = null;
00041
00047 protected $_oEditval = null;
00048
00054 protected $_iSendWishList = null;
00055
00061 protected $_sSearchParam = null;
00062
00068 protected $_oWishListUsers = false;
00069
00075 protected $_blEmailSent = false;
00076
00082 protected $_aEditValues = false;
00083
00089 protected $_iViewIndexState = VIEW_INDEXSTATE_NOINDEXNOFOLLOW;
00090
00102 public function render()
00103 {
00104 parent::render();
00105
00106
00107 $oUser = $this->getUser();
00108 if ( !$oUser ) {
00109 return $this->_sThisTemplate = $this->_sThisLoginTemplate;
00110 }
00111
00112 $this->_aViewData['blshowsuggest'] = $this->showSuggest();
00113 $this->_aViewData['similarrecommlist'] = $this->getSimilarRecommLists();
00114
00115 $this->_aViewData['wishlist'] = $this->getWishList();
00116 if ( $this->getWishList() ) {
00117 $this->_aViewData['wishlist']->aList = $this->getWishProductList();
00118 }
00119
00120 return $this->_sThisTemplate;
00121 }
00122
00128 public function showSuggest()
00129 {
00130 if ( $this->_blShowSuggest === null ) {
00131 $this->_blShowSuggest = ( bool ) oxConfig::getParameter( 'blshowsuggest' );
00132 }
00133 return $this->_blShowSuggest;
00134 }
00135
00141 public function getWishList()
00142 {
00143 if ( $this->_oWishList === null ) {
00144 $this->_oWishList = false;
00145
00146 if ( $oUser = $this->getUser() ) {
00147 $oWishList = $oUser->getBasket( 'wishlist' );
00148 if ( $oWishListProducts = $oWishList->getArticles() ) {
00149
00150 $this->_aWishProductList = $oWishListProducts;
00151 $this->_oWishList = $oWishList;
00152 }
00153 }
00154 }
00155
00156 return $this->_oWishList;
00157 }
00158
00164 public function getWishProductList()
00165 {
00166 if ( $this->_aWishProductList === null ) {
00167 $this->_aWishProductList = false;
00168
00169 if ( $oWishList = $this->getWishList() ) {
00170 return $this->_aWishProductList;
00171 }
00172 }
00173 return $this->_aWishProductList;
00174 }
00175
00181 public function getSimilarRecommLists()
00182 {
00183
00184 if ( $this->_aRecommList === null ) {
00185
00186
00187 $this->_aRecommList = false;
00188
00189
00190 $aWishProdList = $this->getWishProductList();
00191 if ( is_array( $aWishProdList ) && ( $oSimilarProd = current( $aWishProdList ) ) ) {
00192 $oRecommList = oxNew('oxrecommlist');
00193 $this->_aRecommList = $oRecommList->getRecommListsByIds( array( $oSimilarProd->getId() ) );
00194 }
00195 }
00196
00197 return $this->_aRecommList;
00198 }
00199
00208 public function sendWishList()
00209 {
00210 $aParams = oxConfig::getParameter( 'editval' );
00211
00212 if ( !is_array( $aParams ) ) {
00213 return;
00214 }
00215
00216
00217 reset( $aParams );
00218 $oParams = new OxstdClass();
00219 while ( list( $sName, $sValue ) = each( $aParams ) ) {
00220 $oParams->$sName = $sValue;
00221 }
00222 $this->_aEditValues = $oParams;
00223
00224 if ( !$aParams['rec_name'] || !$aParams['rec_email'] ) {
00225 oxUtilsView::getInstance()->addErrorToDisplay('ACCOUNT_WISHLIST_ERRCOMLETEFIELDSCORRECTLY', false, true );
00226 return;
00227 }
00228
00229 if ( $oUser = $this->getUser() ) {
00230
00231 $oParams->send_email = $oUser->oxuser__oxusername->value;
00232 $oParams->send_name = $oUser->oxuser__oxfname->value.' '.$oUser->oxuser__oxlname->value;
00233 $oParams->send_id = $oUser->getId();
00234
00235 $oEmail = oxNew( 'oxemail' );
00236 if ( !$oEmail->sendWishlistMail( $oParams ) ) {
00237 oxUtilsView::getInstance()->addErrorToDisplay( 'ACCOUNT_WISHLIST_ERRWRONGEMAIL', false, true );
00238 return;
00239 } else {
00240 $this->_blEmailSent = true;
00241 }
00242 }
00243
00244 $this->_aViewData['success'] = $this->isWishListEmailSent();
00245 $this->_aViewData['editval'] = $this->getEnteredData();
00246 }
00247
00253 public function isWishListEmailSent()
00254 {
00255 return $this->_blEmailSent;
00256 }
00257
00263 public function getEnteredData()
00264 {
00265 return $this->_aEditValues;
00266 }
00267
00274 public function togglePublic()
00275 {
00276 if ( $oUser = $this->getUser() ) {
00277
00278 $blPublic = (int) oxConfig::getParameter( 'blpublic' );
00279 $blPublic = ( $blPublic == 1 )?$blPublic:0;
00280
00281 $oBasket = $oUser->getBasket( 'wishlist' );
00282 $oBasket->oxuserbaskets__oxpublic = new oxField($blPublic);
00283 $oBasket->save();
00284 }
00285 }
00286
00296 public function searchForWishList()
00297 {
00298 if ( $sSearch = oxConfig::getParameter( 'search' ) ) {
00299
00300
00301 $oUserList = oxNew( 'oxuserlist' );
00302 $oUserList->loadWishlistUsers( $sSearch );
00303 if ( $oUserList->count() ) {
00304 $this->_oWishListUsers = $oUserList;
00305 }
00306
00307 $this->_sSearchParam = $sSearch;
00308 }
00309
00310 $this->_aViewData['search'] = $this->getWishListSearchParam();
00311 $this->_aViewData['wish_result'] = $this->getWishListUsers();
00312 }
00313
00320 public function getWishListUsers()
00321 {
00322 return $this->_oWishListUsers;
00323 }
00324
00330 public function getWishListSearchParam()
00331 {
00332 return $this->_sSearchParam;
00333 }
00334 }