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 $_aSimilarRecommListIds = null;
00090 
00096     protected $_iViewIndexState = VIEW_INDEXSTATE_NOINDEXNOFOLLOW;
00097 
00106     public function render()
00107     {
00108         parent::render();
00109 
00110         // is logged in ?
00111         $oUser = $this->getUser();
00112         if ( !$oUser ) {
00113             return $this->_sThisTemplate = $this->_sThisLoginTemplate;
00114         }
00115 
00116         return $this->_sThisTemplate;
00117     }
00118 
00124     public function showSuggest()
00125     {
00126         if ( $this->_blShowSuggest === null ) {
00127             $this->_blShowSuggest = ( bool ) oxConfig::getParameter( 'blshowsuggest' );
00128         }
00129         return $this->_blShowSuggest;
00130     }
00131 
00137     public function getWishList()
00138     {
00139         if ( $this->_oWishList === null ) {
00140             $this->_oWishList = false;
00141             if ( $oUser = $this->getUser() ) {
00142                 $this->_oWishList = $oUser->getBasket( 'wishlist' );
00143                 if ( $this->_oWishList->isEmpty() ) {
00144                     $this->_oWishList = false;
00145                 }
00146             }
00147         }
00148 
00149         return $this->_oWishList;
00150     }
00151 
00157     public function getWishProductList()
00158     {
00159         if ( $this->_aWishProductList === null ) {
00160             $this->_aWishProductList = false;
00161             if ( $oWishList = $this->getWishList() ) {
00162                 $this->_aWishProductList = $oWishList->getArticles();
00163             }
00164         }
00165         return $this->_aWishProductList;
00166     }
00167 
00173     public function getSimilarRecommListIds()
00174     {
00175         if ( $this->_aSimilarRecommListIds === null ) {
00176             $this->_aSimilarRecommListIds = false;
00177 
00178             $aWishProdList = $this->getWishProductList();
00179             if ( is_array( $aWishProdList ) && ( $oSimilarProd = current( $aWishProdList ) ) ) {
00180                 $this->_aSimilarRecommListIds = array( $oSimilarProd->getId() );
00181             }
00182         }
00183 
00184         return $this->_aSimilarRecommListIds;
00185     }
00186 
00192     public function sendWishList()
00193     {
00194         if (!oxRegistry::getSession()->checkSessionChallenge()) {
00195             return false;
00196         }
00197 
00198         $aParams = oxConfig::getParameter( 'editval', true );
00199         if ( is_array( $aParams ) ) {
00200 
00201             $oParams = ( object ) $aParams;
00202             $this->setEnteredData( ( object ) oxConfig::getParameter( 'editval' ) );
00203 
00204             if ( !isset( $aParams['rec_name'] ) || !isset( $aParams['rec_email'] ) ||
00205                  !$aParams['rec_name'] || !$aParams['rec_email'] ) {
00206                 return oxRegistry::get("oxUtilsView")->addErrorToDisplay( 'ERROR_MESSAGE_COMPLETE_FIELDS_CORRECTLY', false, true );
00207             } else {
00208 
00209                 if ( $oUser = $this->getUser() ) {
00210                     $oParams->send_email = $oUser->oxuser__oxusername->value;
00211                     $oParams->send_name  = $oUser->oxuser__oxfname->getRawValue().' '.$oUser->oxuser__oxlname->getRawValue();
00212                     $oParams->send_id    = $oUser->getId();
00213 
00214                     $this->_blEmailSent = oxNew( 'oxemail' )->sendWishlistMail( $oParams );
00215                     if ( !$this->_blEmailSent ) {
00216                         return oxRegistry::get("oxUtilsView")->addErrorToDisplay( 'ERROR_MESSAGE_CHECK_EMAIL', false, true );
00217                     }
00218                 }
00219             }
00220         }
00221     }
00222 
00228     public function isWishListEmailSent()
00229     {
00230         return $this->_blEmailSent;
00231     }
00232 
00240     public function setEnteredData( $oData )
00241     {
00242         $this->_aEditValues = $oData;
00243     }
00244 
00250     public function getEnteredData()
00251     {
00252         return $this->_aEditValues;
00253     }
00254 
00261     public function togglePublic()
00262     {
00263         if (!oxRegistry::getSession()->checkSessionChallenge()) {
00264             return false;
00265         }
00266 
00267         if ( $oUser = $this->getUser() ) {
00268 
00269             $blPublic = (int) oxConfig::getParameter( 'blpublic' );
00270             $oBasket = $oUser->getBasket( 'wishlist' );
00271             $oBasket->oxuserbaskets__oxpublic = new oxField( ( $blPublic == 1 ) ? $blPublic : 0 );
00272             $oBasket->save();
00273         }
00274     }
00275 
00282     public function searchForWishList()
00283     {
00284         if ( $sSearch = oxConfig::getParameter( 'search' ) ) {
00285 
00286             // search for baskets
00287             $oUserList = oxNew( 'oxuserlist' );
00288             $oUserList->loadWishlistUsers( $sSearch );
00289             if ( $oUserList->count() ) {
00290                 $this->_oWishListUsers = $oUserList;
00291             }
00292 
00293             $this->_sSearchParam = $sSearch;
00294         }
00295     }
00296 
00303     public function getWishListUsers()
00304     {
00305         return $this->_oWishListUsers;
00306     }
00307 
00313     public function getWishListSearchParam()
00314     {
00315         return $this->_sSearchParam;
00316     }
00317 
00323     public function getBreadCrumb()
00324     {
00325         $aPaths = array();
00326         $aPath = array();
00327 
00328         $aPath['title'] = oxRegistry::getLang()->translateString( 'MY_ACCOUNT', oxRegistry::getLang()->getBaseLanguage(), false );
00329         $aPath['link']  = oxRegistry::get("oxSeoEncoder")->getStaticUrl( $this->getViewConfig()->getSelfLink() . 'cl=account' );
00330         $aPaths[] = $aPath;
00331 
00332         $aPath['title'] = oxRegistry::getLang()->translateString( 'MY_GIFT_REGISTRY', oxRegistry::getLang()->getBaseLanguage(), false );
00333         $aPath['link']  = $this->getLink();
00334         $aPaths[] = $aPath;
00335 
00336         return $aPaths;
00337     }
00338 }