account_wishlist.php

Go to the documentation of this file.
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         // is logged in ?
00107         $oUser = $this->getUser();
00108         if ( !$oUser ) {
00109             return $this->_sThisTemplate = $this->_sThisLoginTemplate;
00110         }
00111         // for older templates
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             if ( $oUser = $this->getUser() ) {
00146                 $this->_oWishList = $oUser->getBasket( 'wishlist' );
00147                 if ( $this->_oWishList->isEmpty() ) {
00148                     $this->_oWishList = false;
00149                 }
00150             }
00151         }
00152 
00153         return $this->_oWishList;
00154     }
00155 
00161     public function getWishProductList()
00162     {
00163         if ( $this->_aWishProductList === null ) {
00164             $this->_aWishProductList = false;
00165             if ( $oWishList = $this->getWishList() ) {
00166                 $this->_aWishProductList = $oWishList->getArticles();
00167             }
00168         }
00169         return $this->_aWishProductList;
00170     }
00171 
00177     public function getSimilarRecommLists()
00178     {
00179         if ( !$this->getViewConfig()->getShowListmania() ) {
00180             return false;
00181         }
00182 
00183         // recomm list
00184         if ( $this->_aRecommList === null ) {
00185 
00186             // just ensuring that next call will skip this check
00187             $this->_aRecommList = false;
00188 
00189             // loading recomm list
00190             $aWishProdList = $this->getWishProductList();
00191             if ( is_array( $aWishProdList ) && ( $oSimilarProd = current( $aWishProdList ) ) ) {
00192                 $this->_aRecommList = oxNew( 'oxrecommlist' )->getRecommListsByIds( array( $oSimilarProd->getId() ) );
00193             }
00194         }
00195 
00196         return $this->_aRecommList;
00197     }
00198 
00207     public function sendWishList()
00208     {
00209         $aParams = oxConfig::getParameter( 'editval', true );
00210         if ( is_array( $aParams ) ) {
00211 
00212             $oParams = ( object ) $aParams;
00213             $this->setEnteredData( ( object ) oxConfig::getParameter( 'editval' ) );
00214 
00215             if ( !isset( $aParams['rec_name'] ) || !isset( $aParams['rec_email'] ) ||
00216                  !$aParams['rec_name'] || !$aParams['rec_email'] ) {
00217                 return oxUtilsView::getInstance()->addErrorToDisplay( 'ACCOUNT_WISHLIST_ERRCOMLETEFIELDSCORRECTLY', false, true );
00218             } else {
00219 
00220                 if ( $oUser = $this->getUser() ) {
00221                     $oParams->send_email = $oUser->oxuser__oxusername->value;
00222                     $oParams->send_name  = $oUser->oxuser__oxfname->getRawValue().' '.$oUser->oxuser__oxlname->getRawValue();
00223                     $oParams->send_id    = $oUser->getId();
00224 
00225                     $this->_blEmailSent = oxNew( 'oxemail' )->sendWishlistMail( $oParams );
00226                     if ( !$this->_blEmailSent ) {
00227                         return oxUtilsView::getInstance()->addErrorToDisplay( 'ACCOUNT_WISHLIST_ERRWRONGEMAIL', false, true );
00228                     }
00229                 }
00230 
00231                 $this->_aViewData['success'] = $this->isWishListEmailSent();
00232                 $this->_aViewData['editval'] = $this->getEnteredData();
00233             }
00234         }
00235     }
00236 
00242     public function isWishListEmailSent()
00243     {
00244         return $this->_blEmailSent;
00245     }
00246 
00254     public function setEnteredData( $oData )
00255     {
00256         $this->_aEditValues = $oData;
00257     }
00258 
00264     public function getEnteredData()
00265     {
00266         return $this->_aEditValues;
00267     }
00268 
00275     public function togglePublic()
00276     {
00277         if ( $oUser = $this->getUser() ) {
00278 
00279             $blPublic = (int) oxConfig::getParameter( 'blpublic' );
00280 
00281             $oBasket = $oUser->getBasket( 'wishlist' );
00282             $oBasket->oxuserbaskets__oxpublic = new oxField( ( $blPublic == 1 ) ? $blPublic : 0 );
00283             $oBasket->save();
00284         }
00285     }
00286 
00296     public function searchForWishList()
00297     {
00298         if ( $sSearch = oxConfig::getParameter( 'search' ) ) {
00299 
00300             // search for baskets
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 }