Changeset 632

Show
Ignore:
Timestamp:
07/07/08 22:23:03 (5 months ago)
Author:
aarkerio
Message:

Adding annotations

Location:
trunk/app
Files:
5 modified

Legend:

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

    r630 r632  
    1616 public function add() 
    1717 { 
    18   if (!empty($this->data['CommentsLesson']) ): 
     18  if (!empty($this->data['Annotation']) ): 
    1919       
    2020    $this->Sanitize = new Sanitize; 
    2121        
    22     $this->Sanitize->clean($this->data['CommentsLesson']);  
    23         
    24     $this->Comment->create(); 
    25         
    26     if ($this->Comment->save($this->data['CommenttsLesson'])): 
    27            $this->msgFlash(__('Comment added', true), $this->data['CommenttsLesson']['redirect_to'].'/#comments'); 
     22    $this->Sanitize->clean($this->data['Annotation']); 
     23 
     24    $this->data['Annotation']['user_id'] = $this->Auth->user('id');   
     25      
     26    $this->Annotation->create(); 
     27 
     28    if ($this->Annotation->save($this->data['Annotation'])): 
     29          $this->msgFlash(__('Comment added', true), $this->data['Annotation']['redirect_to'].'/#comments'); 
    2830    endif; 
    2931 endif; 
     
    3335  
    3436  // change status enabled/disabled actived 
    35   public function admin_change($comment_id, $status) 
     37  public function admin_change($annotation_id, $status) 
    3638  {  
    37     $this->data['Comment']['status'] = ($status == 0 ) ? 1 : 0; 
     39    $this->data['Annotation']['status'] = ($status == 0 ) ? 1 : 0; 
    3840      
    39     $this->data['Comment']['id']     = $comment_id; 
     41    $this->data['Annotation']['id']     = $annotation_id; 
    4042       
    41     if ($this->Comment->save($this->data['Comment'])): 
    42       $this->msgFlash('Comment status changed', '/admin/entries/comments'); 
     43    if ($this->Annotation->save($this->data['Annotation'])): 
     44      $this->msgFlash('Annotation status changed', '/admin/entries/comments'); 
    4345    endif; 
    4446  } 
     
    4850    $this->layout    = 'admin'; 
    4951      
    50     if ( empty( $this->data["Comment"] ) ): 
    51       $this->data      = $this->Comment->read(null, $id); 
     52    if ( empty( $this->data["Annotation"] ) ): 
     53      $this->data      = $this->Annotation->read(null, $id); 
    5254    else: 
    5355    $this->Sanitize = new Sanitize; 
    5456          
    55     $this->Sanitize->html($this->data["Comment"]["comment"]); 
     57    $this->Sanitize->html($this->data["Annotation"]["comment"]); 
    5658          
    57     if ($this->Comment->save($this->data["Comment"])):   
    58       $this->msgFlash('Comment saved!', '/admin/comments/edit/'.$this->data["Comment"]["id"]); 
     59    if ($this->Annotation->save($this->data["Annotation"])):   
     60       $this->msgFlash('Annotation saved!', '/admin/comments/edit/'.$this->data["Annotation"]["id"]); 
    5961    endif; 
    60     endif; 
     62   endif; 
    6163  } 
    6264  
    63   public function admin_delete($id) 
     65  public function admin_delete($annotation_id) 
    6466  { 
    65     if ($this->Comment->del($id)): 
    66        $this->msgFlash('Comment deleted', '/admin/comments/listing'); 
     67    if ($this->Annotation->del($annotation_id)): 
     68        $this->msgFlash('Annotation deleted', '/admin/comments/listing'); 
    6769    endif; 
    6870  } 
  • trunk/app/controllers/lessons_controller.php

    r625 r632  
    3434        $this->LessonTitle = 'Lesson'; 
    3535         
    36         $conditions        = array("Lesson.id"=>$id, "Lesson.status"=>1); 
     36        $conditions        = array('Lesson.id'=>$id, 'Lesson.status'=>1); 
    3737         
    38         $fields            = array("Lesson.id", "Lesson.title", "Lesson.body", "Lesson.created", "Lesson.modified"); 
     38        $fields            = array('Lesson.id', 'Lesson.title', 'Lesson.body', 'Lesson.created', 'Lesson.modified', 'Annotation.comment'); 
    3939         
    4040        $order             = null; 
    4141         
    42         $this->set('data', $this->Lesson->find($conditions, $fields, $order, null, null, 0)); 
     42        $this->set('data', $this->Lesson->find($conditions)); 
    4343 } 
    4444     
  • trunk/app/models/annotation.php

    r630 r632  
    1313                  'conditions' => '', 
    1414                  'order'      => '', 
    15                                  'foreignKey' => 'user_id' 
     15                                 'foreignKey'  => 'user_id' 
    1616                  ), 
    1717                           'Lesson' => 
     
    1919                  'conditions' => '', 
    2020                  'order'      => null, 
    21                                  'foreignKey' => 'lersson_id' 
     21                                  'foreignKey' => 'lesson_id' 
    2222                  ) 
    2323                ); 
    2424 
    2525  public $validate = array( 
    26       'comment' => VALID_NOT_EMPTY, 
    27       'user_id' => VALID_NOT_EMPTY 
     26      'comment'   => VALID_NOT_EMPTY, 
     27      'user_id'   => VALID_NOT_EMPTY, 
     28      'lesson_id' => VALID_NOT_EMPTY 
    2829   ); 
    2930/* 
  • trunk/app/models/lesson.php

    r630 r632  
    2525                ); 
    2626 
    27   public $hasMany = array('CommentsLesson' => 
    28                         array('className'     => 'CommentsLesson', 
     27  public $hasMany = array('Annotation' => 
     28                        array('className'     => 'Annotation', 
    2929                  'conditions'    =>  null, 
    30                   'order'         => 'CommentsLesson.created', 
     30                  'order'         => 'Annotation.created', 
    3131                  'limit'         => null, 
    3232                  'foreignKey'    => 'lesson_id', 
  • trunk/app/views/lessons/view.ctp

    r630 r632  
    11<?php 
     2//die(debug($data)); 
    23  echo '<h1>'  .$data['Lesson']['title']   . '</h1>'; 
    34  echo $html->div(null, $data['Lesson']['body']); 
    45  echo $html->div(null, __('Last edition', true). ': '.$data['Lesson']['created']); 
    56   
    6   echo $form->create('CommentsLesson', array('onsubmit'=>'return chkForm()', 'action'=>'add')); 
    7   echo $form->hidden('CommentsLesson.redirect_to', array('value'=>'/lessons/view/'.$blog['User']['username'].'/'.$data['Lesson']['id'])); 
    8   echo $form->hidden('CommentsLesson.lesson_id', array('value'=>$data['Lesson']['id'])); 
     7  echo $form->create('Annotation', array('onsubmit'=>'return chkForm()', 'action'=>'add')); 
     8  echo $form->hidden('Annotation.redirect_to', array('value'=>'/lessons/view/'.$blog['User']['username'].'/'.$data['Lesson']['id'])); 
     9  echo $form->hidden('Annotation.lesson_id', array('value'=>$data['Lesson']['id'])); 
    910        
    1011  if ( $session->check('Auth.User') ): 
     
    1516   echo $session->read('Auth.User.username') . ' ' . __('writes', true); 
    1617                  
    17    echo $form->label('CommentsLesson.comment', 'Comment'); 
    18    echo $form->textarea('CommentsLesson.comment', array('rows' => 10, 'cols' => 50)); 
    19    echo $form->error('CommentsLesson.comment', 'A comment is required.'); 
     18   echo $form->label('Annotation.comment', 'Comment'); 
     19   echo $form->textarea('Annotation.comment', array('rows' => 10, 'cols' => 50)); 
     20   echo $form->error('Annotation.comment', 'A comment is required.'); 
    2021         
    2122   echo $form->end(__('Send', true));