Changeset 25

Show
Ignore:
Timestamp:
12/09/05 11:53:57 (3 years ago)
Author:
fabien
Message:

day 10 modifications

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/frontend/config/settings.yml

    r2 r25  
    1919 
    2020all: 
    21 ;  .actions: 
     21  .actions: 
     22    login_module:           user 
     23    login_action:           login 
     24 
    2225;    default_module:         default 
    2326;    default_action:         index 
  • trunk/frontend/lib/helper/AnswerHelper.php

    r23 r25  
    11<?php 
     2 
     3use_helper('Global'); 
    24 
    35function answer_pager_link($name, $question, $page) 
     
    4143  else 
    4244  { 
    43     return link_to_function($name, visual_effect('blind_down', 'login', array('duration' => 0.5))); 
     45    return link_to_login($name); 
    4446  } 
    4547} 
  • trunk/frontend/lib/helper/GlobalHelper.php

    r23 r25  
    11<?php 
     2 
     3function link_to_login($name, $uri = null) 
     4{ 
     5  if ($uri && sfContext::getInstance()->getUser()->isAuthenticated()) 
     6  { 
     7    return link_to($name, $uri); 
     8  } 
     9  else 
     10  { 
     11    return link_to_function($name, visual_effect('blind_down', 'login', array('duration' => 0.5))); 
     12  } 
     13} 
    214 
    315function pager_navigation($pager, $uri) 
  • trunk/frontend/lib/helper/UserHelper.php

    r20 r25  
    11<?php 
    22 
    3 use_helper('Javascript'); 
     3use_helpers('Javascript', 'Global'); 
    44 
    55function link_to_user_interested($user, $question) 
     
    2626  else 
    2727  { 
    28     return link_to_function('interested?', visual_effect('blind_down', 'login', array('duration' => 0.5))); 
     28    return link_to_login('interested?'); 
    2929  } 
    3030} 
  • trunk/frontend/modules/answer/actions/actions.class.php

    r18 r25  
    1515    $this->answer_pager = AnswerPeer::getRecentPager($this->getRequestParameter('page', 1)); 
    1616  } 
     17 
     18  public function executeAdd() 
     19  { 
     20    if ($this->getRequest()->getMethod() == sfRequest::POST) 
     21    { 
     22      if (!$this->getRequestParameter('body')) 
     23      { 
     24        return sfView::NONE; 
     25      } 
     26 
     27      $question = QuestionPeer::retrieveByPk($this->getRequestParameter('question_id')); 
     28      $this->forward404Unless($question); 
     29   
     30      // user or anonymous coward 
     31      $user = $this->getUser()->isAuthenticated() ? $this->getUser()->getSubscriber() : UserPeer::getUserFromNickname('anonymous'); 
     32   
     33      // create answer 
     34      $this->answer = new Answer(); 
     35      $this->answer->setQuestion($question); 
     36      $this->answer->setBody($this->getRequestParameter('body')); 
     37      $this->answer->setUser($user); 
     38      $this->answer->save(); 
     39   
     40      return sfView::SUCCESS; 
     41    } 
     42   
     43    $this->forward404(); 
     44  } 
    1745} 
    1846 
  • trunk/frontend/modules/answer/templates/_list.php

    r23 r25  
    1 <?php use_helpers('Date') ?> 
     1<?php use_helper('Global') ?> 
    22 
    33<div id="answers"> 
    4 <?php foreach ($answer_pager->getResults() as $answer): ?> 
    5   <div> 
    6     <div class="vote_block" id="vote_<?php echo $answer->getId() ?>"> 
    7       <?php echo include_partial('answer/vote_user', array('answer' => $answer)) ?> 
    8     </div> 
    9     posted by <?php echo $answer->getUser() ?> 
    10     on <?php echo format_date($answer->getCreatedAt(), 'p') ?> 
    11     <div> 
    12       <?php echo $answer->getHtmlBody() ?> 
    13     </div> 
     4<?php foreach ($answers as $answer): ?> 
     5  <div class="answer"> 
     6  <?php include_partial('answer/answer', array('answer' => $answer)) ?> 
    147  </div> 
    158<?php endforeach ?> 
     9 
     10<div class="answer" id="add_answer"> 
     11  <?php echo form_remote_tag(array( 
     12    'url'      => '@add_answer', 
     13    'update'   => array('success' => 'add_answer'), 
     14    'loading'  => "Element.show('indicator')", 
     15    'complete' => "Element.hide('indicator');".visual_effect('highlight', 'add_answer'), 
     16  )) ?> 
     17    <fieldset> 
     18 
     19    <div class="form-row"> 
     20      <?php if ($user->isAuthenticated()): ?> 
     21        <?php echo $user->getNickname() ?> 
     22      <?php else: ?> 
     23        <?php echo 'Anonymous Coward' ?> 
     24        <?php echo link_to_login('login') ?> 
     25      <?php endif ?> 
     26    </div> 
     27 
     28    <div class="form-row"> 
     29      <label for="label">Your answer:</label> 
     30      <?php echo textarea_tag('body', $params->get('body')) ?> 
     31    </div> 
     32 
     33    </fieldset> 
     34 
     35    <div class="submit-row"> 
     36      <?php echo input_hidden_tag('question_id', $question->getId()) ?> 
     37      <?php echo submit_tag('answer it') ?> 
     38    </div> 
     39  </form> 
    1640</div> 
     41 
     42</div> 
  • trunk/frontend/modules/question/actions/actions.class.php

    r18 r25  
    2121    $this->forward404Unless($this->question); 
    2222 
    23     $this->answer_pager = AnswerPeer::getPager($this->question->getId(), $this->getRequestParameter('page', 1)); 
     23    $c = new Criteria(); 
     24    $c->add(AnswerPeer::QUESTION_ID, $this->question->getId()); 
     25    $this->answers = AnswerPeer::doSelect($c); 
    2426  } 
    2527 
     
    2830    $this->question_pager = QuestionPeer::getRecentPager($this->getRequestParameter('page', 1)); 
    2931  } 
     32 
     33  public function executeAdd() 
     34  { 
     35    if ($this->getRequest()->getMethod() == sfRequest::POST) 
     36    { 
     37      // create question 
     38      $user = $this->getUser()->getSubscriber(); 
     39 
     40      $question = new Question(); 
     41      $question->setTitle($this->getRequestParameter('title')); 
     42      $question->setBody($this->getRequestParameter('body')); 
     43      $question->setUser($user); 
     44      $question->save(); 
     45 
     46      $user->isInterestedIn($question); 
     47 
     48      return $this->redirect('@question?stripped_title='.$question->getStrippedTitle()); 
     49    } 
     50  } 
     51 
     52  public function handleErrorAdd() 
     53  { 
     54    return sfView::SUCCESS; 
     55  } 
    3056} 
    3157 
  • trunk/frontend/modules/question/config/security.yml

    r16 r25  
     1add: 
     2  is_secure:   on 
     3  credentials: subscriber 
     4 
    15edit: 
    26  is_secure:   on 
  • trunk/frontend/modules/question/templates/showSuccess.php

    r23 r25  
    1111</div> 
    1212 
    13 <?php include_partial('answer/list', array('answer_pager' => $answer_pager)) ?> 
    14  
    15 <?php if ($answer_pager->haveToPaginate()): ?> 
    16   <div id="answers_pager"> 
    17  
    18   <?php echo answer_pager_link('&laquo;', $question, 1) ?> 
    19   <?php echo answer_pager_link('&lt;', $question, $answer_pager->getPreviousPage()) ?> 
    20  
    21   <?php foreach ($answer_pager->getLinks() as $page): ?> 
    22     <?php echo ($page == $answer_pager->getPage()) ? $page : answer_pager_link($page, $question, $page) ?> 
    23     <?php echo ($page != $answer_pager->getCurrentMaxLink()) ? '-' : '' ?> 
    24   <?php endforeach ?> 
    25  
    26   <?php echo answer_pager_link('&gt;', $question, $answer_pager->getNextPage()) ?> 
    27   <?php echo answer_pager_link('&raquo;', $question, $answer_pager->getLastPage()) ?> 
    28  
    29   </div> 
    30 <?php endif ?> 
     13<?php include_partial('answer/list', array('question' => $question, 'answers' => $answers)) ?> 
  • trunk/frontend/modules/sidebar/templates/defaultSuccess.php

    r23 r25  
    1 <?php echo link_to('ask a new question', '@add_question') ?> 
    2   
     1<?php use_helper('Global') ?> 
     2 
     3<?php echo link_to_login('ask a new question', '@add_question') ?> 
     4 
    35<ul> 
    46  <li><?php echo link_to('popular questions', '@homepage') ?> 
  • trunk/frontend/modules/user/actions/actions.class.php

    r23 r25  
    2626    $this->forward404Unless($this->question); 
    2727 
    28     $user = $this->getUser()->getSubscriber(); 
    29  
    30     $interest = new Interest(); 
    31     $interest->setQuestion($this->question); 
    32     $interest->setUser($user); 
    33     $interest->save(); 
     28    $this->getUser()->getSubscriber()->isInterestedIn($this->question); 
    3429  } 
    3530 
  • trunk/lib/model/User.php

    r16 r25  
    2222  } 
    2323 
     24  public function isInterestedIn($question) 
     25  { 
     26    $interest = new Interest(); 
     27    $interest->setQuestion($question); 
     28    $interest->setUserId($this->getId()); 
     29    $interest->save(); 
     30  } 
     31 
    2432  public function setPassword($password) 
    2533  {