user_address.php

Go to the documentation of this file.
00001 <?php
00002 
00008 class User_Address extends oxAdminDetails
00009 {
00015     protected $_blDelete = false;
00016 
00024     public function render()
00025     {
00026         parent::render();
00027 
00028         $soxId = $this->getEditObjectId();
00029         if ( $soxId != "-1" && isset( $soxId)) {
00030             // load object
00031             $oUser = oxNew( "oxuser" );
00032             $oUser->load( $soxId);
00033 
00034             // load adress
00035             $soxAddressId = isset($this->sSavedOxid)?$this->sSavedOxid:oxConfig::getParameter( "oxaddressid");
00036             if ( $soxAddressId != "-1" && isset( $soxAddressId ) ) {
00037                 $oAdress = oxNew( "oxaddress" );
00038                 $oAdress->load( $soxAddressId );
00039                 $this->_aViewData["edit"] = $oAdress;
00040             }
00041 
00042             $this->_aViewData["oxaddressid"] = $soxAddressId;
00043 
00044             // generate selected
00045             $oAddressList = $oUser->getUserAddresses();
00046             foreach ( $oAddressList as $oAddress ) {
00047                 if ( $oAddress->oxaddress__oxid->value == $soxAddressId ) {
00048                     $oAddress->selected = 1;
00049                     break;
00050                 }
00051             }
00052 
00053             $this->_aViewData["edituser"] = $oUser;
00054         }
00055 
00056         $oCountryList = oxNew( "oxCountryList" );
00057         $oCountryList->loadActiveCountries( oxRegistry::getLang()->getObjectTplLanguage() );
00058 
00059         $this->_aViewData["countrylist"] = $oCountryList;
00060 
00061         if (!$this->_allowAdminEdit($soxId))
00062             $this->_aViewData['readonly'] = true;
00063 
00064         return "user_address.tpl";
00065     }
00066 
00072     public function save()
00073     {
00074         parent::save();
00075 
00076         if ( $this->_allowAdminEdit( $this->getEditObjectId() ) ) {
00077             $aParams = oxConfig::getParameter( "editval" );
00078             $oAdress = oxNew( "oxaddress" );
00079             if ( isset( $aParams['oxaddress__oxid'] ) && $aParams['oxaddress__oxid'] == "-1" ) {
00080                 $aParams['oxaddress__oxid'] = null;
00081             } else {
00082                 $oAdress->load( $aParams['oxaddress__oxid'] );
00083             }
00084 
00085             $oAdress->assign( $aParams );
00086             $oAdress->save();
00087 
00088             $this->sSavedOxid = $oAdress->getId();
00089         }
00090     }
00091 
00097     public function delAddress()
00098     {
00099         $this->_blDelete = false;
00100         if ( $this->_allowAdminEdit( $this->getEditObjectId() ) ) {
00101             $aParams = oxConfig::getParameter( "editval" );
00102             if ( isset( $aParams['oxaddress__oxid'] ) && $aParams['oxaddress__oxid'] != "-1" ) {
00103                 $oAdress = oxNew( "oxaddress" );
00104                 $this->_blDelete = $oAdress->delete( $aParams['oxaddress__oxid'] );
00105             }
00106         }
00107     }
00108 }