示例#1
0
 public function indexAction()
 {
     $entityManager = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     $dql = "SELECT a, u, l, c FROM Cms\\Entity\\Article a LEFT JOIN a.author u LEFT JOIN a.language l LEFT JOIN a.categories c WHERE a.parent IS NULL";
     $query = $entityManager->createQuery($dql);
     $query->setMaxResults(30);
     $articles = $query->getResult();
     $tags = $this->getEntityManager()->getRepository('Cms\\Entity\\Tag')->findAll();
     $list = new ItemList();
     foreach ($tags as $tag) {
         if (count($tag->getArticles()) > 0) {
             $list[] = new Item(array('title' => $tag->getTagName(), 'weight' => count($tag->getArticles()), 'params' => array('id' => $tag->getTagId())));
         }
     }
     $list->spreadWeightValues(array(55, 60, 65, 70, 75, 80, 85, 90, 95, 100));
     $resultSet = $this->getEntityManager()->getRepository('Cms\\Entity\\Category')->findAll();
     return new ViewModel(array('categories' => $resultSet, 'list' => $list));
     return new ViewModel(array('articles' => $articles));
 }
示例#2
0
 public function testSpreadWeightValuesWithEmptyValuesArray()
 {
     $list = new Tag\ItemList();
     $this->setExpectedException('Zend\\Tag\\Exception\\InvalidArgumentException', 'Value list may not be empty');
     $list->spreadWeightValues(array());
 }
示例#3
0
 public function testSpreadWeightValuesWithEmptyValuesArray()
 {
     $list = new Tag\ItemList();
     try {
         $list->spreadWeightValues(array());
         $this->fail('An expected Zend_Tag_Exception was not raised');
     } catch (Tag\Exception $e) {
         $this->assertEquals($e->getMessage(), 'Value list may not be empty');
     }
 }
示例#4
0
 /**
  * Defined by Zend_Tag_Cloud_Decorator_Tag
  *
  * @param  \Zend\Tag\ItemList $tags
  * @return array
  */
 public function render(\Zend\Tag\ItemList $tags)
 {
     if (null === ($weightValues = $this->getClassList())) {
         $weightValues = range($this->getMinFontSize(), $this->getMaxFontSize());
     }
     $tags->spreadWeightValues($weightValues);
     $result = array();
     $enc = $this->getEncoding();
     foreach ($tags as $tag) {
         if (null === ($classList = $this->getClassList())) {
             $attribute = sprintf('style="font-size: %d%s;"', $tag->getParam('weightValue'), $this->getFontSizeUnit());
         } else {
             $attribute = sprintf('class="%s"', htmlspecialchars($tag->getParam('weightValue'), ENT_COMPAT, $enc));
         }
         $tagHTML = sprintf('<a href="%s" %s>%s</a>', htmlSpecialChars($tag->getParam('url'), ENT_COMPAT, $enc), $attribute, $tag->getTitle());
         foreach ($this->getHTMLTags() as $key => $data) {
             if (is_array($data)) {
                 $htmlTag = $key;
                 $attributes = '';
                 foreach ($data as $param => $value) {
                     $attributes .= ' ' . $param . '="' . htmlspecialchars($value, ENT_COMPAT, $enc) . '"';
                 }
             } else {
                 $htmlTag = $data;
                 $attributes = '';
             }
             $tagHTML = sprintf('<%1$s%3$s>%2$s</%1$s>', $htmlTag, $tagHTML, $attributes);
         }
         $result[] = $tagHTML;
     }
     return $result;
 }