Changeset 702 for trunk/app/controllers

Show
Ignore:
Timestamp:
08/08/08 18:58:10 (4 months ago)
Author:
aarkerio
Message:

New validates

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/app/controllers/polls_controller.php

    r540 r702  
    2525      $this->pageTitle = 'Polls'; 
    2626       
    27       $conditions      = array("user_id" => $this->Auth->user('id')); 
     27      $conditions      = null; 
    2828      $fields          = array("id", "question", "created", "status"); 
    2929      $order           = "created DESC"; 
     
    3535 { 
    3636  $this->layout    = 'admin'; 
    37   $this->pageTitle = 'Add Poll'; 
     37  $this->pageTitle = __('Add Poll', true); 
    3838       
    39   if (!empty($this->data['Poll'])) 
    40   { 
     39  if (!empty($this->data['Poll'])): 
    4140    $this->Sanitize = new Sanitize; 
    4241          
    43     $this->Sanitize->clean($this->data['Poll']); //Hopefully this is enough 
    44           
    45     $this->Pollrow = new Pollrow; 
    46           
    47     $this->data['Poll']['user_id'] = $this->Auth->user('id'); 
     42    $this->Sanitize->clean($this->data['Poll']);                   
     43    $this->data['Poll']['user_id'] = (int) $this->Auth->user('id'); 
    4844      
    49      $this->Poll->create(); 
    50           
    51     if ( $this->Poll->save($this->data['Poll'])) 
    52     {    
    53         $this->Poll->id    = false; 
    54         $this->Pollrow->id = false; 
    55                  
    56         $poll_id = $this->Poll->getLastInsertID(); 
    57                  
    58         $colors = array('green', 'blue', 'brown', 'yellow', 'orange', 'red', 'black'); 
    59                  
    60                 $i = 0; 
    61                  
    62                 foreach($this->data['Row'] as $pollrow) 
    63                 { 
    64                        if ( strlen($pollrow) > 0 ) 
    65                        {   
    66                            if ( !$this->Pollrow->save(array('Pollrow' => array('answer' => $pollrow, 'poll_id' => $poll_id, 'color'=>$colors[$i], 'id'=>false) ) ) ) 
    67                            { 
    68                                      die("Error " . $pollrow . "<br />" . $poll_id . "<br />"); 
    69                            } 
    70                        } 
    71                  $i++; 
    72                 } 
    73              
    74             $this->msgFlash('Poll saved', '/admin/polls/listing'); 
    75              
    76      }  
    77      else 
    78      { 
    79             $this->flash('/admin/polls/listing', 'Error Pollrow model'); 
    80      }  
    81    } 
     45    if ( $this->Poll->save($this->data)):    
     46      $this->Poll->id    = false; 
     47      $this->Pollrow->id = false;             
     48      $poll_id           = $this->Poll->getLastInsertID(); 
     49      $colors            = array('green', 'blue', 'brown', 'yellow', 'orange', 'red', 'black');  
     50      $i                 = (int) 0; 
     51  
     52      foreach($this->data['Row'] as $pollrow): 
     53        if ( strlen($pollrow) > 0 ): 
     54 
     55          $this->data['Pollrow'] = array('answer' => $pollrow, 'poll_id' => $poll_id, 'color'=>$colors[$i], 'id'=>false); 
     56 
     57      if (!$this->Poll->Pollrow->save($this->data)): 
     58                             die("Error " . $pollrow . "<br />" . $poll_id . "<br />"); 
     59          endif; 
     60        endif;  
     61        $i++; 
     62      endforeach; 
     63    endif; 
     64  $this->msgFlash(__('Poll saved', true), '/admin/polls/listing');        
     65  endif; 
    8266 } 
    8367