account_wishlist.php

Go to the documentation of this file.
00001 <?php
00002 
00012 class Account_Wishlist extends Account
00013 {
00019     protected $_sThisTemplate = 'page/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 
00099     public function render()
00100     {
00101         parent::render();
00102 
00103         // is logged in ?
00104         $oUser = $this->getUser();
00105         if ( !$oUser ) {
00106             return $this->_sThisTemplate = $this->_sThisLoginTemplate;
00107         }
00108 
00109         return $this->_sThisTemplate;
00110     }
00111 
00117     public function showSuggest()
00118     {
00119         if ( $this->_blShowSuggest === null ) {
00120             $this->_blShowSuggest = ( bool ) oxConfig::getParameter( 'blshowsuggest' );
00121         }
00122         return $this->_blShowSuggest;
00123     }
00124 
00130     public function getWishList()
00131     {
00132         if ( $this->_oWishList === null ) {
00133             $this->_oWishList = false;
00134             if ( $oUser = $this->getUser() ) {
00135                 $this->_oWishList = $oUser->getBasket( 'wishlist' );
00136                 if ( $this->_oWishList->isEmpty() ) {
00137                     $this->_oWishList = false;
00138                 }
00139             }
00140         }
00141 
00142         return $this->_oWishList;
00143     }
00144 
00150     public function getWishProductList()
00151     {
00152         if ( $this->_aWishProductList === null ) {
00153             $this->_aWishProductList = false;
00154             if ( $oWishList = $this->getWishList() ) {
00155                 $this->_aWishProductList = $oWishList->getArticles();
00156             }
00157         }
00158         return $this->_aWishProductList;
00159     }
00160 
00166     public function getSimilarRecommLists()
00167     {
00168         if ( !$this->getViewConfig()->getShowListmania() ) {
00169             return false;
00170         }
00171 
00172         // recomm list
00173         if ( $this->_aRecommList === null ) {
00174 
00175             // just ensuring that next call will skip this check
00176             $this->_aRecommList = false;
00177 
00178             // loading recomm list
00179             $aWishProdList = $this->getWishProductList();
00180             if ( is_array( $aWishProdList ) && ( $oSimilarProd = current( $aWishProdList ) ) ) {
00181                 $this->_aRecommList = oxNew( 'oxrecommlist' )->getRecommListsByIds( array( $oSimilarProd->getId() ) );
00182             }
00183         }
00184 
00185         return $this->_aRecommList;
00186     }
00187 
00193     public function sendWishList()
00194     {
00195         $aParams = oxConfig::getParameter( 'editval', true );
00196         if ( is_array( $aParams ) ) {
00197 
00198             $oParams = ( object ) $aParams;
00199             $this->setEnteredData( ( object ) oxConfig::getParameter( 'editval' ) );
00200 
00201             if ( !isset( $aParams['rec_name'] ) || !isset( $aParams['rec_email'] ) ||
00202                  !$aParams['rec_name'] || !$aParams['rec_email'] ) {
00203                 return oxUtilsView::getInstance()->addErrorToDisplay( 'FORM_WISHLIST_SUGGEST_ERRCOMLETEFIELDSCORRECTLY', false, true );
00204             } else {
00205 
00206                 if ( $oUser = $this->getUser() ) {
00207                     $oParams->send_email = $oUser->oxuser__oxusername->value;
00208                     $oParams->send_name  = $oUser->oxuser__oxfname->getRawValue().' '.$oUser->oxuser__oxlname->getRawValue();
00209                     $oParams->send_id    = $oUser->getId();
00210 
00211                     $this->_blEmailSent = oxNew( 'oxemail' )->sendWishlistMail( $oParams );
00212                     if ( !$this->_blEmailSent ) {
00213                         return oxUtilsView::getInstance()->addErrorToDisplay( 'FORM_WISHLIST_SUGGEST_ERRWRONGEMAIL', false, true );
00214                     }
00215                 }
00216             }
00217         }
00218     }
00219 
00225     public function isWishListEmailSent()
00226     {
00227         return $this->_blEmailSent;
00228     }
00229 
00237     public function setEnteredData( $oData )
00238     {
00239         $this->_aEditValues = $oData;
00240     }
00241 
00247     public function getEnteredData()
00248     {
00249         return $this->_aEditValues;
00250     }
00251 
00258     public function togglePublic()
00259     {
00260         if ( $oUser = $this->getUser() ) {
00261 
00262             $blPublic = (int) oxConfig::getParameter( 'blpublic' );
00263             $oBasket = $oUser->getBasket( 'wishlist' );
00264             $oBasket->oxuserbaskets__oxpublic = new oxField( ( $blPublic == 1 ) ? $blPublic : 0 );
00265             $oBasket->save();
00266         }
00267     }
00268 
00275     public function searchForWishList()
00276     {
00277         if ( $sSearch = oxConfig::getParameter( 'search' ) ) {
00278 
00279             // search for baskets
00280             $oUserList = oxNew( 'oxuserlist' );
00281             $oUserList->loadWishlistUsers( $sSearch );
00282             if ( $oUserList->count() ) {
00283                 $this->_oWishListUsers = $oUserList;
00284             }
00285 
00286             $this->_sSearchParam = $sSearch;
00287         }
00288     }
00289 
00296     public function getWishListUsers()
00297     {
00298         return $this->_oWishListUsers;
00299     }
00300 
00306     public function getWishListSearchParam()
00307     {
00308         return $this->_sSearchParam;
00309     }
00310 
00316     public function getBreadCrumb()
00317     {
00318         $aPaths = array();
00319         $aPath = array();
00320 
00321         $aPath['title'] = oxLang::getInstance()->translateString( 'PAGE_ACCOUNT_MY_ACCOUNT', oxLang::getInstance()->getBaseLanguage(), false );
00322         $aPath['link']  = oxSeoEncoder::getInstance()->getStaticUrl( $this->getViewConfig()->getSelfLink() . 'cl=account' );
00323         $aPaths[] = $aPath;
00324 
00325         $aPath['title'] = oxLang::getInstance()->translateString( 'PAGE_ACCOUNT_WISHLIST_TITLE', oxLang::getInstance()->getBaseLanguage(), false );
00326         $aPath['link']  = $this->getLink();
00327         $aPaths[] = $aPath;
00328 
00329         return $aPaths;
00330     }
00331 }