Changeset 653 for trunk/app/controllers

Show
Ignore:
Timestamp:
07/15/08 14:38:50 (4 months ago)
Author:
aarkerio
Message:

Messages and news imprved

Location:
trunk/app/controllers
Files:
3 modified

Legend:

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

    r636 r653  
    1414class DiscussionsController extends AppController 
    1515{ 
    16  public $name          = 'Discussions'; 
    17  
    1816 public $helpers       = array('Ajax', 'Gags'); 
    1917 
     
    4644     $this->data['Discussion']['comment'] = nl2br($this->data['Discussion']['comment']); 
    4745            
    48      if ( $this->Auth->user() ) 
    49      { 
     46     if ( $this->Auth->user() ): 
    5047          $this->data['Discussion']['user_id']  = $this->Auth->user('id'); 
    5148          $this->data['Discussion']['username'] = $this->Auth->user('username'); 
    52      } 
    53      else 
    54      { 
     49     else: 
    5550       /*if ($this->data['Discussion']['captcha'] != $this->Session->read('captcha') || strlen($this->data['Discussion']['captcha']) < 3) 
    5651       { 
     
    5954                 
    6055         $this->data['Discussion']['user_id'] = 0; 
    61      } 
     56     endif; 
    6257          
    6358     if ( $this->Discussion->save($this->data) ):  //save the comment 
     
    6762          $this->__sendMail($user_id, $this->data['Discussion']['new_id']); 
    6863                 
    69           $this->redirect('/news/view/'.$this->data['Discussion']['new_id'].'#cnews'); 
     64          $this->msgFlash(__('Message waiting for approval', true), '/news/view/'.$this->data['Discussion']['new_id'].'#cnews'); 
    7065     endif; 
    7166   } 
     
    115110   $this->layout    = 'admin'; 
    116111 
    117    $this->pageTitle = 'Comments on News'; 
     112   $this->pageTitle = __('Comments on News', true); 
    118113 
    119114   $this->Discussion->bindModel(array('belongsTo'=> array('News' =>array('className'=> 'News', 'foreignKey'=> 'new_id' ))));    
     115    
     116   $this->paginate['fields'] = array('Discussion.id','News.id','News.title','Discussion.id','Discussion.comment', 'Discussion.created', 'Discussion.user_id', 'Discussion.status', 'User.username');  
     117   $this->paginate['conditions']   = null; 
     118   $this->paginate['order']        = "Discussion.id DESC"; 
     119   $this->paginate['limit']        = 30; 
     120   $data = $this->paginate('Discussion'); 
    120121 
    121    $conditions  = null; 
    122     
    123    $fields = array('Discussion.id','News.id','News.title','Discussion.id','Discussion.comment', 'Discussion.created', 'Discussion.user_id', 'Discussion.status', 'User.username'); 
    124  
    125    $order  = "Discussion.id DESC"; 
    126     
    127    $limit  = 50;      
     122   $this->set(compact('data')); 
    128123     
    129    $this->set('data', $this->Discussion->findAll($conditions, $fields, $order, $limit)); 
    130124 } 
    131125  
  • trunk/app/controllers/messages_controller.php

    r652 r653  
    6565      $this->set('nick', $nick); 
    6666 } 
    67   
     67/* 
     68 * deliver method, used to deliver message in /messages/message and /message/compose  views 
     69 * 
     70 */ 
    6871 public function deliver() 
    69  { 
    70      
     72 {     
    7173    if (!empty($this->data['Message'])): 
    7274       
    73            $this->Sanitize = new Sanitize; 
    74             
    75            $this->Sanitize->html($this->data['Message']['title']); 
    76             
    77            $this->Sanitize->html($this->data['Message']['body']); 
    78             
    79            $this->data['Message']['sender']   = $this->Auth->user('id');  
    80            $this->data['Message']['username'] = $this->Auth->user('username'); 
    81  
    82            if ( $this->Message->save($this->data) ): 
    83                 $this->__sendMail($this->data['Message']['user_id']); 
     75      $this->Sanitize = new Sanitize; 
     76            
     77      $this->Sanitize->html($this->data['Message']['title']); 
     78            
     79      $this->Sanitize->html($this->data['Message']['body']); 
     80            
     81      $this->data['Message']['sender']   = $this->Auth->user('id');  
     82            
     83      if ( !isset( $this->data['Message']['user_id'] ) ): 
     84        $this->data['Message']['user_id'] = $this->Message->User->field('User.id',array('User.username'=>trim($this->data['Message']['sender']))); 
     85      endif; 
     86 
     87      if ( $this->Message->save($this->data) ): 
     88            $this->__sendMail($this->data['Message']['user_id']); 
     89            if ( isset($this->data['Message']['ajax']) ): 
     90           $this->render('sent', 'ajax');     
     91        else: 
    8492            $this->msgFlash(__('Message sent', true), '/messages/listing'); 
    85            endif; 
     93            endif; 
     94      endif; 
    8695   endif; 
    8796 } 
  • trunk/app/controllers/news_controller.php

    r648 r653  
    119119         
    120120      $this->layout = 'admin'; 
    121          
    122       $conditions   = array("News.user_id" => $this->Auth->user('id') );             // only the user's news 
    123       $fields       = array("id", "title", "body", "created", "reference", "status", "theme_id", "user_id"); 
    124       $order        = "News.id DESC"; 
    125       $limit      = 20; 
    126          
    127       $this->set('data', $this->News->findAll($conditions, $fields, $order, $limit));  
     121      $this->News->unbindModel(array('hasMany'=>array('Discussion')));   
     122      $this->paginate['conditions']   = null; 
     123      $this->paginate['fields']       = array('News.id', 'News.title', 'News.created', 'News.status',  'News.user_id', 'User.username'); 
     124      $this->paginate['order']        = 'News.id DESC'; 
     125      $this->paginate['limit']        = 20; 
     126      $data = $this->paginate('News'); 
     127 
     128      $this->set(compact('data')); 
    128129  } 
    129130