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 
00090     protected $_iViewIndexState = 1;
00091 
00103     public function render()
00104     {
00105         parent::render();
00106 
00107         // is logged in ?
00108         $oUser = $this->getUser();
00109         if ( !$oUser ) {
00110             return $this->_sThisTemplate = $this->_sThisLoginTemplate;
00111         }
00112         // for older templates
00113         $this->_aViewData['blshowsuggest'] = $this->showSuggest();
00114         $this->_aViewData['similarrecommlist'] = $this->getSimilarRecommLists();
00115 
00116         $this->_aViewData['wishlist'] = $this->getWishList();
00117         if ( $this->getWishList() ) {
00118             $this->_aViewData['wishlist']->aList = $this->getWishProductList();
00119         }
00120 
00121         return $this->_sThisTemplate;
00122     }
00123 
00129     public function showSuggest()
00130     {
00131         if ( $this->_blShowSuggest === null ) {
00132             $this->_blShowSuggest = ( bool ) oxConfig::getParameter( 'blshowsuggest' );
00133         }
00134         return $this->_blShowSuggest;
00135     }
00136 
00142     public function getWishList()
00143     {
00144         if ( $this->_oWishList === null ) {
00145             $this->_oWishList = false;
00146 
00147             if ( $oUser = $this->getUser() ) {
00148                 $oWishList = $oUser->getBasket( 'wishlist' );
00149                 if ( $oWishListProducts = $oWishList->getArticles() ) {
00150                     // wish list
00151                     $this->_aWishProductList = $oWishListProducts;
00152                     $this->_oWishList = $oWishList;
00153                 }
00154             }
00155         }
00156 
00157         return $this->_oWishList;
00158     }
00159 
00165     public function getWishProductList()
00166     {
00167         if ( $this->_aWishProductList === null ) {
00168             $this->_aWishProductList = false;
00169 
00170             if ( $oWishList = $this->getWishList() ) {
00171                 return $this->_aWishProductList;
00172             }
00173         }
00174         return $this->_aWishProductList;
00175     }
00176 
00182     public function getSimilarRecommLists()
00183     {
00184         // recomm list
00185         if ( $this->_aRecommList === null ) {
00186 
00187             // just ensuring that next call will skip this check
00188             $this->_aRecommList = false;
00189 
00190             // loading recomm list
00191             $aWishProdList = $this->getWishProductList();
00192             if ( is_array( $aWishProdList ) && ( $oSimilarProd = current( $aWishProdList ) ) ) {
00193                 $oRecommList = oxNew('oxrecommlist');
00194                 $this->_aRecommList = $oRecommList->getRecommListsByIds( array( $oSimilarProd->getId() ) );
00195             }
00196         }
00197 
00198         return $this->_aRecommList;
00199     }
00200 
00209     public function sendWishList()
00210     {
00211         $aParams = oxConfig::getParameter( 'editval' );
00212 
00213         if ( !is_array( $aParams ) ) {
00214             return;
00215         }
00216 
00217         //setting pointer to first element
00218         reset( $aParams );
00219         $oParams = new OxstdClass();
00220         while ( list( $sName, $sValue ) = each( $aParams ) ) {
00221             $oParams->$sName = $sValue;
00222         }
00223         $this->_aEditValues = $oParams;
00224 
00225         if ( !$aParams['rec_name'] || !$aParams['rec_email'] ) {
00226             oxUtilsView::getInstance()->addErrorToDisplay('ACCOUNT_WISHLIST_ERRCOMLETEFIELDSCORRECTLY', false, true );
00227             return;
00228         }
00229 
00230         if ( $oUser = $this->getUser() ) {
00231 
00232             $oParams->send_email = $oUser->oxuser__oxusername->value;
00233             $oParams->send_name  = $oUser->oxuser__oxfname->value.' '.$oUser->oxuser__oxlname->value;
00234             $oParams->send_id    = $oUser->getId();
00235 
00236             $oEmail = oxNew( 'oxemail' );
00237             if ( !$oEmail->sendWishlistMail( $oParams ) ) {
00238                 oxUtilsView::getInstance()->addErrorToDisplay( 'ACCOUNT_WISHLIST_ERRWRONGEMAIL', false, true );
00239                 return;
00240             } else {
00241                 $this->_blEmailSent = true;
00242             }
00243         }
00244 
00245         $this->_aViewData['success'] = $this->isWishListEmailSent();
00246         $this->_aViewData['editval'] = $this->getEnteredData();
00247     }
00248 
00254     public function isWishListEmailSent()
00255     {
00256         return $this->_blEmailSent;
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             $blPublic = ( $blPublic == 1 )?$blPublic:0;
00281 
00282             $oBasket = $oUser->getBasket( 'wishlist' );
00283             $oBasket->oxuserbaskets__oxpublic = new oxField($blPublic);
00284             $oBasket->save();
00285         }
00286     }
00287 
00297     public function searchForWishList()
00298     {
00299         if ( $sSearch = oxConfig::getParameter( 'search' ) ) {
00300 
00301             // search for baskets
00302             $oUserList = oxNew( 'oxuserlist' );
00303             $oUserList->loadWishlistUsers( $sSearch );
00304             if ( $oUserList->count() ) {
00305                 $this->_oWishListUsers = $oUserList;
00306             }
00307 
00308             $this->_sSearchParam = $sSearch;
00309         }
00310 
00311         $this->_aViewData['search'] = $this->getWishListSearchParam();
00312         $this->_aViewData['wish_result'] = $this->getWishListUsers();
00313     }
00314 
00321     public function getWishListUsers()
00322     {
00323         return $this->_oWishListUsers;
00324     }
00325 
00331     public function getWishListSearchParam()
00332     {
00333         return $this->_sSearchParam;
00334     }
00335 }

Generated on Thu Dec 4 12:04:57 2008 for OXID eShop CE by  doxygen 1.5.5