Changeset 461

Show
Ignore:
Timestamp:
05/08/08 11:43:23 (8 months ago)
Author:
aarkerio
Message:

Forums and topics improveds

Location:
trunk/app
Files:
1 added
12 modified

Legend:

Unmodified
Added
Removed
  • trunk/app/config/sql/postgresql/replies.sql

    r436 r461  
    33 reply text NOT NULL, 
    44 created timestamp(0) with time zone DEFAULT now() NOT NULL, 
    5  topic_id integer NOT NULL REFERENCES topics(id) ON DELETE CASCADE, 
    6  user_id integer NOT NULL REFERENCES users(id) ON DELETE CASCADE, 
     5 topic_id int NOT NULL REFERENCES topics(id) ON DELETE CASCADE, 
     6 vclassroom_id int NOT NULL REFERENCES vclassrooms(id) ON DELETE CASCADE, -- just one facility to create student's reports 
     7 user_id int NOT NULL REFERENCES users(id) ON DELETE CASCADE, 
    78 status int NOT NULL DEFAULT 1 
    89); 
  • trunk/app/config/sql/postgresql/visitors.sql

    r436 r461  
    22  id serial PRIMARY KEY, 
    33  user_id   int NOT NULL REFERENCES users(id) ON DELETE CASCADE, 
    4   topic_id int NOT NULL REFERENCES topics(id) ON DELETE CASCADE, 
    5   UNIQUE (user_id, topic_id)  -- constraint 
     4  topic_id int NOT NULL REFERENCES topics(id) ON DELETE CASCADE 
    65);  
    7  
    8  
  • trunk/app/controllers/forums_controller.php

    r397 r461  
    88*  @package Karamelo 
    99*/ 
    10 // file : app/controller/faqs_controller.php 
     10// file : app/controller/forums_controller.php 
    1111 
    1212uses('sanitize'); 
     
    1616 public $helpers       = array('Javascript', 'Ajax', 'Time'); 
    1717  
    18  public $components    = array('Edublog'); 
     18 public $components    = array('Edublog', 'Email'); 
    1919  
    2020 public function beforeFilter()  
     
    3636 } 
    3737  
    38   
    3938 public function index($user_id)  
    4039 {       
     
    137136   $this->layout = 'admin'; 
    138137    
    139    $vclassrooms = $this->Forum->getVclassrooms($this->Auth->user('id')); 
    140     
    141    $this->set('vclassrooms', $vclassrooms); 
     138   $this->set('vclassrooms', $this->Forum->getVclassrooms($this->Auth->user('id'))); 
    142139 
    143140   if ( !empty( $this->data['Forum'] ) ) 
     
    164161 public function admin_edit($id = null) 
    165162 { 
    166    $vclassrooms = $this->Forum->getVclassrooms($this->Auth->user('id')); 
    167     
    168    $this->set('vclassrooms', $vclassrooms); 
     163  
     164  $this->set('vclassrooms', $this->Forum->getVclassrooms($this->Auth->user('id'))); 
    169165 
    170166  if (empty($this->data['Forum'])) 
  • trunk/app/controllers/replies_controller.php

    r400 r461  
    1313  
    1414 public $components    = array('Edublog'); 
     15 
     16 public function beforeFilter()  
     17 { 
     18    $this->Auth->allow(array('add', 'reply')); 
     19    parent::beforeFilter(); 
     20 } 
    1521  
    1622 public function isAuthorized() 
     
    2632 } 
    2733  
    28  public function display($user_id, $forum_id, $topic_id) 
    29  {   
    30      $this->pageTitle = 'Discussion'; 
    31       
    32      $this->layout    = $this->Edublog->layout($user_id); 
    33       
    34      $this->Edublog->blog($user_id); 
    35       
    36      $conditions = array('Reply.status'=>1, 'Reply.id'=>$topic_id); 
    37      $fields     = null; 
    38      $order      = 'Reply.created DESC'; 
    39       
    40      $this->set('data', $this->Reply->find($conditions, $fields, $order)); 
    41  } 
    42   
    43  public function add($username=null, $forum_id = null)  
     34 public function add()  
    4435 { 
    4536   if (!empty($this->data['Reply'])) 
  • trunk/app/controllers/topics_controller.php

    r339 r461  
    1414 public $components    = array('Edublog'); 
    1515  
    16 public function beforeFilter()  
     16 public function beforeFilter()  
    1717 { 
    1818    $this->Auth->allow(array('display', 'add', 'reply')); 
     
    4747   $this->Topic->Forum->unbindModel(array('hasMany'=>array('Topic'))); 
    4848   $data =  $this->Topic->find($conditions, $fields, $order, 2); 
     49   //die(debug($data)); 
    4950   $this->set('data',$data); 
    5051 
    51    if ( $this->Auth->user('id') ) 
     52   if ( !$this->Session->check('topic'.$topic_id)  ) // add 1 to visit 
    5253   {  
    53         $this->Topic->addVisitor($data['Visitor'],  $this->Auth->user('id'), $data['Topic']['id']); 
     54        $this->Topic->addVisitor($topic_id, $this->Auth->user('id')); 
     55        $this->Session->write('topic'.$topic_id,  $topic_id); //set session, only one visit per session 
    5456   } 
    5557 } 
    5658   
    57  public function add($username=null, $forum_id = null)  
     59 public function add($vclassroom_id = null, $forum_id = null)  
    5860 { 
     61   $this->layout='ajax'; 
     62 
    5963   if (!empty($this->data['Topic'])) 
    6064   {  
     
    7478   else  
    7579   { 
    76       $user_id = $this->Topic->User->field('id', array('User.username'=>$username)); 
    77        
    78       $this->layout    = $this->Edublog->layout($user_id); 
    79        
    80       $this->Edublog->blog($user_id); 
    81        
    8280      $this->set('forum_id', $forum_id); 
    83     } 
    84      
     81      $this->set('vclassroom_id', $vclassroom_id); 
     82   }  
    8583 } 
    8684  
    87  public function reply($user_id, $forum_id, $topic_id)  
     85 public function reply($vclassroom_id, $forum_id, $topic_id, $blogger_id)  
    8886 { 
    8987       // adds new reply to topic 
    9088        
    91        $this->layout    = $this->Edublog->layout($user_id); 
     89       $this->layout    = 'ajax'; 
    9290        
    93        $this->Edublog->blog($user_id); 
    94         
    95        $this->set('forum_id', $forum_id); 
    96        $this->set('topic_id', $topic_id); 
     91       $this->set('forum_id',      $forum_id); 
     92       $this->set('topic_id',      $topic_id); 
     93       $this->set('blogger_id',    $blogger_id); 
     94       $this->set('vclassroom_id', $vclassroom_id); 
    9795 } 
    9896  
  • trunk/app/models/topic.php

    r333 r461  
    22/** 
    33*  Karamelo eLearning Platform 
    4 *  Chipotle Software 2002-2008  
     4*  Chipotle Software 2002-2008 
     5*  @author: Manuel Montoya  
    56*  GPLv3 manuel<arroba>mononeurona<punto>org 
    67**/  
     8// file: app/models/topic.php 
    79 
    810class Topic extends AppModel 
     
    4648        ); */ 
    4749 
    48   public function addVisitor($users = array(), $user_id, $topic_id)   
    49   { // this is just to set a flag to indicate user is visiting topic for first time 
    50      
    51     $ids = array(); 
    52     //die(var_dump( $users  )); 
    53     foreach ($users as $v) 
    54     {  
    55        array_push($ids, $v['id']); 
    56     } 
    57      
    58     if ( in_array($user_id, $ids) ) 
    59     { 
    60       return false; 
    61     } 
    62     else 
    63     { 
    64         $this->data['Visitor']['topic_id'] = $topic_id;  
    65         $this->data['Visitor']['user_id']  = $user_id; 
    66         $this->Visitor->create(); 
    67  
    68         if ( $this->Visitor->save( $this->data['Visitor'] ) ) 
    69         { 
    70           return true; 
    71         } 
    72         else 
    73         { 
    74           die('Error on addVisitor function'); 
    75         } 
    76     } 
    77     return true; 
    78   } 
    79  
    80   public $validate = array( 
     50 public $validate = array( 
    8151      'subject' => VALID_NOT_EMPTY, 
    8252      'message' => VALID_NOT_EMPTY, 
     
    8454      'forum_id' => VALID_NOT_EMPTY 
    8555      ); 
     56 
     57  public function addVisitor($topic_id, $user_id)   
     58  {  
     59    $this->data['Visitor']['topic_id'] = $topic_id;  
     60    $this->data['Visitor']['user_id']  = $user_id; 
     61 
     62    $this->Visitor->create(); 
     63 
     64    if ( $this->Visitor->save( $this->data['Visitor'] ) ): 
     65          return true; 
     66    else: 
     67          die('Error on addVisitor function'); 
     68    endif; 
     69 
     70    return true; 
     71  } 
    8672} 
    8773?> 
  • trunk/app/views/forums/admin_edit.ctp

    r321 r461  
    1212?> 
    1313<br /> 
     14<?php 
     15  echo $form->label('Forum.vclassroom_id', 'Class:'); 
     16  echo $form->select('Forum.vclassroom_id', $vclassrooms, null, null, false); 
     17?> 
    1418<br /> 
    1519<?php  
  • trunk/app/views/forums/display.ctp

    r333 r461  
    77               ); 
    88 
    9     echo  $html->div('titentry', $data["Forum"]["title"]); 
    10     echo  $html->para(null, $data["Forum"]["description"]); 
     9 echo  $html->div('titentry', $data["Forum"]["title"]); 
     10 echo  $html->para(null, $data["Forum"]["description"]); 
    1111 
    12     echo $html->div(null,  
    13                     $html->link($html->image('static/new_post.gif', array("alt"=>"Add new topic", "title"=>"Add new topic")),  
    14                       '/topics/add/'.$blog["User"]["username"].'/'.$data["Forum"]["id"],  
    15                       null, null, false) 
    16               ); 
     12  $tmp = $ajax->link($html->image("static/new_post.gif", array("alt"=>"New Topic", "title"=>"New Topic")), '/topics/add/'.$data['Vclassroom']['id'].'/'.$data['Forum']['id'], 
     13                                array("update" => "qn", 
     14                              "loading"=>"Element.show('loading3');", 
     15                          "complete"=>"Element.hide('loading3');Effect.Appear('qn')"), 
     16                               null, 
     17                               false 
     18                               ); 
     19    
     20 $tmp .= '<div id="loading3" style="display: none;">'.$html->image("static/loading.gif", array("alt"=>"Loading")).'</div>'; 
     21                 
     22 $tmp .= $ajax->div('qn', array("style"=>"padding:3px")) . $ajax->divEnd('qn'); 
     23                   
     24 echo $html->div(null, $tmp); 
    1725   
    1826    //Topics 
    1927    echo '<table style="border-collapse:collapse;width:100%">'; 
    20      if ( count($data["Topic"]) == 0) 
    21      { 
     28     if ( count($data["Topic"]) == 0): 
    2229                 echo '<tr><td colspan="6"><br /><h4>There is not topic on this forum yet</h4></td></tr>'; 
    23      } 
    24      else 
    25      { 
    26                 $th = array('Read', 'Topics', 'Replies', 'Author', 'Views', 'Last Post'); 
    27                 echo $html->tableHeaders($th); 
    28       } 
     30     else: 
     31                $th = array('Read', 'Topics', 'Replies', 'Author', 'Views', 'Last Post'); echo $html->tableHeaders($th); 
     32     endif; 
    2933      //die(print_r($data["Topic"])); 
    3034             
  • trunk/app/views/topics/add.ctp

    r321 r461  
    1 <?php echo $javascript->link('myfunctions'); ?> 
    2 <div> 
    3 <?php  
    4    echo $html->addCrumb('Phorums', '/forums/view/'.$blog["User"]["id"]);  
    5    echo $html->getCrumbs(' / ');  
    6 ?> 
    7 </div> 
    8 <div class="title_section">New Topic</div> 
    9  
    10 <div class="spaced"> 
    11  
    121<?php  
    132    echo $form->create('Topic'); 
    143    echo $form->hidden('Topic.forum_id', array('value'=>$forum_id)); 
    15  ?> 
     4    echo $form->hidden('Topic.vclassroom_id', array('value'=>$vclassroom_id)); 
     5?> 
    166 
    177<fieldset> 
    188  <legend>New Topic</legend> 
    199  <?php  
    20      echo $form->input('Topic.subject', array("size" => 40, "maxlength" => 60));  
     10     echo $form->input('Topic.subject', array("size" => 30, "maxlength" => 60, 'between'=>': <br />'));  
    2111     echo $form->error('Topic.subject', 'A subject is required.');  
    2212  ?> 
    2313  <p> 
    2414    <?php  
    25     echo $form->label('Topic.message', 'Message:' ) . '<br />'; 
    26     echo $form->textarea('Topic.message', array("rows" => 10, "cols" => 50)); 
    27     echo $form->error('Topic.message', 'A phorum message is required.');  
     15    echo $form->label('Topic.message', 'Topic :') . '<br />'; 
     16    echo $form->textarea('Topic.message', array("rows" => 7, "cols" => 30)); 
    2817  ?> 
    2918  </p> 
    3019  <br />   
    31   <p><br /></fieldset> 
    32   <?php echo $form->end('Save'); ?></p> 
    33 </div> 
     20  <br /> 
     21  <?php echo $form->end('Save'); ?> 
     22</fieldset> 
  • trunk/app/views/topics/display.ctp

    r329 r461  
    11<?php 
    22//die(debug($data)); 
     3echo '<h1>'. $data['Forum']['title'] .'</h1>'; 
    34 
    4 echo '<div>'; 
     5echo $html->para(null, $data['User']['username'] . ' suggest topic: <b>'.$data['Topic']['subject'] .'</b>  at <span class="dates">'.$data['Topic']['created'].'</span>'); 
     6 
     7echo $html->para(null, $html->link( 
     8$html->image('static/return.jpg', array('alt'=>'Return to '. $data['Forum']['title'], 'title'=>'Return to '. $data['Forum']['title'])) 
     9, '/forums/display/'.$data['Topic']['forum_id'], null, null, false)); 
     10 
     11echo $html->div('titentry', 'Discussion on '.$data['Topic']['subject']); 
    512 
    613if ( isset( $cU ) ): 
    7  
    8 echo $html->link(  // add topic 
     14/* 
     15 $tmp = $html->link(  // add topic 
    916                 $html->image( 
    1017                              'static/new_topic.gif', array("alt"=>"New topic", "title"=>"New topic") 
     
    1421                 ) .'  &nbsp;&nbsp;&nbsp;'; 
    1522 
    16 echo $html->link(  // add reply 
    17                  $html->image( 
    18                               'static/reply.gif', array("alt"=>"Reply", "title"=>"Reply")),  
    19                               '/topics/reply/'.$blog["User"]["id"].'/'.$data['Forum']['id'] .'/'.$data['Topic']['id'],  
    20                               false, false, null);  
     23**/ 
     24 $tmp = $ajax->link($html->image("static/reply.gif", array("alt"=>"New reply", "title"=>"Reply")),  
     25      '/topics/reply/'.$data['Topic']['vclassroom_id'].'/'.$data['Forum']['id'] .'/'.$data['Topic']['id'].'/'.$data['Topic']['user_id'], 
     26                                array("update" => "qn", 
     27                              "loading"=>"Element.show('loading3');", 
     28                          "complete"=>"Element.hide('loading3');Effect.Appear('qn')"), 
     29                               null, 
     30                               false 
     31                               ); 
     32    
     33 $tmp .= '<div id="loading3" style="display: none;">'.$html->image("static/loading.gif", array("alt"=>"Loading")).'</div>'; 
     34                 
     35 $tmp .= $ajax->div('qn', array("style"=>"padding:3px")) . $ajax->divEnd('qn'); 
     36                   
     37 echo $html->div(null, $tmp); 
     38 
    2139endif; 
    2240 
    23 echo '</div>'; 
    24  
    25 echo '<h1>'. $data['Forum']['title'] .'</h1>'; 
    26 echo '<p>'. $data['User']['username'] . ' suggest topic: <b>'.$data['Topic']['subject'] .'</b>  <span class="dates">'.$data['Topic']['created'].'</span></p>'; 
    2741 
    2842echo '<div style="padding:2px;margin:10px 5px 10px 5px">'; 
     
    3852 { 
    3953    $i = $int++; 
    40     $tmp   = '<b>'.  $i . '.-</b> ';  
     54        $tmp   = '<b>'.  $i . '.-</b> ';  
    4155    $tmp  .= $html->link($val['User']['username'], '/users/about/'.  $val['User']['username']); 
    4256    $tmp  .= $html->link($html->image('avatars/'.$val['User']['avatar'], array('alt'=>$val['User']['username'])),  
    4357                         '/users/about/'.  $val['User']['username'], null, null, false) .'<br />'; 
    4458    $tmp  .= $html->image('static/time.png') .'  '. $time->timeAgoInWords($val['created']).'<br /><br />' . $val['reply']; 
     59 
    4560    echo $html->div('reply', $tmp); 
    4661     
     
    4964 
    5065if ( isset( $cU ) ): 
    51  
     66  /* 
    5267echo $html->link(  // add topic 
    5368                 $html->image( 
     
    5772                  false, false, null 
    5873                 ) . '      &nbsp;&nbsp;&nbsp;&nbsp;'; 
    59  
    60 echo $html->link(  // add reply 
    61                  $html->image( 
    62                               'static/reply.gif', array("alt"=>"Reply", "title"=>"Reply")),  
    63                               '/topics/reply/'.$blog["User"]["id"].'/'.$data['Forum']['id'] .'/'.$data['Topic']['id'],  
    64                               false, false, null);  
     74  */ 
    6575endif; 
    66  
    6776?> 
  • trunk/app/views/topics/reply.ctp

    r329 r461  
    1 <?php echo $javascript->link('fckeditor/fckeditor'); ?> 
    2 <div class="title_section">Reply</div> 
    3  
    4 <div class="spaced"> 
    5  
    61<?php  
    72 if ( isset ($cU['User']) ): 
    83   echo $form->create('Reply', array('action'=>'add')); 
    9    echo $form->hidden('Reply.redirect_to', array('value'=>'/topics/display/'.$blog['User']['id'].'/'.$forum_id.'/'.$topic_id)); 
     4   echo $form->hidden('Reply.redirect_to', array('value'=>'/topics/display/'.$blogger_id.'/'.$forum_id.'/'.$topic_id)); 
    105   echo $form->hidden('Reply.topic_id', array('value'=>$topic_id)); 
     6   echo $form->hidden('Reply.vclassroom_id', array('value'=>$vclassroom_id)); 
    117?> 
    128<fieldset> 
    13   <legend>New reply</legend> 
     9  <legend><?php __('New reply'); ?></legend> 
    1410  <?php  
    1511    echo $form->label('Reply.reply', 'Message:' ) . '<br />'; 
    1612    echo $form->textarea('Reply.reply', array("rows" => 10, "cols" => 50)); 
    1713    echo $fck->load('ReplyReply', 'Basic', 500, 300);  
    18     echo $form->error('Reply.reply', 'A message is required.');  
    19   ?> 
    20     </fieldset> 
    21   <?php  
    22   echo $form->end('Send');  
     14    echo $form->end('Send'); 
     15    echo '</fieldset>';  
     16endif; 
     17?> 
    2318 
    24 else: 
    25         echo $html->para(null, $html->link('You must be logged in to write a reply', '/users/login')); 
    26 endif; 
    27   ?> 
    28 </div> 
  • trunk/app/views/vclassrooms/show.ctp

    r450 r461  
    3636       foreach($data['Forum'] as $f) 
    3737       { 
    38          echo $html->para(null, $html->link($f['title'], '/vclassrooms/forums/'.$f['id'])); 
     38         echo $html->para(null, $html->link($f['title'], '/forums/display/'.$f['id'])); 
    3939       } 
    4040     }