diff --git a/application/modules/default/models/DbTable/Tags.php b/application/modules/default/models/DbTable/Tags.php index 36db8542a..0f2e3e2b6 100644 --- a/application/modules/default/models/DbTable/Tags.php +++ b/application/modules/default/models/DbTable/Tags.php @@ -1,309 +1,314 @@ . **/ class Default_Model_DbTable_Tags extends Local_Model_Table { /** @var Zend_Cache_Core */ protected $cache; protected $_name = "tag"; protected $_keyColumnsForRow = array('tag_id'); protected $_key = 'tag_id'; protected $_defaultValues = array( 'tag_id' => null, 'tag_name' => null ); const TAG_TYPE_PROJECT = 1; const TAG_TYPE_FILE = 3; const TAG_GROUP_USER = 5; const TAG_GROUP_CATEGORY = 6; const TAG_GROUP_LICENSE = 7; const TAG_GROUP_PACKAGETYPE = 8; const TAG_GROUP_ARCHITECTURE = 9; const TAG_GROUP_GHNS_EXCLUDED = 10; const TAG_GHNS_EXCLUDED_ID = 1529; /** * @inheritDoc */ public function init() { parent::init(); // TODO: Change the autogenerated stub $this->cache = Zend_Registry::get('cache'); } /** * @param string $tags * * @return array */ public function storeTags($tags) { $arrayTags = explode(',', $tags); $sqlFetchTag = "SELECT `tag_id` FROM tag WHERE tag_name = :name"; $resultIds = array(); foreach ($arrayTags as $tag) { $resultRow = $this->_db->fetchRow($sqlFetchTag, array('name' => $tag)); if (empty($resultRow)) { $this->_db->insert($this->_name, array('tag_name' => $tag)); $resultIds[] = $this->_db->lastInsertId(); } else { $resultIds[] = $resultRow['tag_id']; } } return $resultIds; } /** * @param string $tags * * @return array */ public function storeTagsUser($tags) { $arrayTags = explode(',', strtolower($tags)); $sqlFetchTag = "SELECT `tag_id` FROM tag WHERE tag_name = :name"; $resultIds = array(); foreach ($arrayTags as $tag) { if(strlen(trim($tag))==0) { continue; } $resultRow = $this->_db->fetchRow($sqlFetchTag, array('name' => $tag)); if (empty($resultRow)) { $this->_db->insert($this->_name, array('tag_name' => $tag)); $tagId = $this->_db->lastInsertId(); $resultIds[] = $tagId; $sql = "SELECT tag_group_item_id FROM tag_group_item WHERE tag_group_id = :group_id AND tag_id = :tag_id"; $resultSet = $this->_db->fetchRow($sql, array('group_id' => Default_Model_DbTable_Tags::TAG_GROUP_USER, 'tag_id' =>$tagId)); if (empty($resultSet)) { $this->_db->insert('tag_group_item', array('tag_group_id' => Default_Model_DbTable_Tags::TAG_GROUP_USER, 'tag_id' => $tagId)); } } else { $resultIds[] = $resultRow['tag_id']; $sql = "SELECT tag_group_item_id FROM tag_group_item WHERE tag_group_id = :group_id AND tag_id = :tag_id"; $resultSet = $this->_db->fetchRow($sql, array('group_id' => Default_Model_DbTable_Tags::TAG_GROUP_USER, 'tag_id' =>$resultRow['tag_id'])); if (empty($resultSet)) { $this->_db->insert('tag_group_item', array('tag_group_id' => Default_Model_DbTable_Tags::TAG_GROUP_USER, 'tag_id' => $resultRow['tag_id'])); } } } return $resultIds; } /** * @return array */ public function fetchArchitectureTagsForSelect() { return $this->fetchForGroupForSelect(Default_Model_DbTable_Tags::TAG_GROUP_ARCHITECTURE); } /** * @return array */ public function fetchPackagetypeTagsForSelect() { return $this->fetchForGroupForSelect(Default_Model_DbTable_Tags::TAG_GROUP_PACKAGETYPE); } /** * @return array */ public function fetchGhnsExcludedTagId() { return $this:: TAG_GHNS_EXCLUDED_ID; // $tag = $this->fetchForGroupForSelect(Default_Model_DbTable_Tags::TAG_GROUP_GHNS_EXCLUDED); // $keys = array_keys($tag); // if(isset($keys) && count($keys) == 1) { // return $keys[0]; // } // return null; } /** * @return array */ public function fetchLicenseTagsForSelect() { return $this->fetchForGroupForSelect(Default_Model_DbTable_Tags::TAG_GROUP_LICENSE); } /** * @param int|array $groupId * @return array */ - public function fetchForGroupForSelect($groupId) + public function fetchForGroupForSelect($groupId, $withGroup = false) { $str = is_array($groupId) ? implode(',', $groupId) : $groupId; /** @var Zend_Cache_Core $cache */ $cache = $this->cache; - $cacheName = __FUNCTION__ . '_' . md5($str); + $cacheName = __FUNCTION__ . '_' . md5($str . $withGroup); if (false === ($tags = $cache->load($cacheName))) { $inQuery = '?'; if (is_array($groupId)) { $inQuery = implode(',', array_fill(0, count($groupId), '?')); } $sql = " - SELECT t.* FROM tag t + SELECT t.*,case when tg.group_display_name IS NULL OR LENGTH(tg.group_display_name) = 0 then tg.group_name ELSE tg.group_display_name END AS group_name FROM tag t JOIN tag_group_item g on g.tag_id = t.tag_id + JOIN tag_group tg ON tg.group_id = g.tag_group_id WHERE g.tag_group_id IN ($inQuery) and is_active = 1 ORDER BY t.tag_fullname "; $tagsList = $this->_db->query($sql, $groupId)->fetchAll(); + + if($withGroup) { + $tags['header'] = $tagsList[0]['group_name']; + } foreach ($tagsList as $tag) { - $tags[$tag['tag_id']] = $tag['tag_fullname']; + $tags[$tag['tag_id']] = $tag['tag_fullname']; } if (count($tags) == 0) { $tags = array(); } $cache->save($tags, $cacheName, array(), 3600); } return $tags; } /** * @return array */ public function fetchPackagetypeTagsAsJsonArray() { return $this->fetchForGroupAsJsonArray(Default_Model_DbTable_Tags::TAG_GROUP_PACKAGETYPE); } /** * @param int|array $groupId * @return array */ public function fetchForGroupAsJsonArray($groupId) { $str = is_array($groupId) ? implode(',', $groupId) : $groupId; /** @var Zend_Cache_Core $cache */ $cache = $this->cache; $cacheName = __FUNCTION__ . '_' . md5($str); if (false === ($tags = $cache->load($cacheName))) { $inQuery = '?'; if (is_array($groupId)) { $inQuery = implode(',', array_fill(0, count($groupId), '?')); } $sql = " SELECT t.* FROM tag t JOIN tag_group_item g on g.tag_id = t.tag_id WHERE g.tag_group_id IN ($inQuery) ORDER BY t.tag_fullname "; $tagsList = $this->_db->query($sql, $groupId)->fetchAll(); $tags = "{"; $tags .= "'':'',"; foreach ($tagsList as $tag) { $tags .= "'".$tag['tag_id']."':'" . $tag['tag_fullname']. "',"; } $tags .= "}"; $cache->save($tags, $cacheName, array(), 3600); } return $tags; } /** * @param int $projectId * @return array */ public function fetchLicenseTagsForProject($projectId) { return $this->fetchTagsForProject($projectId, $this::TAG_GROUP_LICENSE); } /** * @param int $projectId * @return array */ public function fetchArchitectureTagsForProject($projectId) { return $this->fetchTagsForProject($projectId, $this::TAG_GROUP_ARCHITECTURE); } /** * @param int $projectId * @return array */ public function fetchPackagetypeTagsForProject($projectId) { return $this->fetchTagsForProject($projectId, $this::TAG_GROUP_PACKAGETYPE); } /** * @param int $projectId Description * @param int|array $groupId * @return array */ public function fetchTagsForProject($projectId, $groupId) { $typeId = $this::TAG_TYPE_PROJECT; $sql = " SELECT `to`.*, t.tag_fullname FROM tag_object `to` JOIN tag t on t.tag_id = to.tag_id JOIN tag_group_item g on g.tag_id = t.tag_id WHERE g.tag_group_id = $groupId and `to`.is_deleted = 0 and `to`.tag_type_id = $typeId and `to`.tag_object_id = $projectId "; $tagsList = $this->_db->query($sql)->fetchAll(); $tags = $tagsList; return $tags; } } \ No newline at end of file diff --git a/application/modules/default/views/helpers/FetchTagsForTagGroup.php b/application/modules/default/views/helpers/FetchTagsForTagGroup.php index 6efc9d758..56ef4aa28 100644 --- a/application/modules/default/views/helpers/FetchTagsForTagGroup.php +++ b/application/modules/default/views/helpers/FetchTagsForTagGroup.php @@ -1,34 +1,42 @@ . **/ class Default_View_Helper_FetchTagsForTagGroup extends Zend_View_Helper_Abstract { - public function fetchList($groupId) + public function fetchList($groupId, $withHeader = false) { $tableTags = new Default_Model_DbTable_Tags(); - $tags = $tableTags->fetchForGroupForSelect($groupId); + $tags = array(); + if($withHeader) { + $tags = $tableTags->fetchForGroupForSelect($groupId, true); + $tags['header'] = 'Filter for: ' . $tags['header']; + } else { + $tags = $tableTags->fetchForGroupForSelect($groupId); + } + + return $tags; } } \ No newline at end of file diff --git a/application/modules/default/views/scripts/explore/index.phtml b/application/modules/default/views/scripts/explore/index.phtml index 0b0a59772..b03eb48ca 100644 --- a/application/modules/default/views/scripts/explore/index.phtml +++ b/application/modules/default/views/scripts/explore/index.phtml @@ -1,302 +1,303 @@ . **/ $modelCategory = new Default_Model_DbTable_ProjectCategory(); $this->dataCategory = $modelCategory->findSingleRow($this->cat_id); $store_config = Zend_Registry::get('store_config'); $host = $store_config->host; $og_server = $this->serverUrl(true); $catTitle = ''; if($this->dataCategory['project_category_id']) { $catTitle = $this->dataCategory['title']; } if($this->filters['order'] == 'latest'){ $og_title = 'Browse '.$catTitle.' Latest | '.$host; }else if($this->filters['order'] == 'top'){ $og_title = 'Browse '.$catTitle.' Top | '.$host; }else{ $og_title='Browse '.$catTitle.' | '.$host; } $og_description = $og_title .'| A community for free and open source software and libre content'; $this->templateConfigData = Zend_Registry::get('store_template'); $og_image = 'https://' . $_SERVER['HTTP_HOST'] .$this->templateConfigData['logo']; $this->doctype(Zend_View_Helper_Doctype::XHTML1_RDFA); $this->headMeta()->appendProperty('og:type', 'website'); $this->headMeta()->appendProperty('og:url', $og_server); $this->headMeta()->appendProperty('og:title', $og_title); $this->headMeta()->appendProperty('og:site_name',$host); $this->headMeta()->appendProperty('og:description',$og_description); $this->headMeta()->appendProperty('og:image',$og_image); $helperBuildExploreUrl = new Default_View_Helper_BuildExploreUrl(); $modelInfo = new Default_Model_Info(); $this->countSupporters = $modelInfo->getCountAllSupporters(); $this->supporters = $modelInfo->getNewActiveSupporters(7); $this->headLink()->appendStylesheet('/theme/flatui/css/explore_index.css'); if($this->inputFilterOriginal ==1) { $checkedOriginal = ' checked'; }else { $checkedOriginal = ''; } ?>
products) == 0) { echo '
No products to show in this category.
'; } else { $time_start = microtime(true); echo $this->render('explore/partials/products.phtml'); $time_elapsed = microtime(true) - $time_start; } ?> hasIdentity() AND Zend_Auth::getInstance()->getIdentity()->roleName == 'admin') { echo '
'; echo ''; echo '
'; }?>
comments = $modelInfo->getLatestComments(5, $this->cat_id, $this->tags); //$donations = $modelInfo->getLatestPlings(5, $this->cat_id); $topprods = $modelInfo->getMostDownloaded(100, $this->cat_id, $this->tags); $asidehide = ''; if(!$this->catabout && count($this->comments)==0 && count($topprods)==0 ) { $asidehide = 'hide'; } $this->show_git = false; ?>
inlineScript()->appendScript( ' $(document).ready(function(){ TooltipUser.setup("tooltipuserleft","left"); TooltipUser.setup("tooltipuser","right"); FilterBrowseOriginalFn.setup(); FilterBrowseTagGroupFn.setup(); }); ');