Ejemplo n.º 1
0
 /**
  *
  * @param $cid
  * @return array
  */
 public function getModelTags($cid)
 {
     $terms = $this->getTagsForArticle($cid);
     $showRelatedArticles = CedTagsHelper::param('RelatedArticlesByTags', 0);
     $tags = array();
     if (isset($terms) && !empty($terms)) {
         $singleTermsSuppress = CedTagsHelper::param('SuppresseSingleTerms', 1);
         $termIds = array();
         foreach ($terms as $term) {
             $frequency = $this->getTagFrequency($term);
             if ($showRelatedArticles || $singleTermsSuppress) {
                 if (@intval($frequency) <= 1) {
                     if ($singleTermsSuppress) {
                         continue;
                     }
                 } else {
                     $termIds[] = $term->id;
                 }
             }
             $date = $term->created;
             $tag = new stdClass();
             $tag->title = JText::sprintf('COM_CEDTAG_ITEMS_TITLE', (string) $frequency, (string) $term->name, (string) $date, (string) $term->hits);
             $tag->id = $term->id;
             $tag->link = JRoute::_('index.php?option=com_cedtag&task=tag&tag=' . CedTagsHelper::urlTagname($term->name));
             $tag->tag = CedTagsHelper::ucwords($term->name);
             $tags[] = $tag;
         }
     }
     //Limit size of tags displayed
     array_splice($tags, intval(CedTagsHelper::param('MaxTagsNumber', 10)));
     return $tags;
 }
Ejemplo n.º 2
0
 /**
  * http://rhodopsin.blogspot.com/2008/05/php-tag-cloud.html
  * http://en.wikipedia.org/wiki/Pareto_distribution
  * @param $rows
  * @return array
  */
 public function mappingFrequencyToSizeWithPareto($rows)
 {
     $tags = array();
     $tagsNameToRow = array();
     foreach ($rows as $row) {
         $tags[$row->name] = $row->frequency;
         $tagsNameToRow[$row->name] = $row;
     }
     $maxSize = $rows[0]->frequency;
     $minSize = 1;
     $tags = $this->fromParetoCurve($tags, $minSize, $maxSize);
     $result = array();
     while (list($tagname, $tagsize) = each($tags)) {
         $term = new stdClass();
         $term->size = $tagsize;
         $term->link = JRoute::_('index.php?option=com_cedtag&task=tag&tag=' . CedTagsHelper::urlTagname($tagname));
         $term->name = CedTagsHelper::ucwords($tagname);
         $term->frequency = $tagsNameToRow[$tagname]->frequency;
         $term->hits = $tagsNameToRow[$tagname]->hits;
         $term->created = $tagsNameToRow[$tagname]->created;
         $term->title = JText::sprintf('COM_CEDTAG_ITEMS_TITLE', (string) $term->frequency, (string) $term->name, (string) $term->created, (string) $term->hits);
         $term->class = 'cedtag';
         $result[] = $term;
     }
     return $result;
 }