hajtest
Current file: D:\websites\haj\application\controllers\RegisterController.php
Legend: executed not executed dead code

  Coverage
  Classes Functions / Methods Lines
Total
0.00%0.00%
0.00% 0 / 1
0.00%0.00%
0.00% 0 / 15
0.00%0.00%
0.00% 0 / 109
 
RegisterController
0.00%0.00%
0.00% 0 / 1
0.00%0.00%
0.00% 0 / 15
0.00%0.00%
0.00% 0 / 108
 public function init()
0.00%0.00%
0.00% 0 / 1
0.00%0.00%
0.00% 0 / 3
 public function indexAction()
0.00%0.00%
0.00% 0 / 1
0.00%0.00%
0.00% 0 / 2
 public function validateformAction()
0.00%0.00%
0.00% 0 / 1
0.00%0.00%
0.00% 0 / 7
 public function getPrice($price, $promos)
0.00%0.00%
0.00% 0 / 1
0.00%0.00%
0.00% 0 / 2
 public function processAction()
0.00%0.00%
0.00% 0 / 1
0.00%0.00%
0.00% 0 / 11
 public function getFormAndSelectedOrRedirect()
0.00%0.00%
0.00% 0 / 1
0.00%0.00%
0.00% 0 / 9
 public function setFormPrices($workshop_id)
0.00%0.00%
0.00% 0 / 1
0.00%0.00%
0.00% 0 / 12
 public function paypalAction()
0.00%0.00%
0.00% 0 / 1
0.00%0.00%
0.00% 0 / 15
 public function notifyAction()
0.00%0.00%
0.00% 0 / 1
0.00%0.00%
0.00% 0 / 14
 protected function saveUserToDatabase($post)
0.00%0.00%
0.00% 0 / 1
0.00%0.00%
0.00% 0 / 9
 protected function savePaymentToDatabase()
0.00%0.00%
0.00% 0 / 1
0.00%0.00%
0.00% 0 / 6
 public function returnAction()
0.00%0.00%
0.00% 0 / 1
0.00%0.00%
0.00% 0 / 1
 public function fillFormFromTable(Application_Form_Register $form)
0.00%0.00%
0.00% 0 / 1
0.00%0.00%
0.00% 0 / 6
 protected function logoutAction()
0.00%0.00%
0.00% 0 / 1
0.00%0.00%
0.00% 0 / 3
 protected function login()
