Changeset 34

Show
Ignore:
Timestamp:
12/13/05 16:34:16 (4 years ago)
Author:
fabien
Message:

day 14 modifications

Files:

Legend:

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

    r31 r34  
    6464  param: { module: tag, action: show } 
    6565 
     66tag_autocomplete: 
     67  url:   /tag_autocomplete 
     68  param: { module: tag, action: autocomplete } 
     69 
     70tag_add: 
     71  url:   /tag_add 
     72  param: { module: tag, action: add } 
     73 
     74popular_tags: 
     75  url:   /popular_tags 
     76  param: { module: tag, action: popular } 
     77 
    6678# feeds 
    6779feed_recent_answers: 
  • trunk/frontend/modules/sidebar/templates/questionSuccess.php

    r32 r34  
    1414  <?php echo include_partial('tag/question_tags', array('question' => $question, 'tags' => $question->getTags())) ?>  
    1515</ul> 
     16 
     17<?php if ($user->isAuthenticated()): ?> 
     18  <div>Add your own: 
     19    <?php echo form_remote_tag(array( 
     20      'url'    => '@tag_add', 
     21      'update' => 'question_tags', 
     22    )) ?> 
     23      <?php echo input_hidden_tag('question_id', $question->getId()) ?> 
     24      <?php echo input_auto_complete_tag('tag', '', '@tag_autocomplete', 'autocomplete=off', 'use_style=true') ?> 
     25      <?php echo submit_tag('Tag') ?> 
     26    </form> 
     27  </div> 
     28<?php endif ?> 
  • trunk/frontend/modules/tag/actions/actions.class.php

    r31 r34  
    1515    $this->question_pager = QuestionPeer::getPopularByTag($this->getRequestParameter('tag'), $this->getRequestParameter('page', 1)); 
    1616  } 
     17 
     18  public function executeAutocomplete() 
     19  { 
     20    // disable web debug toolbar 
     21    $this->getRequest()->setAttribute('disable_web_debug', true, 'debug/web'); 
     22 
     23    $tags = array(); 
     24 
     25    $con = Propel::getConnection(); 
     26    $query = ' 
     27      SELECT DISTINCT %s AS tag 
     28      FROM %s 
     29      WHERE %s = ? AND %s LIKE ? 
     30      ORDER BY %s 
     31    '; 
     32 
     33    $query = sprintf($query, 
     34      QuestionTagPeer::TAG, 
     35      QuestionTagPeer::TABLE_NAME, 
     36      QuestionTagPeer::USER_ID, 
     37      QuestionTagPeer::TAG, 
     38      QuestionTagPeer::TAG 
     39    ); 
     40 
     41    $stmt = $con->prepareStatement($query); 
     42    $stmt->setInt(1, $this->getUser()->getSubscriberId()); 
     43    $stmt->setString(2, $this->getRequestParameter('tag').'%'); 
     44    $stmt->setLimit(10); 
     45    $rs = $stmt->executeQuery(); 
     46    while ($rs->next()) 
     47    { 
     48      $tags[] = $rs->getString('tag'); 
     49    } 
     50 
     51    $this->tags = $tags; 
     52  } 
     53 
     54  public function executeAdd() 
     55  { 
     56    // disable web debug toolbar 
     57    $this->getRequest()->setAttribute('disable_web_debug', true, 'debug/web'); 
     58 
     59    $this->question = QuestionPeer::retrieveByPk($this->getRequestParameter('question_id')); 
     60    $this->forward404Unless($this->question); 
     61 
     62    $userId = $this->getUser()->getSubscriberId(); 
     63    $phrase = $this->getRequestParameter('tag'); 
     64    $this->question->addTagsForUser($phrase, $userId); 
     65 
     66    $this->tags = $this->question->getTags(); 
     67  } 
     68 
     69  public function executePopular() 
     70  { 
     71    $this->tags = QuestionTagPeer::getPopularTags(40); 
     72  } 
    1773} 
    1874 
  • trunk/lib/model/Question.php

    r31 r34  
    105105    return $tags; 
    106106  } 
     107 
     108  public function addTagsForUser($phrase, $userId) 
     109  { 
     110    // split phrase into individual tags 
     111    $tags = Tag::splitPhrase($phrase); 
     112 
     113    // add tags 
     114    foreach ($tags as $tag) 
     115    { 
     116      $questionTag = new QuestionTag(); 
     117      $questionTag->setQuestionId($this->getId()); 
     118      $questionTag->setUserId($userId); 
     119      $questionTag->setTag($tag); 
     120      $questionTag->save(); 
     121    } 
     122  } 
    107123} 
    108124 
  • trunk/lib/model/QuestionTagPeer.php

    r31 r34  
    1919 * @package model 
    2020 */  
    21 class QuestionTagPeer extends BaseQuestionTagPeer { 
     21class QuestionTagPeer extends BaseQuestionTagPeer 
     22
     23  public function getPopularTags($max = 5) 
     24  { 
     25    $tags = array(); 
    2226 
    23 } // QuestionTagPeer 
     27    $con = Propel::getConnection(); 
     28    $query = ' 
     29      SELECT '.QuestionTagPeer::NORMALIZED_TAG.' AS tag, 
     30      COUNT('.QuestionTagPeer::NORMALIZED_TAG.') AS count 
     31      FROM '.QuestionTagPeer::TABLE_NAME.' 
     32      GROUP BY '.QuestionTagPeer::NORMALIZED_TAG.' 
     33      ORDER BY count DESC'; 
     34 
     35    $stmt = $con->prepareStatement($query); 
     36    $stmt->setLimit($max); 
     37    $rs = $stmt->executeQuery(); 
     38    $max_popularity = 0; 
     39    while ($rs->next()) 
     40    { 
     41      if (!$max_popularity) 
     42      { 
     43        $max_popularity = $rs->getInt('count'); 
     44      } 
     45 
     46      $tags[$rs->getString('tag')] = floor(($rs->getInt('count') / $max_popularity * 3) + 1); 
     47    } 
     48 
     49    ksort($tags); 
     50 
     51    return $tags; 
     52  } 
     53
     54 
     55?> 
  • trunk/web/css/main.css

    r20 r34  
    158158  background: url(/images/indicator.gif) no-repeat 0 0; 
    159159} 
     160 
     161ul#tag_cloud 
     162{ 
     163  list-style: none; 
     164} 
     165  
     166ul#tag_cloud li 
     167{ 
     168  list-style: none; 
     169  display: inline; 
     170} 
     171  
     172ul#tag_cloud li.tag_popularity_1 
     173{ 
     174  font-size: 60%; 
     175} 
     176  
     177ul#tag_cloud li.tag_popularity_2 
     178{ 
     179  font-size: 100%; 
     180} 
     181  
     182ul#tag_cloud li.tag_popularity_3 
     183{ 
     184  font-size: 130%; 
     185} 
     186  
     187ul#tag_cloud li.tag_popularity_4 
     188{ 
     189  font-size: 160%; 
     190}