Changeset 34
- Timestamp:
- 12/13/05 16:34:16 (3 years ago)
- Files:
-
- trunk/frontend/config/routing.yml (modified) (1 diff)
- trunk/frontend/modules/sidebar/templates/questionSuccess.php (modified) (1 diff)
- trunk/frontend/modules/tag/actions/actions.class.php (modified) (1 diff)
- trunk/frontend/modules/tag/config/view.yml (added)
- trunk/frontend/modules/tag/templates/addSuccess.php (added)
- trunk/frontend/modules/tag/templates/autocompleteSuccess.php (added)
- trunk/frontend/modules/tag/templates/popularSuccess.php (added)
- trunk/frontend/templates/popularSuccess.php (added)
- trunk/lib/model/Question.php (modified) (1 diff)
- trunk/lib/model/QuestionTagPeer.php (modified) (1 diff)
- trunk/web/css/main.css (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/frontend/config/routing.yml
r31 r34 64 64 param: { module: tag, action: show } 65 65 66 tag_autocomplete: 67 url: /tag_autocomplete 68 param: { module: tag, action: autocomplete } 69 70 tag_add: 71 url: /tag_add 72 param: { module: tag, action: add } 73 74 popular_tags: 75 url: /popular_tags 76 param: { module: tag, action: popular } 77 66 78 # feeds 67 79 feed_recent_answers: trunk/frontend/modules/sidebar/templates/questionSuccess.php
r32 r34 14 14 <?php echo include_partial('tag/question_tags', array('question' => $question, 'tags' => $question->getTags())) ?> 15 15 </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 15 15 $this->question_pager = QuestionPeer::getPopularByTag($this->getRequestParameter('tag'), $this->getRequestParameter('page', 1)); 16 16 } 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 } 17 73 } 18 74 trunk/lib/model/Question.php
r31 r34 105 105 return $tags; 106 106 } 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 } 107 123 } 108 124 trunk/lib/model/QuestionTagPeer.php
r31 r34 19 19 * @package model 20 20 */ 21 class QuestionTagPeer extends BaseQuestionTagPeer { 21 class QuestionTagPeer extends BaseQuestionTagPeer 22 { 23 public function getPopularTags($max = 5) 24 { 25 $tags = array(); 22 26 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 158 158 background: url(/images/indicator.gif) no-repeat 0 0; 159 159 } 160 161 ul#tag_cloud 162 { 163 list-style: none; 164 } 165 166 ul#tag_cloud li 167 { 168 list-style: none; 169 display: inline; 170 } 171 172 ul#tag_cloud li.tag_popularity_1 173 { 174 font-size: 60%; 175 } 176 177 ul#tag_cloud li.tag_popularity_2 178 { 179 font-size: 100%; 180 } 181 182 ul#tag_cloud li.tag_popularity_3 183 { 184 font-size: 130%; 185 } 186 187 ul#tag_cloud li.tag_popularity_4 188 { 189 font-size: 160%; 190 }