0.00%0.00%
0.00% 0 / 1
0.00%0.00%
0.00% 0 / 7


       1                 :                                                                                                                 
       2               0 : <?php                                                                                                           
       3                 :                                                                                                                 
       4               0 : class RegisterController extends Zend_Controller_Action {                                                       
       5                 :                                                                                                                 
       6                 :     protected $_form;                                                                                           
       7                 :     protected $_selected;                                                                                       
       8                 :                                                                                                                 
       9                 :     public function init() {                                                                                    
      10               0 :         $this->_helper->_acl->allow(null);                                                                      
      11               0 :         $this->_form = new Application_Form_Register();                                                         
      12               0 :     }                                                                                                           
      13                 :                                                                                                                 
      14                 :     public function indexAction() {                                                                             
      15               0 :         $this->getFormAndSelectedOrRedirect();                                                                  
      16               0 :     }                                                                                                           
      17                 :                                                                                                                 
      18                 : // used for AJAX validation                                                                                     
      19                 :     public function validateformAction() {                                                                      
      20               0 :         $this->_helper->viewRenderer->setNoRender();                                                            
      21               0 :         $this->view->layout()->disableLayout();                                                                 
      22                 :                                                                                                                 
      23               0 :         $this->_form->isValid($this->getRequest()->getPost());                                                  
      24               0 :         $json = $this->_form->getMessages();                                                                    
      25               0 :         header('Content-type: application/json');                                                               
      26               0 :         echo Zend_Json::encode($json);                                                                          
      27               0 :     }                                                                                                           
      28                 : /**                                                                                                             
      29                 :  * Accepts selected price and string with promo codes ',' seperated.                                            
      30                 :  * Queries for promo code actions and calculates new price.                                                     
      31                 :  * @param int $price                                                                                            
      32                 :  * @param string $promos                                                                                        
      33                 :  * @return int                                                                                                  
      34                 :  */                                                                                                             
      35                 :     public function getPrice($price, $promos) {                                                                 
      36               0 :         PromoCodes::calculatePromos($price, $promos);                                                           
      37               0 :     }                                                                                                           
      38                 :                                                                                                                 
      39                 :     public function processAction() {                                                                           
      40               0 :         $this->getFormAndSelectedOrRedirect();                                                                  
      41               0 :         $post = $this->getRequest()->getPost();                                                                 
      42               0 :         if ($this->_form->isValid($post)) {                                                                     
      43               0 :             $this->_forward('paypal');                                                                          
      44               0 :         } else {                                                                                                
      45               0 :             $this->view->form = $this->_form->populate($post);                                                  
      46               0 :             $workshop_id = $post['workshop'];                                                                   
      47               0 :             if ($workshop_id) {                                                                                 
      48               0 :                 $this->view->selected = Workshops::findByIdJoinInstructorCategory($workshop_id);                
      49               0 :             }                                                                                                   
      50                 :         }                                                                                                       
      51               0 :     }                                                                                                           
      52                 :                                                                                                                 
      53                 :     public function getFormAndSelectedOrRedirect() {                                                            
      54               0 :         $workshop_id = $this->_getParam('workshop');                                                            
      55               0 :         if ($workshop_id) {                                                                                     
      56               0 :             $this->_selected = Workshops::findByIdJoinInstructorCategory($workshop_id);                         
      57                 :                                                                                                                 
      58               0 :             $this->setFormPrices($workshop_id);                                                                 
      59               0 :         } else {                                                                                                
      60               0 :             $this->_redirect('/workshops#scheduled');                                                           
      61                 :         }                                                                                                       
      62               0 :         $this->view->selected = $this->_selected;                                                               
      63               0 :         $this->view->form = $this->_form;                                                                       
      64               0 :     }                                                                                                           
      65                 :                                                                                                                 
      66                 :     /**                                                                                                         
      67                 :      * Finds prices set in workshop & Prices model and converts to array                                        
      68                 :      * @param int $workshop_id                                                                                   
      69                 :      */                                                                                                         
      70                 :     public function setFormPrices($workshop_id) {                                                               
      71               0 :         $additional = Prices::findAllbyWorkshopId($workshop_id);                                                
      72               0 :         $sel = $this->_selected[0];                                                                             
      73               0 :         $days = HAJ_Helpers::diffDate($sel->start_date, $sel->end_date);                                        
      74                 :                                                                                                                 
      75                 :         $prices = array(                                                                                        
      76               0 :             $sel->double_price => "$day day stay in a double occupnecy hale \${$sel->double_price}",          
      77               0 :             $sel->single_price => "$day day stay in a single occupnecy hale \${$sel->single_price}",          
      78               0 :             $sel->extra_price => "$day day stay in a double with a non-attending guest \${$sel->extra_price}",
					
      79               0 :         );                                                                                                      
      80               0 :         foreach ($additional as $add) {                                                                         
      81               0 :             $prices[$add->price] = "$add->desc \$$add->price";                                                  
      82               0 :         }                                                                                                       
      83               0 :         $this->_form->setPrice($prices);                                                                        
      84               0 :     }                                                                                                           
      85                 :                                                                                                                 
      86                 :     public function paypalAction() {                                                                            
      87               0 :         $this->_helper->layout->disableLayout();                                                                
      88               0 :         $post = $this->getRequest()->getPost();                                                                 
      89                 :                                                                                                                 
      90               0 :         $paypalInfo = Zend_Registry::get('config')->site->paypal;                                               
      91               0 :         $paypal = new HAJ_Paypal_Standard(true); // flag sets pp_sandbox_url                                    
      92               0 :         $paypal->setBusinessEmail($paypalInfo->businessEmail);                                                  
      93               0 :         $paypal->setPayer($post['email']);                                                                      
      94               0 :         $paypal->setAmount($post['price']);                                                                     
      95               0 :         $paypal->setWorkshop($post['workshop']);                                                                
      96               0 :         $paypal->addItem(array(                                                                                 
      97               0 :             'item_name' => "$paypalInfo->itemDesc",                                                             
      98               0 :             'item_amount' => $post['price'],                                                                    
      99               0 :             'quantity' => 1));                                                                                  
     100               0 :         $paypal->setControllerUrl("http://" . $this->getRequest()->getHttpHost() . $this->view->url());         
     101                 :                                                                                                                 
     102               0 :         $this->view->paypalForm = $paypal->form();                                                              
     103               0 :     }                                                                                                           
     104                 :                                                                                                                 
     105                 :     public function notifyAction() {                                                                            
     106               0 :         $this->_helper->viewRenderer->setNoRender();                                                            
     107               0 :         $this->_helper->layout->disableLayout();                                                                
     108                 :                                                                                                                 
     109               0 :         $post = $this->getRequest()->getPost();                                                                 
     110                 :         try {                                                                                                   
     111               0 :             if ($this->paypal()->validateNotify($post)) {                                                       
     112                 :                                                                                                                 
     113                 : //                $dbUserPayment = new Model_DbTable_Users_Payments();                                          
     114                 : //                $dbUserPayment->insert(array(                                                                 
     115                 : //                    "ifv_user_id" => $arrPost["payer_id"],                                                    
     116                 : //                    "txn_id" => $arrPost["txn_id"],                                                           
     117                 : //                    "credits" => $arrPost["custom"])                                                          
     118                 : //                );                                                                                            
     119                 :                                                                                                                 
     120               0 :                 Zend_Registry::get('log')->log($post, Zend_Log::NOTICE);                                        
     121               0 :                 $registered = new Registered();                                                                 
     122               0 :                 $registered->user_id = $post['payer_id'];                                                       
     123               0 :                 $registered->workshop_id = $post['workshop'];                                                   
     124               0 :                 $registered->amount_paid = $post['amount'];                                                     
     125               0 :                 $registered->save();                                                                            
     126               0 :             }                                                                                                   
     127               0 :         } catch (Exception $e) {                                                                                
     128               0 :             Zend_Registry::get('log')->log("{$e->getMessage()}", Zend_Log::ERR);                                
     129                 :         }                                                                                                       
     130               0 :     }                                                                                                           
     131                 :                                                                                                                 
     132                 :     protected function saveUserToDatabase($post) {                                                              
     133               0 :         $this->_form->populate($post);                                                                          
     134                 :                                                                                                                 
     135               0 :         $user = new Users();                                                                                    
     136               0 :         if ($this->_user)                                                                                       
     137               0 :             $user->id = $this->_user->id; // if user is logged in, update                                       
     138               0 :         $user = $this->_form->fillModel($user);                                                                 
     139               0 :         $user->user_type = 'member';                                                                            
     140               0 :         $user->save();                                                                                          
     141               0 :         Zend_Registry::get('log')->log("user created: $user->id", Zend_Log::NOTICE);                            
     142               0 :         return $user->id;                                                                                       
     143                 :     }                                                                                                           
     144                 :                                                                                                                 
     145                 :     protected function savePaymentToDatabase() {                                                                
     146                 :         // add user's selected class and payed amount:                                                          
     147               0 :         $registered = new Registered();                                                                         
     148               0 :         $registered->user_id = $user->id;                                                                       
     149               0 :         $registered->workshop_id = $this->_form->getElement('workshop')->getValue();                            
     150               0 :         $registered->amount_paid = 0;                                                                           
     151               0 :         $registered->save();                                                                                    
     152               0 :     }                                                                                                           
     153                 :                                                                                                                 
     154                 :     public function returnAction() {                                                                            
     155                 :                                                                                                                         
     156               0 :     }                                                                                                           
     157                 :                                                                                                                 
     158                 :     public function fillFormFromTable(Application_Form_Register $form) {                                        
     159               0 :         if ($this->isLoggedIn() && !$this->getRequest()->isPost()) {                                            
     160               0 :             $userId = Zend_Auth::getInstance()->getIdentity()->id;                                              
     161               0 :             $user = Users::findOne($userId);                                                                    
     162               0 :             $form->getSubForm('profile')->fillForm($user);                                                      
     163               0 :         }                                                                                                       
     164               0 :         return $form;                                                                                           
     165                 :     }                                                                                                           
     166                 :                                                                                                                 
     167                 :     protected function logoutAction() {                                                                         
     168               0 :         Zend_Auth::getInstance()->clearIdentity();                                                              
     169               0 :         $this->_redirect('/register/');                                                                         
     170               0 :     }                                                                                                           
     171                 :                                                                                                                 
     172                 :     protected function login() {                                                                                
     173               0 :         $adapter = new KHA_Auth_Adapter($this->_getParam('user'), md5($salt . $this->_getParam('pass')));       
     174               0 :         $result = Zend_Auth::getInstance()->authenticate($adapter);                                             
     175               0 :         if (Zend_Auth::getInstance()->hasIdentity()) {                                                          
     176               0 :             $this->_forward('index');                                                                           
     177               0 :         } else {                                                                                                
     178               0 :             $this->view->message = implode(' ', $result->getMessages());                                        
     179                 :         }                                                                                                       
     180               0 :     }                                                                                                           
     181                 :                                                                                                                 

Generated by PHPUnit 3.4.15 and Xdebug 2.1.0rc1 using PHP 5.3.1 at Mon Jan 17 15:42:18 PST 2011.