Changeset 25
- Timestamp:
- 12/09/05 11:53:57 (7 years ago)
- Files:
-
- trunk/frontend/config/settings.yml (modified) (1 diff)
- trunk/frontend/lib/helper/AnswerHelper.php (modified) (2 diffs)
- trunk/frontend/lib/helper/GlobalHelper.php (modified) (1 diff)
- trunk/frontend/lib/helper/UserHelper.php (modified) (2 diffs)
- trunk/frontend/modules/answer/actions/actions.class.php (modified) (1 diff)
- trunk/frontend/modules/answer/config/view.yml (added)
- trunk/frontend/modules/answer/templates/_answer.php (added)
- trunk/frontend/modules/answer/templates/_list.php (modified) (1 diff)
- trunk/frontend/modules/answer/templates/addSuccess.php (added)
- trunk/frontend/modules/question/actions/actions.class.php (modified) (2 diffs)
- trunk/frontend/modules/question/config/security.yml (modified) (1 diff)
- trunk/frontend/modules/question/templates/addSuccess.php (added)
- trunk/frontend/modules/question/templates/showSuccess.php (modified) (1 diff)
- trunk/frontend/modules/question/validate (added)
- trunk/frontend/modules/question/validate/add.yml (added)
- trunk/frontend/modules/sidebar/templates/defaultSuccess.php (modified) (1 diff)
- trunk/frontend/modules/user/actions/actions.class.php (modified) (1 diff)
- trunk/lib/model/User.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/frontend/config/settings.yml
r2 r25 19 19 20 20 all: 21 ; .actions: 21 .actions: 22 login_module: user 23 login_action: login 24 22 25 ; default_module: default 23 26 ; default_action: index trunk/frontend/lib/helper/AnswerHelper.php
r23 r25 1 1 <?php 2 3 use_helper('Global'); 2 4 3 5 function answer_pager_link($name, $question, $page) … … 41 43 else 42 44 { 43 return link_to_ function($name, visual_effect('blind_down', 'login', array('duration' => 0.5)));45 return link_to_login($name); 44 46 } 45 47 } trunk/frontend/lib/helper/GlobalHelper.php
r23 r25 1 1 <?php 2 3 function 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 } 2 14 3 15 function pager_navigation($pager, $uri) trunk/frontend/lib/helper/UserHelper.php
r20 r25 1 1 <?php 2 2 3 use_helper ('Javascript');3 use_helpers('Javascript', 'Global'); 4 4 5 5 function link_to_user_interested($user, $question) … … 26 26 else 27 27 { 28 return link_to_ function('interested?', visual_effect('blind_down', 'login', array('duration' => 0.5)));28 return link_to_login('interested?'); 29 29 } 30 30 } trunk/frontend/modules/answer/actions/actions.class.php
r18 r25 15 15 $this->answer_pager = AnswerPeer::getRecentPager($this->getRequestParameter('page', 1)); 16 16 } 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 } 17 45 } 18 46 trunk/frontend/modules/answer/templates/_list.php
r23 r25 1 <?php use_helper s('Date') ?>1 <?php use_helper('Global') ?> 2 2 3 3 <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)) ?> 14 7 </div> 15 8 <?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> 16 40 </div> 41 42 </div> trunk/frontend/modules/question/actions/actions.class.php
r18 r25 21 21 $this->forward404Unless($this->question); 22 22 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); 24 26 } 25 27 … … 28 30 $this->question_pager = QuestionPeer::getRecentPager($this->getRequestParameter('page', 1)); 29 31 } 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 } 30 56 } 31 57 trunk/frontend/modules/question/config/security.yml
r16 r25 1 add: 2 is_secure: on 3 credentials: subscriber 4 1 5 edit: 2 6 is_secure: on trunk/frontend/modules/question/templates/showSuccess.php
r23 r25 11 11 </div> 12 12 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('«', $question, 1) ?> 19 <?php echo answer_pager_link('<', $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('>', $question, $answer_pager->getNextPage()) ?> 27 <?php echo answer_pager_link('»', $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 3 5 <ul> 4 6 <li><?php echo link_to('popular questions', '@homepage') ?> trunk/frontend/modules/user/actions/actions.class.php
r23 r25 26 26 $this->forward404Unless($this->question); 27 27 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); 34 29 } 35 30 trunk/lib/model/User.php
r16 r25 22 22 } 23 23 24 public function isInterestedIn($question) 25 { 26 $interest = new Interest(); 27 $interest->setQuestion($question); 28 $interest->setUserId($this->getId()); 29 $interest->save(); 30 } 31 24 32 public function setPassword($password) 25 33 {
