diff --git a/application/modules/backend/controllers/StoreController.php b/application/modules/backend/controllers/StoreController.php index 7825f351a..e209079e8 100644 --- a/application/modules/backend/controllers/StoreController.php +++ b/application/modules/backend/controllers/StoreController.php @@ -1,309 +1,351 @@ . **/ class Backend_StoreController extends Local_Controller_Action_Backend { const RESULT_OK = "OK"; const RESULT_ERROR = "ERROR"; const DATA_ID_NAME = 'store_id'; /** @var Default_Model_DbTable_ConfigStore */ protected $_model; protected $_modelName = 'Default_Model_DbTable_ConfigStore'; protected $_pageTitle = 'Manage Store Config'; public function init() { $this->_model = new $this->_modelName(); $this->view->pageTitle = $this->_pageTitle; parent::init(); } public function indexAction() { } public function createAction() { $jTableResult = array(); try { $allParams = $this->getAllParams(); $resultWalk = array_walk($allParams, function (&$value) { $value = empty($value) ? null : $value; }); if (false === $resultWalk) { throw new Exception('array_walk through input parameters failed.'); } //$newRow = $this->_model->createRow($allParams); //$result = $newRow->save(); $newRow = $this->_model->save($allParams); $jTableResult['Result'] = self::RESULT_OK; $jTableResult['Record'] = $newRow->toArray(); } catch (Exception $e) { Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true)); $translate = Zend_Registry::get('Zend_Translate'); $jTableResult['Result'] = self::RESULT_ERROR; $jTableResult['Message'] = $translate->_('Error while processing data.'); } $this->_helper->json($jTableResult); } public function initcacheAction() { $allStoresCat = $this->_model->fetchAllStoresAndCategories(true); $allStoresConfig = $this->_model->fetchAllStoresConfigArray(true); $modelPCat = new Default_Model_ProjectCategory(); foreach ($allStoresConfig as $config) { $modelPCat->fetchCategoryTreeForStore($config['store_id'], true); $this->_model->fetchConfigForStore($config['store_id'], true); } } public function updateAction() { $jTableResult = array(); try { $values = $this->getAllParams(); foreach ($values as $key => $value) { if ($value == '') { $values[$key] = new Zend_Db_Expr('NULL'); } } // patch checkbox is_show_title get no parameter when is_show_title = 0 if(!isset($values['is_show_title'])){ $values['is_show_title'] = 0; } if(!isset($values['is_show_git_projects'])){ $values['is_show_git_projects'] = 0; } if(!isset($values['cross_domain_login'])){ $values['cross_domain_login'] = 0; } if(!isset($values['is_client'])){ $values['is_client'] = 0; } $record = $this->_model->save($values); $this->initCache($record->store_id); $tagsid = $this->getParam('tags_id', null); $tagmodel = new Default_Model_Tags(); $tagmodel->updateTagsPerStore($values['store_id'], $tagsid); + + $groupsid = $this->getParam('groups_id', null); + $groupmodel = new Default_Model_TagGroup(); + $groupmodel->updateTagGroupsPerStore($values['store_id'], $groupsid); + $jTableResult = array(); $jTableResult['Result'] = self::RESULT_OK; } catch (Exception $e) { Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true)); $translate = Zend_Registry::get('Zend_Translate'); $jTableResult['Result'] = self::RESULT_ERROR; $jTableResult['Message'] = $translate->_('Error while processing data.'); } $this->_helper->json($jTableResult); } protected function initCache($store_id) { $modelPCat = new Default_Model_ProjectCategory(); $modelPCat->fetchCategoryTreeForStore($store_id, true); $this->_model->fetchConfigForStore($store_id, true); $this->_model->fetchAllStoresAndCategories(true); $this->_model->fetchAllStoresConfigArray(true); } public function deleteAction() { $dataId = (int)$this->getParam(self::DATA_ID_NAME, null); $this->_model->deleteId($dataId); $this->cacheClear($dataId); $jTableResult = array(); $jTableResult['Result'] = self::RESULT_OK; $this->_helper->json($jTableResult); } protected function cacheClear($store_id) { /** @var Zend_Cache_Core $cache */ $cache = Zend_Registry::get('cache'); $cache->remove(Default_Model_ProjectCategory::CACHE_TREE_STORE . "_{$store_id}"); $cache->remove(Default_Model_DbTable_ConfigStore::CACHE_STORE_CONFIG . "_{$store_id}"); $this->_model->fetchAllStoresAndCategories(true); $this->_model->fetchAllStoresConfigArray(true); } public function listAction() { $startIndex = (int)$this->getParam('jtStartIndex'); $pageSize = (int)$this->getParam('jtPageSize'); $sorting = $this->getParam('jtSorting'); $filter['hostname'] = $this->getParam('filter_hostname'); $filter['category_id'] = $this->getParam('filter_category_id'); $select = $this->_model->select()->from($this->_model, array( '*', - 'tags_id' => new Zend_Db_Expr('(SELECT GROUP_CONCAT(CASE WHEN `tag`.`tag_fullname` IS NULL THEN `tag`.`tag_name` ELSE `tag`.`tag_fullname` END) + 'groups_id' => new Zend_Db_Expr('(SELECT GROUP_CONCAT(CASE WHEN `tag`.`tag_fullname` IS NULL THEN `tag`.`tag_name` ELSE `tag`.`tag_fullname` END) FROM `config_store_tag`,`tag` WHERE `tag`.`tag_id` = `config_store_tag`.`tag_id` AND `config_store_tag`.`store_id` = `config_store`.`store_id` GROUP BY `config_store_tag`.`store_id`) AS `tags_name`, (SELECT GROUP_CONCAT(`tag`.`tag_id`) FROM `config_store_tag`,`tag` WHERE `tag`.`tag_id` = `config_store_tag`.`tag_id` AND `config_store_tag`.`store_id` = `config_store`.`store_id` - GROUP BY `config_store_tag`.`store_id`)') + GROUP BY `config_store_tag`.`store_id`) AS `tags_id`, + (SELECT GROUP_CONCAT(`tag_group`.`group_name`) + FROM `config_store_tag_group`,`tag_group` + WHERE `tag_group`.`group_id` = `config_store_tag_group`.`tag_group_id` AND `config_store_tag_group`.`store_id` = `config_store`.`store_id` + GROUP BY `config_store_tag_group`.`store_id`) AS `groups_name`, + (SELECT GROUP_CONCAT(`tag_group`.`group_id`) + FROM `config_store_tag_group`,`tag_group` + WHERE `tag_group`.`group_id` = `config_store_tag_group`.`tag_group_id` AND `config_store_tag_group`.`store_id` = `config_store`.`store_id` + GROUP BY `config_store_tag_group`.`store_id`)') ))->order($sorting)->limit($pageSize, $startIndex)->setIntegrityCheck(false); foreach ($filter as $key => $value) { if (false === empty($value)) { $select->where("{$key} like ?", $value); } } $reports = $this->_model->fetchAll($select); $select = $this->_model->select()->from($this->_model)->setIntegrityCheck(false); foreach ($filter as $key => $value) { if (false === empty($value)) { $select->where("{$key} like ?", $value); } } $reportsAll = $this->_model->fetchAll($select->limit(null, null)->reset('columns') ->columns(array('countAll' => new Zend_Db_Expr('count(*)')))); $jTableResult = array(); $jTableResult['Result'] = self::RESULT_OK; $jTableResult['Records'] = $reports->toArray(); $jTableResult['TotalRecordCount'] = $reportsAll->current()->countAll; $this->_helper->json($jTableResult); } public function hostnamesAction() { $result = true; $id = (int)$this->getParam('c'); try { $records = $this->_model->fetchHostnamesForJTable($id); } catch (Exception $e) { Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true)); $result = false; $records = array(); } $jTableResult = array(); $jTableResult['Result'] = ($result == true) ? self::RESULT_OK : self::RESULT_ERROR; $jTableResult['Options'] = $records; $this->_helper->json($jTableResult); } public function loadstoreconfigAction() { $jTableResult = array(); try { $configStoreId = $this->getParam('c'); $modelConfig = new Backend_Model_ClientFileConfig($configStoreId); $modelConfig->loadClientConfig(); if ($modelConfig->getDefaultConfigLoaded()) { $this->view->defaultConfigLoaded = true; } $form = $modelConfig->getForm(); $this->view->formConfig = $form; $view = $this->view->render('store/configform.phtml'); $jTableResult = array(); $jTableResult['Result'] = self::RESULT_OK; $jTableResult['ViewRecord'] = $view; } catch (Exception $e) { Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true)); $translate = Zend_Registry::get('Zend_Translate'); $this->getResponse()->setHttpResponseCode(500); $jTableResult['Result'] = self::RESULT_ERROR; $jTableResult['Message'] = $translate->_('Error while processing data.'); } $this->_helper->json($jTableResult); } public function savestoreconfigAction() { $jTableResult = array(); try { $clientName = $this->getParam('clientname'); unset($_POST['clientname']); $modelConfig = new Backend_Model_ClientFileConfig($clientName); $modelConfig->saveClientConfig($_POST, $clientName); $jTableResult = array(); $jTableResult['Result'] = self::RESULT_OK; } catch (Exception $e) { Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true)); $translate = Zend_Registry::get('Zend_Translate'); $jTableResult['Result'] = self::RESULT_ERROR; $jTableResult['Message'] = $translate->_('Error while processing data.'); } $this->_helper->json($jTableResult); } public function tagsallAction() { $result = true; $tagmodel = new Default_Model_Tags(); try { $resultRows = $tagmodel->getAllTagsForStoreFilter(); $resultForSelect = array(); + $resultForSelect[] = array('DisplayText' => '', 'Value' => ''); foreach ($resultRows as $row) { $resultForSelect[] = array('DisplayText' => $row['tag_name'].'['.$row['tag_id'].']', 'Value' => $row['tag_id']); } } catch (Exception $e) { Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true)); $result = false; $records = array(); } $jTableResult = array(); $jTableResult['Result'] = ($result == true) ? self::RESULT_OK : self::RESULT_ERROR; $jTableResult['Options'] = $resultForSelect; $this->_helper->json($jTableResult); } + + + public function alltaggroupsAction() + { + + $result = true; + $tagmodel = new Default_Model_TagGroup(); + + try { + $resultRows = $tagmodel->fetchAllGroups(); + $resultForSelect = array(); + $resultForSelect[] = array('DisplayText' => '', 'Value' => ''); + foreach ($resultRows as $row) { + $resultForSelect[] = array('DisplayText' => $row['group_name'].'['.$row['group_id'].']', 'Value' => $row['group_id']); + } + + } catch (Exception $e) { + Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true)); + $result = false; + $records = array(); + } + + $jTableResult = array(); + $jTableResult['Result'] = ($result == true) ? self::RESULT_OK : self::RESULT_ERROR; + $jTableResult['Options'] = $resultForSelect; + + $this->_helper->json($jTableResult); + } } \ No newline at end of file diff --git a/application/modules/backend/views/scripts/store/index.phtml b/application/modules/backend/views/scripts/store/index.phtml index 7a52ef2d2..a44b5b522 100644 --- a/application/modules/backend/views/scripts/store/index.phtml +++ b/application/modules/backend/views/scripts/store/index.phtml @@ -1,414 +1,460 @@ . **/ ?>
getCurrentMessages() as $message) : ?>

escape($message); ?>

diff --git a/application/modules/default/controllers/ExploreController.php b/application/modules/default/controllers/ExploreController.php index 25c53cf6f..571f50458 100644 --- a/application/modules/default/controllers/ExploreController.php +++ b/application/modules/default/controllers/ExploreController.php @@ -1,386 +1,441 @@ . **/ class ExploreController extends Local_Controller_Action_DomainSwitch { const DEFAULT_ORDER = 'latest'; const TAG_ISORIGINAL = 'original-product'; /** @var string */ protected $_browserTitlePrepend; public function init() { parent::init(); $this->_auth = Zend_Auth::getInstance(); } public function categoriesAction() { // Filter-Parameter $inputFilterParams['category'] = (int)$this->getParam('cat', null); $inputFilterParams['filter'] = (int)$this->getParam('fil', null); $inputFilterParams['order'] = preg_replace('/[^-a-zA-Z0-9_]/', '', $this->getParam('ord', self::DEFAULT_ORDER)); $inputFilterParams['selected'] = (int)$this->getParam('sel', $inputFilterParams['category']); $modelCategories = new Default_Model_DbTable_ProjectCategory(); $children = $modelCategories->fetchImmediateChildren($inputFilterParams['selected']); $selChild = $modelCategories->fetchElement($inputFilterParams['filter']); $response = $this->generateResponseMsg($children, $inputFilterParams, $selChild); $this->_helper->json($response); } private function generateResponseMsg($children, $inputParams, $selChild) { $result = array(); if (count($children) == 0) { return $result; } $helperBuildExploreUrl = new Default_View_Helper_BuildExploreUrl(); foreach ($children as $child) { $nodeSelectedState = ($inputParams['filter'] == $child['project_category_id']) ? true : false; if (1 == ($child['rgt'] - $child['lft'])) { $result[] = array( 'title' => $child['title'], 'key' => $child['project_category_id'], 'href' => $helperBuildExploreUrl->buildExploreUrl($inputParams['category'], $child['project_category_id'], $inputParams['order']), 'target' => '_top', 'selected' => $nodeSelectedState ); } else { $nodeHasChildren = (1 == ($child['rgt'] - $child['lft'])) ? false : true; $nodeIsSelectedSubCat = (($selChild['lft'] > $child['lft']) AND ($selChild['rgt'] < $child['rgt'])) ? true : false; $nodeExpandedState = false; $nodeChildren = null; if ($nodeHasChildren AND $nodeIsSelectedSubCat) { $nodeExpandedState = true; $modelCategories = new Default_Model_DbTable_ProjectCategory(); $immChildren = $modelCategories->fetchImmediateChildren($child['project_category_id']); $nodeChildren = $this->generateResponseMsg($immChildren, $inputParams, $selChild); } $result[] = array( 'title' => $child['title'], 'key' => $child['project_category_id'], 'folder' => true, 'lazy' => true, 'selected' => $nodeSelectedState, 'expanded' => $nodeExpandedState, 'href' => $helperBuildExploreUrl->buildExploreUrl($inputParams['category'], $child['project_category_id'], $inputParams['order']), 'target' => '_top', 'children' => $nodeChildren ); } } return $result; } /** * @throws Zend_Cache_Exception * @throws Zend_Db_Select_Exception * @throws Zend_Exception * @throws Zend_Loader_PluginLoader_Exception * @throws Zend_Paginator_Exception */ public function indexAction() { // Filter-Parameter $inputFilterOriginal = $this->getParam('filteroriginal', $this->getFilterOriginalFromCookie()); $this->storeFilterOriginalInCookie($inputFilterOriginal); $this->view->inputFilterOriginal = $inputFilterOriginal; $inputCatId = (int)$this->getParam('cat', null); if ($inputCatId) { // $this->view->isFilterCat = true; // $this->view->filterCat = $inputCatId; $this->view->catabout = $this->getCategoryAbout($inputCatId); $helperFetchCategory = new Default_View_Helper_CatTitle(); $catTitle = $helperFetchCategory->catTitle($inputCatId); $this->view->headTitle($catTitle . ' - ' . $_SERVER['HTTP_HOST'], 'SET'); } $this->view->cat_id = $inputCatId; $storeCatIds = Zend_Registry::isRegistered('store_category_list') ? Zend_Registry::get('store_category_list') : null; $filter = array(); $filter['category'] = $inputCatId ? $inputCatId : $storeCatIds; $filter['order'] = preg_replace('/[^-a-zA-Z0-9_]/', '', $this->getParam('ord', self::DEFAULT_ORDER)); $filter['original'] = $inputFilterOriginal == 1 ? self::TAG_ISORIGINAL : null; + $filter['tag'] = Zend_Registry::isRegistered('config_store_tags') ? Zend_Registry::get('config_store_tags') : null; if (APPLICATION_ENV == "development") { Zend_Registry::get('logger')->debug(__METHOD__ . ' - ' . json_encode($filter)); } $tagFilter = Zend_Registry::isRegistered('config_store_tags') ? Zend_Registry::get('config_store_tags') : null; + + + $tagGroupFilter = Zend_Registry::isRegistered('config_store_taggroups') ? Zend_Registry::get('config_store_taggroups') : null; + if(!empty($tagGroupFilter)) { + $filterArray = array(); + foreach ($tagGroupFilter as $tagGroupId) { + $inputFilter = $this->getFilterTagFromCookie($tagGroupId); + $filterArray[$tagGroupId] = $inputFilter; + if(!empty($inputFilter)) { + $filter['tag'][] = $inputFilter; + } + } + $this->view->tag_group_filter = $filterArray; + } + + $page = (int)$this->getParam('page', 1); $storeConfig = Zend_Registry::isRegistered('store_config') ? Zend_Registry::get('store_config') : null; if ($storeConfig->layout_explore && $storeConfig->isRenderReact()) { $pageLimit = 50; $requestedElements = $this->fetchRequestedElements($filter, $pageLimit, ($page - 1) * $pageLimit); $this->view->productsJson = Zend_Json::encode($requestedElements['elements']); $this->view->filtersJson = Zend_Json::encode($filter); $this->view->cat_idJson = Zend_Json::encode($inputCatId); $modelInfo = new Default_Model_Info(); $topprods = $modelInfo->getMostDownloaded(100, $inputCatId, $tagFilter); $this->view->topprodsJson = Zend_Json::encode($topprods); $comments = $modelInfo->getLatestComments(5, $inputCatId, $tagFilter); $this->view->commentsJson = Zend_Json::encode($comments); $modelCategory = new Default_Model_ProjectCategory(); $this->view->categoriesJson = Zend_Json::encode($modelCategory->fetchTreeForView()); $this->_helper->viewRenderer('index-react'); } else { $pageLimit = 10; $requestedElements = $this->fetchRequestedElements($filter, $pageLimit, ($page - 1) * $pageLimit); } $paginator = Local_Paginator::factory($requestedElements['elements']); $paginator->setItemCountPerPage($pageLimit); $paginator->setCurrentPageNumber($page); $paginator->setTotalItemCount($requestedElements['total_count']); $this->view->products = $paginator; $this->view->totalcount = $requestedElements['total_count']; $this->view->filters = $filter; $this->view->page = $page; $this->view->package_type = Zend_Registry::isRegistered('config_store_tags') ? Zend_Registry::get('config_store_tags') : null; $this->view->tags = $tagFilter; } /** * @param $inputCatId * * @return string|null * @throws Zend_Exception */ protected function getCategoryAbout($inputCatId) { $config = Zend_Registry::get('config'); $static_config = $config->settings->static; $include_path_cat = $static_config->include_path . 'category_about/' . $inputCatId . '.phtml'; if (file_exists($include_path_cat)) { return $include_path_cat; } return null; } /** * @param array $inputFilterParams * @param int $limit * @param int $offset * * @return array * @throws Zend_Cache_Exception * @throws Zend_Db_Select_Exception * @throws Zend_Exception */ private function fetchRequestedElements($inputFilterParams, $limit = null, $offset = null) { $modelProject = new Default_Model_Project(); $requestedElements = $modelProject->fetchProjectsByFilter($inputFilterParams, $limit, $offset); return $requestedElements; } /** * @throws Zend_Exception * @throws Zend_Paginator_Exception */ public function searchAction() { ini_set('memory_limit', '3072M'); $allDomainCatIds = Zend_Registry::isRegistered('store_category_list') ? Zend_Registry::get('store_category_list') : null; if (count($allDomainCatIds) == 0) { $allDomainCatIds = null; } if (isset($allDomainCatIds)) { $this->view->categories = $allDomainCatIds; } else { $modelCategories = new Default_Model_DbTable_ProjectCategory(); $this->view->categories = $modelCategories->fetchMainCatIdsOrdered(); } // Filter-Parameter $filterInput = new Zend_Filter_Input(array('*' => 'StringTrim', 'projectSearchText' => 'StripTags', 'page' => 'digits'), array( 'projectSearchText' => array( new Zend_Validate_StringLength(array('min' => 3, 'max' => 100)), 'presence' => 'required' ), 'page' => 'digits' ), $this->getAllParams()); if ($filterInput->hasInvalid()) { $this->_helper->viewRenderer('searchError'); $this->view->messages = $filterInput->getMessages(); return; } $inputFilterParams['projectSearchText'] = $filterInput->getUnescaped('projectSearchText'); $page = (int)$filterInput->getEscaped('page'); $config = Zend_Registry::get('config'); Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('utf-8'); Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8_CaseInsensitive()); $dataPath = $config->settings->search->path; $dataPath .= $this->getNameForStoreClient() . DIRECTORY_SEPARATOR; $index = Zend_Search_Lucene::open($dataPath); try { $hits = $index->find($inputFilterParams['projectSearchText'] . '*'); } catch (Zend_Search_Lucene_Exception $e) { Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . $e->getMessage() . PHP_EOL . $e->getTraceAsString()); $hits = array(); } if (count($hits) == 0) { $this->_helper->viewRenderer('searchError'); $this->view->inputFilter = $inputFilterParams; $this->view->searchText = $inputFilterParams['projectSearchText']; return; } $results = $this->copyToArray($hits); $paginator = Zend_Paginator::factory($results); $paginator->setDefaultItemCountPerPage(10); $paginator->setCurrentPageNumber($page); $this->view->hitsCount = count($hits); $this->view->hits = $paginator; $this->view->page = $page; $this->view->inputFilter = $inputFilterParams; $this->view->searchText = $inputFilterParams['projectSearchText']; } /** * @param array $hits * * @return array */ protected function copyToArray($hits) { $returnArray = array(); /** @var $hit Zend_Search_Lucene_Search_QueryHit */ foreach ($hits as $hit) { $returnArray[] = $hit->getDocument(); } return $returnArray; } protected function _initResponseHeader() { $duration = 1800; // in seconds $expires = gmdate("D, d M Y H:i:s", time() + $duration) . " GMT"; $this->getResponse() ->setHeader('X-FRAME-OPTIONS', 'ALLOWALL', true) // ->setHeader('Last-Modified', $modifiedTime, true) ->setHeader('Expires', $expires, true)->setHeader('Pragma', 'no-cache', true) ->setHeader('Cache-Control', 'private, no-cache, must-revalidate', true) ; } /** * @param Zend_Config $static_config * @return string|null */ protected function getStoreAbout($static_config) { $include_path = $static_config->include_path . 'store_about/' . $this->view->filterStore . '.phtml'; if (file_exists($include_path)) { return $include_path; } return null; } /** * @param array $elements * * @return array with additional info's * @deprecated */ private function fetchAdditionalData($elements) { $modelProject = new Default_Model_Project(); $requestedElements = Array(); foreach ($elements as $project) { $info = $modelProject->fetchProductInfo($project['project_id']); $requestedElements[] = $info; } return $requestedElements; } protected function setLayout() { $layoutName = 'flat_ui_template'; $storeConfig = Zend_Registry::isRegistered('store_config') ? Zend_Registry::get('store_config') : null; if($storeConfig && $storeConfig->layout_explore) { $this->_helper->layout()->setLayout($storeConfig->layout_explore); }else{ $this->_helper->layout()->setLayout($layoutName); } } private function storeFilterOriginalInCookie($inputFilterOriginal) { $storedInCookie = $this->getFilterOriginalFromCookie(); if (isset($inputFilterOriginal) AND ($inputFilterOriginal != $storedInCookie)) { $config = Zend_Registry::get('config'); $cookieName = $config->settings->session->filter_browse_original; $remember_me_seconds = $config->settings->session->remember_me->cookie_lifetime; $cookieExpire = time() + $remember_me_seconds; setcookie($cookieName, $inputFilterOriginal, $cookieExpire, '/'); } } private function getFilterOriginalFromCookie() { $config = Zend_Registry::get('config'); $cookieName = $config->settings->session->filter_browse_original; $storedInCookie = isset($_COOKIE[$cookieName]) ? $_COOKIE[$cookieName] : NULL; return $storedInCookie; } + + + private function storeFilterTagInCookie($group, $tag) + { + $storedInCookie = $this->getFilterTagFromCookie($group); + + if (isset($tag) AND ($tag != $storedInCookie)) { + $config = Zend_Registry::get('config'); + $cookieName = $config->settings->session->filter_browse_original.$group; + $remember_me_seconds = $config->settings->session->remember_me->cookie_lifetime; + $cookieExpire = time() + $remember_me_seconds; + setcookie($cookieName, $tag, $cookieExpire, '/'); + } + } + + private function getFilterTagFromCookie($group) + { + $config = Zend_Registry::get('config'); + $cookieName = $config->settings->session->filter_browse_original.$group; + + $storedInCookie = isset($_COOKIE[$cookieName]) ? $_COOKIE[$cookieName] : NULL; + + return $storedInCookie; + } + + + public function savetaggroupfilterAction() + { + // Filter-Parameter + $tagGroupId = (int)$this->getParam('group_id', null); + $tagId = (int)$this->getParam('tag_id', null); + + $this->storeFilterTagInCookie($tagGroupId, $tagId); + + $response = array(); + $response['Result'] = 'OK'; + $this->_helper->json($response); + } } \ No newline at end of file diff --git a/application/modules/default/models/ConfigStoreTagGroups.php b/application/modules/default/models/ConfigStoreTagGroups.php new file mode 100644 index 000000000..9ad038043 --- /dev/null +++ b/application/modules/default/models/ConfigStoreTagGroups.php @@ -0,0 +1,49 @@ +. + * + * Created: 23.01.2019 + */ +class Default_Model_ConfigStoreTagGroups +{ + + /** + * @param int $store_id + * @param bool $onlyActive + * + * @return null|array + */ + public function getTagGroupsAsIdForStore($store_id, $onlyActive = true) + { + $modelConfigStoreTagGroups = new Default_Model_DbTable_ConfigStoreTagGroups(); + + $sql = "SELECT `tag_group_id` FROM `config_store_tag_group` WHERE `store_id` = :store_id AND `is_active` = :active ORDER BY `tag_group_id`;"; + + $result = $modelConfigStoreTagGroups->getAdapter()->fetchAll($sql, array('store_id' => $store_id, 'active' => ($onlyActive ? 1 : 0)), Zend_Db::FETCH_COLUMN); + + if (0 == count($result)) { + return null; + } + + return $result; + } + +} \ No newline at end of file diff --git a/application/modules/default/models/DbTable/ConfigStoreTagGroups.php b/application/modules/default/models/DbTable/ConfigStoreTagGroups.php new file mode 100644 index 000000000..df74735f9 --- /dev/null +++ b/application/modules/default/models/DbTable/ConfigStoreTagGroups.php @@ -0,0 +1,50 @@ +. + **/ +class Default_Model_DbTable_ConfigStoreTagGroups extends Local_Model_Table +{ + + protected $_name = "config_store_tag_group"; + + protected $_keyColumnsForRow = array('config_store_taggroup_id'); + + protected $_key = 'config_store_taggroup_id'; + + public function delete($where) + { + $where = parent::_whereExpr($where); + + /** + * Build the DELETE statement + */ + $sql = "UPDATE " . parent::getAdapter()->quoteIdentifier($this->_name, true) . " SET `is_active` = 0, `deleted_at` = NOW() " . (($where) ? " WHERE $where" : ''); + + /** + * Execute the statement and return the number of affected rows + */ + $stmt = parent::getAdapter()->query($sql); + $result = $stmt->rowCount(); + + return $result; + } + +} \ No newline at end of file diff --git a/application/modules/default/models/TagGroup.php b/application/modules/default/models/TagGroup.php index 9ce826d8c..80960424a 100644 --- a/application/modules/default/models/TagGroup.php +++ b/application/modules/default/models/TagGroup.php @@ -1,223 +1,240 @@ . * * Created: 13.09.2017 */ class Default_Model_TagGroup { /** * @inheritDoc */ public function __construct() { } public function fetchGroupHierarchy() { $sql = " SELECT tag_group.group_name, tag.tag_id, tag.tag_name FROM tag_group_item JOIN tag_group ON tag_group.group_id = tag_group_item.tag_group_id JOIN tag ON tag.tag_id = tag_group_item.tag_id "; $resultSet = $this->getAdapter()->fetchAll($sql); $optgroup = array(); foreach ($resultSet as $item) { $optgroup[$item['group_name']][$item['tag_id']] = $item['tag_name']; } return $optgroup; } public function fetchAllGroups() { $sql = " SELECT tag_group.group_name, tag_group.group_id FROM tag_group "; $resultSet = $this->getAdapter()->fetchAll($sql); return $resultSet; } /** * @return Zend_Db_Adapter_Abstract */ private function getAdapter() { return Zend_Db_Table::getDefaultAdapter(); } /** * @param int $group_id * * @return array */ public function fetchGroupItems($group_id) { $sql = "SELECT tag_group_item.tag_group_item_id , tag_group_item.tag_group_id , tag.tag_id, tag.tag_name , tag.tag_fullname , tag.tag_description , tag.is_active FROM tag_group_item JOIN tag ON tag.tag_id = tag_group_item.tag_id WHERE tag_group_id = :group_id"; $resultSet = $this->getAdapter()->fetchAll($sql, array('group_id' => $group_id)); return $resultSet; } /** * @param int $group_id * @param string $tag_name * * @return array */ public function assignGroupTag($group_id, $tag_name,$tag_fullname, $tag_description,$is_active=1) { $tag_id = $this->saveTag($tag_name,$tag_fullname, $tag_description,$is_active); $group_tag_id = $this->saveGroupTag($group_id, $tag_id); $resultSet = $this->fetchOneGroupItem($group_tag_id); return $resultSet; } /** * @param string $tag_name * * @return int */ public function saveTag($tag_name,$tag_fullname, $tag_description,$is_active=1) { $tag_name = strtolower($tag_name); $sql = "SELECT tag_id FROM tag WHERE tag_name = :tagName"; $resultSet = $this->getAdapter()->fetchRow($sql, array('tagName' => $tag_name)); if (empty($resultSet)) { $this->getAdapter()->insert('tag', array('tag_name' => $tag_name, 'tag_fullname' => $tag_fullname, 'tag_description' => $tag_description,'is_active' => $is_active)); $resultId = $this->getAdapter()->lastInsertId(); } else { $resultId = $resultSet['tag_id']; } return $resultId; } /** * @param int $group_id * @param int $tag_id * * @return int */ public function saveGroupTag($group_id, $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->getAdapter()->fetchRow($sql, array('group_id' => $group_id, 'tag_id' => $tag_id)); if (empty($resultSet)) { $this->getAdapter()->insert('tag_group_item', array('tag_group_id' => $group_id, 'tag_id' => $tag_id)); $resultId = $this->getAdapter()->lastInsertId(); } else { $resultId = $resultSet['tag_group_item_id']; } return $resultId; } /** * @param int $group_item_id * * @return array|false */ public function fetchOneGroupItem($group_item_id) { $sql = "SELECT tag_group_item.tag_group_item_id , tag_group_item.tag_group_id , tag.tag_id, tag.tag_name , tag.tag_fullname , tag.tag_description , tag.is_active FROM tag_group_item JOIN tag ON tag.tag_id = tag_group_item.tag_id WHERE tag_group_item_id = :group_item_id"; $resultSet = $this->getAdapter()->fetchRow($sql, array('group_item_id' => $group_item_id)); return $resultSet; } public function updateGroupTag($tag_id, $tag_name,$tag_fullname, $tag_description,$is_active=1) { $updateValues = array( 'tag_name' =>$tag_name, 'tag_fullname' => $tag_fullname, 'tag_description' => $tag_description, 'is_active' => $is_active ); $this->getAdapter()->update('tag', $updateValues, array('tag_id = ?' => $tag_id)); } public function deleteGroupTag($groupItemId) { $this->getAdapter()->delete('tag_group_item', array('tag_group_item_id = ?' => $groupItemId)); } public function fetchTagGroupsForCategory($cat_id) { $sql = " SELECT category_tag_group.tag_group_id , tag_group.group_name , tag_group.group_display_name , tag_group.group_legacy_name , category_tag_group.category_id , project_category.title FROM category_tag_group JOIN tag_group ON tag_group.group_id = category_tag_group.tag_group_id JOIN project_category ON project_category.project_category_id = category_tag_group.category_id WHERE category_tag_group.category_id = :cat_id"; $resultSet = $this->getAdapter()->fetchAll($sql, array('cat_id' => $cat_id)); return $resultSet; } public function updateTagGroupsPerCategory($cat_id,$taggroups) { $sql = "delete from category_tag_group where category_id=:cat_id"; $this->getAdapter()->query($sql, array('cat_id' => $cat_id)); if($taggroups){ $taggroup_id =explode(',', $taggroups); $prepared_insert = array_map(function ($id) use ($cat_id) { return "({$cat_id},{$id})"; }, $taggroup_id); $sql = "INSERT IGNORE INTO category_tag_group (category_id, tag_group_id) VALUES " . implode(',', $prepared_insert); $this->getAdapter()->query($sql); } } + + public function updateTagGroupsPerStore($store_id,$taggroups) + { + $sql = "delete from config_store_tag_group where store_id=:store_id"; + $this->getAdapter()->query($sql, array('store_id' => $store_id)); + + if($taggroups){ + $taggroup_id =explode(',', $taggroups); + $prepared_insert = + array_map(function ($id) use ($store_id) { return "({$store_id},{$id})"; }, + $taggroup_id); + $sql = "INSERT IGNORE INTO config_store_tag_group (store_id, tag_group_id) VALUES " . implode(',', + $prepared_insert); + + $this->getAdapter()->query($sql); + } + } } \ No newline at end of file diff --git a/application/modules/default/models/Tags.php b/application/modules/default/models/Tags.php index 279d5b15d..cba8c6a20 100644 --- a/application/modules/default/models/Tags.php +++ b/application/modules/default/models/Tags.php @@ -1,1026 +1,1041 @@ . * * Created: 11.09.2017 */ class Default_Model_Tags { const TAG_TYPE_PROJECT = 1; const TAG_TYPE_MEMBER = 2; const TAG_TYPE_FILE = 3; const TAG_USER_GROUPID = 5; const TAG_CATEGORY_GROUPID = 6; const TAG_LICENSE_GROUPID = 7; const TAG_PACKAGETYPE_GROUPID = 8; const TAG_ARCHITECTURE_GROUPID = 9; const TAG_GHNS_EXCLUDED_GROUPID = 10; const TAG_PRODUCT_ORIGINAL_GROUPID = 11; const TAG_PRODUCT_ORIGINAL_ID = 2451; const TAG_PRODUCT_EBOOK_GROUPID = 14; const TAG_PRODUCT_EBOOK_AUTHOR_GROUPID = 15; const TAG_PRODUCT_EBOOK_EDITOR_GROUPID = 16; const TAG_PRODUCT_EBOOK_ILLUSTRATOR_GROUPID = 17; const TAG_PRODUCT_EBOOK_TRANSLATOR_GROUPID = 18; const TAG_PRODUCT_EBOOK_SUBJECT_GROUPID = 19; const TAG_PRODUCT_EBOOK_SHELF_GROUPID = 20; const TAG_PRODUCT_EBOOK_LANGUAGE_GROUPID = 21; const TAG_PRODUCT_EBOOK_TYPE_GROUPID = 22; const TAG_PRODUCT_EBOOK_ID = 2532; const TAG_PROJECT_GROUP_IDS = '6,7,10';//type product : category-tags, license-tags,ghns_excluded const TAG_FILE_GROUP_IDS = '8,9';//file-packagetype-tags,file-architecture-tags // $tag_project_group_ids ='6,7,10'; // $tag_file_group_ids ='8,9'; /** * Default_Model_Tags constructor. */ public function __construct() { } /** * @param int $object_id * @param string $tags * @param int $tag_type */ public function processTags($object_id, $tags, $tag_type) { $this->assignTags($object_id, $tags, $tag_type); $this->deassignTags($object_id, $tags, $tag_type); } /** * @param int $object_id * @param string $tags * @param int $tag_type */ public function assignTags($object_id, $tags, $tag_type) { $new_tags = array_diff(explode(',', $tags), explode(',', $this->getTags($object_id, $tag_type))); $tableTags = new Default_Model_DbTable_Tags(); $listIds = $tableTags->storeTags(implode(',', $new_tags)); $prepared_insert = array_map(function ($id) use ($object_id, $tag_type) { return "({$id}, {$tag_type}, {$object_id})"; }, $listIds); $sql = "INSERT IGNORE INTO tag_object (tag_id, tag_type_id, tag_object_id) VALUES " . implode(',', $prepared_insert); $this->getAdapter()->query($sql); } /** * @param int $object_id * @param int $tag_type * * @return string|null */ public function getTags($object_id, $tag_type) { $sql = " SELECT GROUP_CONCAT(tag.tag_name) AS tag_names FROM tag_object JOIN tag ON tag.tag_id = tag_object.tag_id join tag_group_item on tag_object.tag_id = tag_group_item.tag_id WHERE tag_type_id = :type AND tag_object_id = :object_id and tag_group_item.tag_group_id <> :tag_user_groupid and tag_object.is_deleted = 0 GROUP BY tag_object.tag_object_id "; $result = $this->getAdapter()->fetchRow($sql, array('type' => $tag_type, 'object_id' => $object_id, 'tag_user_groupid' =>Default_Model_Tags::TAG_USER_GROUPID )); if (isset($result['tag_names'])) { return $result['tag_names']; } return null; } /** * @param int $object_id * @param int $tag_type * @param String $tag_group_ids * * @return string|null */ public function getTagsArray($object_id, $tag_type,$tag_group_ids) { $sql = " SELECT tag.tag_id,tag.tag_name,tag_group_item.tag_group_id,tag.tag_fullname FROM tag_object JOIN tag ON tag.tag_id = tag_object.tag_id join tag_group_item on tag_object.tag_id = tag_group_item.tag_id and tag_object.tag_group_id = tag_group_item.tag_group_id WHERE tag_type_id = :type AND tag_object_id = :object_id and tag_object.tag_group_id in ({$tag_group_ids} ) and tag_object.is_deleted = 0 order by tag_group_item.tag_group_id desc , tag.tag_name asc "; $result = $this->getAdapter()->fetchAll($sql, array('type' => $tag_type, 'object_id' => $object_id)); return $result; } /** * @param int $object_id * @param int $tag_type * * @return string|null */ public function getTagsUser($object_id, $tag_type) { $tag_group_ids =$this::TAG_USER_GROUPID; $tags = $this->getTagsArray($object_id, $tag_type,$tag_group_ids); $tag_names = ''; foreach ($tags as $tag) { $tag_names=$tag_names.$tag['tag_name'].','; } $len = strlen($tag_names); if ($len>0) { return substr($tag_names,0,($len-1)); } return null; } /** * @param int $projectid * @param int $tag * * @return string|null */ public function isTagsUserExisting($project_id, $tagname) { $sql_object= "select count(1) as cnt from tag_object JOIN tag ON tag.tag_id = tag_object.tag_id WHERE tag.tag_name = :tagname and tag_object.tag_group_id=:tag_group_id and tag_object.is_deleted=0 and tag_object.tag_object_id=:project_id and tag_object.tag_type_id=:tag_type_id"; $r = $this->getAdapter()->fetchRow($sql_object, array( 'tagname' => $tagname ,'tag_group_id'=>Default_Model_Tags::TAG_USER_GROUPID , 'project_id'=>$project_id , 'tag_type_id'=>Default_Model_Tags::TAG_TYPE_PROJECT )); if($r['cnt'] ==0){ return false; }else{ return true; } } /** * @param int $object_id * @param int $tag_type * * @return string|null */ public function getTagsCategory($object_id, $tag_type) { $tag_group_ids = $this::TAG_CATEGORY_GROUPID; $tags = $this->getTagsArray($object_id, $tag_type,$tag_group_ids); $tag_names = ''; foreach ($tags as $tag) { $tag_names=$tag_names.$tag['tag_name'].','; } $len = strlen($tag_names); if ($len>0) { return substr($tag_names,0,($len-1)); } return null; } /** * @param int $object_id * @param int $tag_type * * @return string|null */ public function getTagsSystem($object_id, $tag_type) { $tag_group_ids ='6,7,10'; $tags = $this->getTagsArray($object_id, $tag_type,$tag_group_ids); $tag_names = ''; foreach ($tags as $tag) { $tag_names=$tag_names.$tag['tag_name'].','; } $len = strlen($tag_names); if ($len>0) { return substr($tag_names,0,($len-1)); } return null; } /** * @param int $object_id * @param int $tag_type * * @return string|null */ public function getTagsSystemList($project_id) { $tag_project_group_ids = SELF::TAG_PROJECT_GROUP_IDS; $tag_file_group_ids = SELF::TAG_FILE_GROUP_IDS; $sql =" SELECT tag.tag_id,tag.tag_name,tag_object.tag_group_id FROM tag_object JOIN tag ON tag.tag_id = tag_object.tag_id WHERE tag_type_id = :type_project AND tag_object_id = :project_id and tag_object.tag_group_id in ({$tag_project_group_ids} ) and tag_object.is_deleted = 0 union all SELECT distinct t.tag_id,t.tag_name,o.tag_group_id FROM tag_object o JOIN tag t ON t.tag_id = o.tag_id inner join project p on o.tag_parent_object_id = p.project_id inner join ppload.ppload_files f on p.ppload_collection_id = f.collection_id and o.tag_object_id=f.id and f.active = 1 WHERE o.tag_type_id = :type_file AND p.project_id = :project_id and o.tag_group_id in ({$tag_file_group_ids} ) and o.is_deleted = 0 order by tag_group_id , tag_name "; $result = $this->getAdapter()->fetchAll($sql, array('type_project' => Default_Model_Tags::TAG_TYPE_PROJECT , 'project_id' => $project_id , 'type_file' => Default_Model_Tags::TAG_TYPE_FILE )); return $result; } /** * @param int $object_id * @param int $tag_type * * @return string|null */ public function getTagsUserCount($object_id, $tag_type) { $sql = " SELECT count(*) as cnt FROM tag_object JOIN tag ON tag.tag_id = tag_object.tag_id join tag_group_item on tag_object.tag_id = tag_group_item.tag_id and tag_object.tag_group_id = tag_group_item.tag_group_id WHERE tag_type_id = :type AND tag_object_id = :object_id and tag_object.is_deleted = 0 and tag_group_item.tag_group_id = :tag_user_groupid "; $result = $this->getAdapter()->fetchRow($sql, array('type' => $tag_type, 'object_id' => $object_id, 'tag_user_groupid' =>Default_Model_Tags::TAG_USER_GROUPID )); if (isset($result['cnt'])) { return $result['cnt']; } return 0; } public function filterTagsUser($filter, $limit) { $sql = " select tag.tag_id ,tag.tag_name from tag join tag_group_item on tag.tag_id = tag_group_item.tag_id and tag_group_item.tag_group_id = :tag_user_groupid where tag.tag_name like '%".$filter."%' "; if (isset($limit)) { $sql.= ' limit ' . $limit; } $result = $this->getAdapter()->fetchAll($sql, array('tag_user_groupid' =>Default_Model_Tags::TAG_USER_GROUPID )); return $result; } /** * @return Zend_Db_Adapter_Abstract */ private function getAdapter() { return Zend_Db_Table::getDefaultAdapter(); } /** * @param int $object_id * @param string $tags * @param int $tag_type */ public function deassignTags($object_id, $tags, $tag_type) { $removable_tags = array_diff(explode(',', $this->getTags($object_id, $tag_type)), explode(',', $tags)); //$sql = "DELETE tag_object FROM tag_object JOIN tag ON tag.tag_id = tag_object.tag_id WHERE tag.tag_name = :name and tag_object.tag_object_id=:object_id"; $sql = "UPDATE tag_object inner join tag ON tag.tag_id = tag_object.tag_id SET tag_changed = NOW() , is_deleted = 1 WHERE tag.tag_name = :name and tag_object.tag_object_id=:object_id"; $this->getAdapter()->query($sql, array('tagObjectId' => $object_id, 'tagType' => $tag_type)); foreach ($removable_tags as $removable_tag) { $this->getAdapter()->query($sql, array('name' => $removable_tag,'object_id' => $object_id)); } $this->updateChanged($object_id, $tag_type); } /** * @param int $object_id * @param string $tags * @param int $tag_type */ public function processTagsUser($object_id, $tags, $tag_type) { if($tags) { $this->assignTagsUser($object_id, $tags, $tag_type); } $this->deassignTagsUser($object_id, $tags, $tag_type); } public function isProuductOriginal($project_id) { $sql_object= "select tag_item_id from tag_object WHERE tag_id = :tag_id and tag_object_id=:tag_object_id and tag_group_id=:tag_group_id and tag_type_id = :tag_type_id and is_deleted = 0"; $r = $this->getAdapter()->fetchRow($sql_object, array('tag_id' => self::TAG_PRODUCT_ORIGINAL_ID, 'tag_object_id' =>$project_id, 'tag_group_id' => self::TAG_PRODUCT_ORIGINAL_GROUPID, 'tag_type_id' => self::TAG_TYPE_PROJECT )); if($r){ return true; }else { return false; } } public function isProuductEbook($project_id) { $sql_object= "select tag_item_id from tag_object WHERE tag_id = :tag_id and tag_object_id=:tag_object_id and tag_group_id=:tag_group_id and tag_type_id = :tag_type_id and is_deleted = 0"; $r = $this->getAdapter()->fetchRow($sql_object, array('tag_id' => self::TAG_PRODUCT_EBOOK_ID, 'tag_object_id' =>$project_id, 'tag_group_id' => self::TAG_PRODUCT_EBOOK_GROUPID, 'tag_type_id' => self::TAG_TYPE_PROJECT )); if($r){ return true; }else { return false; } } /** * @param int $object_id * @param string $value */ public function processTagProductOriginal($object_id, $is_original) { $sql_object= "select tag_item_id from tag_object WHERE tag_id = :tag_id and tag_object_id=:tag_object_id and tag_group_id=:tag_group_id and tag_type_id = :tag_type_id and is_deleted = 0"; $r = $this->getAdapter()->fetchRow($sql_object, array('tag_id' => self::TAG_PRODUCT_ORIGINAL_ID, 'tag_object_id' =>$object_id, 'tag_group_id' => self::TAG_PRODUCT_ORIGINAL_GROUPID, 'tag_type_id' => self::TAG_TYPE_PROJECT )); if($is_original=='1') { if(!$r){ $sql = "INSERT IGNORE INTO tag_object (tag_id, tag_type_id, tag_object_id, tag_group_id) VALUES (:tag_id, :tag_type_id, :tag_object_id, :tag_group_id)"; $this->getAdapter()->query($sql, array('tag_id' => self::TAG_PRODUCT_ORIGINAL_ID, 'tag_type_id' => self::TAG_TYPE_PROJECT , 'tag_object_id' => $object_id, 'tag_group_id' => self::TAG_PRODUCT_ORIGINAL_GROUPID)); } }else{ if($r){ $sql = "UPDATE tag_object set tag_changed = NOW() , is_deleted = 1 WHERE tag_item_id = :tagItemId"; $this->getAdapter()->query($sql, array('tagItemId' => $r['tag_item_id'])); } } } /** * @param int $object_id * @param string $tags * @param int $tag_type */ public function assignTagsUser($object_id, $tags, $tag_type) { $tags = strtolower($tags); $tag_group_id = 5; $new_tags = array_diff(explode(',', $tags), explode(',', $this->getTagsUser($object_id, $tag_type))); if(sizeof($new_tags)>0) { $tableTags = new Default_Model_DbTable_Tags(); $listIds = $tableTags->storeTagsUser(implode(',', $new_tags)); $prepared_insert = array_map(function ($id) use ($object_id, $tag_type,$tag_group_id) { return "({$id}, {$tag_type}, {$object_id},{$tag_group_id})"; }, $listIds); $sql = "INSERT IGNORE INTO tag_object (tag_id, tag_type_id, tag_object_id,tag_group_id) VALUES " . implode(',', $prepared_insert); $this->getAdapter()->query($sql); } } /** * @param int $object_id * @param string $tags * @param int $tag_type */ public function addTagUser($object_id, $tag, $tag_type) { $tableTags = new Default_Model_DbTable_Tags(); $listIds = $tableTags->storeTagsUser($tag); $tag_group_id = $this::TAG_USER_GROUPID; $prepared_insert = array_map(function ($id) use ($object_id, $tag_type,$tag_group_id) { return "({$id}, {$tag_type}, {$object_id},{$tag_group_id})"; }, $listIds); $sql = "INSERT IGNORE INTO tag_object (tag_id, tag_type_id, tag_object_id,tag_group_id) VALUES " . implode(',', $prepared_insert); $this->getAdapter()->query($sql); } public function deassignTagsUser($object_id, $tags, $tag_type) { if($tags) { $tags = strtolower($tags); $removable_tags = array_diff(explode(',', $this->getTagsUser($object_id, $tag_type)), explode(',', $tags)); } else { $removable_tags = explode(',', $this->getTagsUser($object_id, $tag_type)); } //$sql = "DELETE tag_object FROM tag_object JOIN tag ON tag.tag_id = tag_object.tag_id WHERE tag_group_id = ".Default_Model_Tags::TAG_USER_GROUPID." and tag.tag_name = :name and tag_object.tag_object_id=:object_id"; $sql = "UPDATE tag_object inner join tag ON tag.tag_id = tag_object.tag_id set tag_changed = NOW() , is_deleted = 1 WHERE tag_group_id = ".Default_Model_Tags::TAG_USER_GROUPID." and tag.tag_name = :name and tag_object.tag_object_id=:object_id"; foreach ($removable_tags as $removable_tag) { $this->getAdapter()->query($sql, array('name' => $removable_tag,'object_id' => $object_id)); // if Tag is the only one in Tag_object table then delete this tag for user_groupid = 5 $sql_object= "select count(1) as cnt from tag_object JOIN tag ON tag.tag_id = tag_object.tag_id WHERE tag.tag_name = :name"; $r = $this->getAdapter()->fetchRow($sql_object, array('name' => $removable_tag)); if($r['cnt'] ==0){ // then remove tag if not existing in Tag_object $sql_delete_tag = "delete from tag where tag_name=:name"; $this->getAdapter()->query($sql_delete_tag, array('name' => $removable_tag)); } } $this->updateChanged($object_id, $tag_type); } public function deleteTagUser($object_id, $tag, $tag_type) { $removable_tag =$tag; // $sql = "DELETE tag_object FROM tag_object JOIN tag ON tag.tag_id = tag_object.tag_id WHERE tag_group_id = ".Default_Model_Tags::TAG_USER_GROUPID." and tag.tag_name = :name and tag_object.tag_object_id=:object_id // and tag_group_id =".Default_Model_Tags::TAG_USER_GROUPID; $sql = "UPDATE tag_object inner join tag ON tag.tag_id = tag_object.tag_id set tag_changed = NOW() , is_deleted = 1 WHERE tag_group_id = ".Default_Model_Tags::TAG_USER_GROUPID." and tag.tag_name = :name and tag_object.tag_object_id=:object_id"; $this->getAdapter()->query($sql, array('name' => $removable_tag,'object_id' => $object_id)); // if Tag is the only one in Tag_object table then delete this tag for user_groupid = 5 $sql_object= "select count(1) as cnt from tag_object JOIN tag ON tag.tag_id = tag_object.tag_id WHERE tag.tag_name = :name "; $r = $this->getAdapter()->fetchRow($sql_object, array('name' => $removable_tag)); if($r['cnt'] ==0){ // then remove tag if not existing in Tag_object $sql_delete_tag = "delete from tag where tag_name=:name"; $this->getAdapter()->query($sql_delete_tag, array('name' => $removable_tag)); } $this->updateChanged($object_id, $tag_type); } private function updateChanged($object_id, $tag_type) { $sql = "UPDATE tag_object SET tag_changed = NOW() WHERE tag_object_id = :tagObjectId AND tag_type_id = :tagType"; $this->getAdapter()->query($sql, array('tagObjectId' => $object_id, 'tagType' => $tag_type)); } public function getTagsPerCategory($cat_id) { $sql = "select t.* from category_tag as c ,tag as t where c.tag_id = t.tag_id and c.category_id = :cat_id"; $r = $this->getAdapter()->fetchAll($sql, array('cat_id' => $cat_id)); return $r; } public function updateTagsPerCategory($cat_id,$tags) { $sql = "delete from category_tag where category_id=:cat_id"; $this->getAdapter()->query($sql, array('cat_id' => $cat_id)); if($tags){ $tags_id =explode(',', $tags); $prepared_insert = array_map(function ($id) use ($cat_id) { return "({$cat_id},{$id})"; }, $tags_id); $sql = "INSERT IGNORE INTO category_tag (category_id, tag_id) VALUES " . implode(',', $prepared_insert); $this->getAdapter()->query($sql); } } public function updateTagsPerStore($store_id,$tags) { $sql = "delete from config_store_tag where store_id=:store_id"; $this->getAdapter()->query($sql, array('store_id' => $store_id)); if($tags){ $tags_id =explode(',', $tags); $prepared_insert = array_map(function ($id) use ($store_id) { return "({$store_id},{$id})"; }, $tags_id); $sql = "INSERT IGNORE INTO config_store_tag (store_id, tag_id) VALUES " . implode(',', $prepared_insert); $this->getAdapter()->query($sql); } } public function getTagsPerGroup($groupid) { $sql = " select tag.tag_id ,tag.tag_name from tag join tag_group_item on tag.tag_id = tag_group_item.tag_id and tag_group_item.tag_group_id = :groupid order by tag_name "; $result = $this->getAdapter()->fetchAll($sql, array('groupid' => $groupid)); return $result; } public function getAllTagsForStoreFilter() { $sql = " select tag.tag_id, CASE WHEN tag.tag_fullname IS NULL THEN tag_name ELSE tag.tag_fullname END as tag_name from tag where tag.is_active = 1 order by tag_name "; $result = $this->getAdapter()->fetchAll($sql); return $result; } + + + public function getAllTagGroupsForStoreFilter() + { + $sql = " + select + tag_group.group_id, + tag_group.group_name as group_name + from tag_group + order by tag_group.group_name + + "; + $result = $this->getAdapter()->fetchAll($sql); + return $result; + } public function saveLicenseTagForProject($object_id, $tag_id) { $tableTags = new Default_Model_DbTable_Tags(); $tags = $tableTags->fetchLicenseTagsForProject($object_id); if(count($tags) ==0){ //insert new tag if($tag_id) { $sql = "INSERT IGNORE INTO tag_object (tag_id, tag_type_id, tag_object_id, tag_group_id) VALUES (:tag_id, :tag_type_id, :tag_object_id, :tag_group_id)"; $this->getAdapter()->query($sql, array('tag_id' => $tag_id, 'tag_type_id' => $this::TAG_TYPE_PROJECT, 'tag_object_id' => $object_id, 'tag_group_id' => $this::TAG_LICENSE_GROUPID)); } }else { $tag = $tags[0]; //remove tag license if(!$tag_id) { //$sql = "DELETE FROM tag_object WHERE tag_item_id = :tagItemId"; $sql = "UPDATE tag_object set tag_changed = NOW() , is_deleted = 1 WHERE tag_item_id = :tagItemId"; $this->getAdapter()->query($sql, array('tagItemId' => $tag['tag_item_id'])); } else { //Update old tag if($tag_id <> $tag['tag_id']) { $sql = "UPDATE tag_object SET tag_changed = NOW(),tag_id = :tag_id WHERE tag_item_id = :tagItemId"; $this->getAdapter()->query($sql, array('tagItemId' => $tag['tag_item_id'], 'tag_id' => $tag_id)); } } } // if(count($tags) >= 1) { // $tag = $tags[0]; // //remove tag license // if(!$tag_id) { // //$sql = "DELETE FROM tag_object WHERE tag_item_id = :tagItemId"; // $sql = "UPDATE tag_object set tag_changed = NOW() , is_deleted = 1 WHERE tag_item_id = :tagItemId"; // $this->getAdapter()->query($sql, array('tagItemId' => $tag['tag_item_id'])); // } else { // //Update old tag // if($tag_id <> $tag['tag_id']) { // $sql = "UPDATE tag_object SET tag_changed = NOW(),tag_id = :tag_id WHERE tag_item_id = :tagItemId"; // $this->getAdapter()->query($sql, array('tagItemId' => $tag['tag_item_id'], 'tag_id' => $tag_id)); // } // } // } else { // //insert new tag // if($tag_id) { // $sql = "INSERT IGNORE INTO tag_object (tag_id, tag_type_id, tag_object_id, tag_group_id) VALUES (:tag_id, :tag_type_id, :tag_object_id, :tag_group_id)"; // $this->getAdapter()->query($sql, array('tag_id' => $tag_id, 'tag_type_id' => $this::TAG_TYPE_PROJECT, 'tag_object_id' => $object_id, 'tag_group_id' => $this::TAG_LICENSE_GROUPID)); // } // } } public function saveGhnsExcludedTagForProject($object_id, $tag_value) { $tableTags = new Default_Model_DbTable_Tags(); $ghnsExcludedTagId = $tableTags->fetchGhnsExcludedTagId(); $sql = "UPDATE tag_object SET tag_changed = NOW() , is_deleted = 1 WHERE tag_group_id = :tag_group_id AND tag_type_id = :tag_type_id AND tag_object_id = :tag_object_id"; $this->getAdapter()->query($sql, array('tag_group_id' => $this::TAG_GHNS_EXCLUDED_GROUPID, 'tag_type_id' => $this::TAG_TYPE_PROJECT, 'tag_object_id' => $object_id)); if($tag_value == 1) { $sql = "INSERT IGNORE INTO tag_object (tag_id, tag_type_id, tag_object_id, tag_group_id) VALUES (:tag_id, :tag_type_id, :tag_object_id, :tag_group_id)"; $this->getAdapter()->query($sql, array('tag_id' => $ghnsExcludedTagId, 'tag_type_id' => $this::TAG_TYPE_PROJECT, 'tag_object_id' => $object_id, 'tag_group_id' => $this::TAG_GHNS_EXCLUDED_GROUPID)); } } public function saveArchitectureTagForProject($project_id, $file_id, $tag_id) { //first delte old //$sql = "DELETE FROM tag_object WHERE tag_group_id = :tag_group_id AND tag_type_id = :tag_type_id AND tag_object_id = :tag_object_id AND tag_parent_object_id = :tag_parent_object_id"; $sql = "UPDATE tag_object SET tag_changed = NOW() , is_deleted = 1 WHERE tag_group_id = :tag_group_id AND tag_type_id = :tag_type_id AND tag_object_id = :tag_object_id AND tag_parent_object_id = :tag_parent_object_id"; $this->getAdapter()->query($sql, array('tag_group_id' => $this::TAG_ARCHITECTURE_GROUPID, 'tag_type_id' => $this::TAG_TYPE_FILE, 'tag_object_id' => $file_id, 'tag_parent_object_id' => $project_id)); if($tag_id) { $sql = "INSERT IGNORE INTO tag_object (tag_id, tag_type_id, tag_object_id, tag_parent_object_id, tag_group_id) VALUES (:tag_id, :tag_type_id, :tag_object_id, :tag_parent_object_id, :tag_group_id)"; $this->getAdapter()->query($sql, array('tag_id' => $tag_id, 'tag_type_id' => $this::TAG_TYPE_FILE, 'tag_object_id' => $file_id, 'tag_parent_object_id' => $project_id, 'tag_group_id' => $this::TAG_ARCHITECTURE_GROUPID)); } /** $tableTags = new Default_Model_DbTable_Tags(); $tags = $tableTags->fetchArchitectureTagsForProject($object_id); if(count($tags) == 1) { $tag = $tags[0]; //remove tag license if(!$tag_id) { $sql = "DELETE FROM tag_object WHERE tag_item_id = :tagItemId"; $this->getAdapter()->query($sql, array('tagItemId' => $tag['tag_item_id'])); } else { //Update old tag if($tag_id <> $tag['tag_id']) { $sql = "UPDATE tag_object SET tag_changed = NOW(),tag_id = :tag_id WHERE tag_item_id = :tagItemId"; $this->getAdapter()->query($sql, array('tagItemId' => $tag['tag_item_id'], 'tag_id' => $tag_id)); } } } else { //insert new tag if($tag_id) { $sql = "INSERT IGNORE INTO tag_object (tag_id, tag_type_id, tag_object_id, tag_group_id) VALUES (:tag_id, :tag_type_id, :tag_object_id, :tag_group_id)"; $this->getAdapter()->query($sql, array('tag_id' => $tag_id, 'tag_type_id' => $this::TAG_TYPE_PROJECT, 'tag_object_id' => $object_id, 'tag_group_id' => $this::TAG_ARCHITECTURE_GROUPID)); } } * */ } public function saveFileTagForProjectAndTagGroup($project_id, $file_id, $tag_id, $tag_group_id) { //first delte old $sql = "UPDATE tag_object SET tag_changed = NOW() , is_deleted = 1 WHERE tag_group_id = :tag_group_id AND tag_type_id = :tag_type_id AND tag_object_id = :tag_object_id AND tag_parent_object_id = :tag_parent_object_id"; $this->getAdapter()->query($sql, array('tag_group_id' => $tag_group_id, 'tag_type_id' => $this::TAG_TYPE_FILE, 'tag_object_id' => $file_id, 'tag_parent_object_id' => $project_id)); if($tag_id) { $sql = "INSERT IGNORE INTO tag_object (tag_id, tag_type_id, tag_object_id, tag_parent_object_id, tag_group_id) VALUES (:tag_id, :tag_type_id, :tag_object_id, :tag_parent_object_id, :tag_group_id)"; $this->getAdapter()->query($sql, array('tag_id' => $tag_id, 'tag_type_id' => $this::TAG_TYPE_FILE, 'tag_object_id' => $file_id, 'tag_parent_object_id' => $project_id, 'tag_group_id' => $tag_group_id)); } } public function deleteFileTagForProject($project_id, $file_id, $tag_id) { //first delte old $sql = "UPDATE tag_object SET tag_changed = NOW() , is_deleted = 1 WHERE tag_id= :tag_id AND tag_type_id = :tag_type_id AND tag_object_id = :tag_object_id AND tag_parent_object_id = :tag_parent_object_id"; $this->getAdapter()->query($sql, array('tag_id' => $tag_id, 'tag_type_id' => $this::TAG_TYPE_FILE, 'tag_object_id' => $file_id, 'tag_parent_object_id' => $project_id)); } public function savePackagetypeTagForProject($project_id, $file_id, $tag_id) { //first delte old $sql = "UPDATE tag_object SET tag_changed = NOW() , is_deleted = 1 WHERE tag_group_id = :tag_group_id AND tag_type_id = :tag_type_id AND tag_object_id = :tag_object_id AND tag_parent_object_id = :tag_parent_object_id"; $this->getAdapter()->query($sql, array('tag_group_id' => $this::TAG_PACKAGETYPE_GROUPID, 'tag_type_id' => $this::TAG_TYPE_FILE, 'tag_object_id' => $file_id, 'tag_parent_object_id' => $project_id)); if($tag_id) { $sql = "INSERT IGNORE INTO tag_object (tag_id, tag_type_id, tag_object_id, tag_parent_object_id, tag_group_id) VALUES (:tag_id, :tag_type_id, :tag_object_id, :tag_parent_object_id, :tag_group_id)"; $this->getAdapter()->query($sql, array('tag_id' => $tag_id, 'tag_type_id' => $this::TAG_TYPE_FILE, 'tag_object_id' => $file_id, 'tag_parent_object_id' => $project_id, 'tag_group_id' => $this::TAG_PACKAGETYPE_GROUPID)); } } public function getProjectPackageTypesString($projectId) { $sql = 'SELECT DISTINCT ta.tag_fullname as name FROM tag_object t INNER JOIN tag ta on ta.tag_id = t.tag_id WHERE t.tag_group_id = :tag_group_id AND t.tag_parent_object_id = :project_id AND t.is_deleted = 0'; $resultSet = $this->getAdapter()->fetchAll($sql, array('tag_group_id' => $this::TAG_PACKAGETYPE_GROUPID,'project_id' => $projectId)); $resultString = ''; if (count($resultSet) > 0) { foreach ($resultSet as $item) { $resultString = $resultString . ' ' . stripslashes($item['name']) . ''; } return $resultString; } return ''; } public function getProjectPackageTypesPureStrings($projectId) { $sql = 'SELECT DISTINCT ta.tag_fullname as name FROM tag_object t INNER JOIN tag ta on ta.tag_id = t.tag_id WHERE t.tag_group_id = :tag_group_id AND t.tag_parent_object_id = :project_id AND t.is_deleted = 0'; $resultSet = $this->getAdapter()->fetchAll($sql, array('tag_group_id' => $this::TAG_PACKAGETYPE_GROUPID,'project_id' => $projectId)); $resultString = ''; if (count($resultSet) > 0) { foreach ($resultSet as $item) { $resultString = $resultString .' '. stripslashes($item['name']) ; } return $resultString; } return ''; } public function deleteFileTagsOnProject($projectId, $fileId) { $sql = "UPDATE tag_object inner join tag ON tag.tag_id = tag_object.tag_id set tag_changed = NOW() , is_deleted = 1 WHERE tag_type_id = :tag_type_id and tag_object.tag_object_id=:object_id and tag_object.tag_parent_object_id=:parent_object_id"; $this->getAdapter()->query($sql, array('tag_type_id' => $this::TAG_TYPE_FILE, 'object_id' => $fileId, 'parent_object_id' => $projectId)); } public function deletePackageTypeOnProject($projectId, $fileId) { $sql = "UPDATE tag_object inner join tag ON tag.tag_id = tag_object.tag_id set tag_changed = NOW() , is_deleted = 1 WHERE tag_group_id = :tag_group_id and tag_object.tag_object_id=:object_id and tag_object.tag_parent_object_id=:parent_object_id"; $this->getAdapter()->query($sql, array('tag_group_id' => $this::TAG_PACKAGETYPE_GROUPID, 'object_id' => $fileId, 'parent_object_id' => $projectId)); } public function deleteArchitectureOnProject($projectId, $fileId) { $sql = "UPDATE tag_object inner join tag ON tag.tag_id = tag_object.tag_id set tag_changed = NOW() , is_deleted = 1 WHERE tag_group_id = :tag_group_id and tag_object.tag_object_id=:object_id and tag_object.tag_parent_object_id=:parent_object_id"; $this->getAdapter()->query($sql, array('tag_group_id' => $this::TAG_ARCHITECTURE_GROUPID, 'object_id' => $fileId, 'parent_object_id' => $projectId)); } /** * @param int $projectId * @param int $fileId * @return string */ public function getPackageType($projectId, $fileId) { $sql = 'SELECT ta.tag_fullname as name FROM tag_object t INNER JOIN tag ta on ta.tag_id = t.tag_id WHERE t.tag_group_id = :tag_group_id AND t.tag_parent_object_id = :project_id AND t.tag_object_id = :file_id AND t.is_deleted = 0'; $resultSet = $this->getAdapter()->fetchAll($sql, array('tag_group_id' => $this::TAG_PACKAGETYPE_GROUPID,'project_id' => $projectId, 'file_id' => $fileId)); if (count($resultSet) > 0) { return $resultSet[0]['name']; } else { return ''; } } /** * @param int $projectId * @param int $fileId * @return string */ public function getFileTags($fileId) { $sql = 'SELECT ta.tag_id, ta.tag_fullname as name FROM tag_object t INNER JOIN tag ta on ta.tag_id = t.tag_id WHERE t.tag_type_id = :tag_type_id AND t.tag_object_id = :file_id AND t.is_deleted = 0'; $resultSet = $this->getAdapter()->fetchAll($sql, array('tag_type_id' => $this::TAG_TYPE_FILE,'file_id' => $fileId)); return $resultSet; } /** * @param int $projectId * @param int $fileId * @return string */ public function getTagsForFileAndTagGroup($projectId, $fileId, $tagGroup) { $sql = 'SELECT ta.tag_fullname as name FROM tag_object t INNER JOIN tag ta on ta.tag_id = t.tag_id WHERE t.tag_group_id = :tag_group_id AND t.tag_parent_object_id = :project_id AND t.tag_object_id = :file_id AND t.is_deleted = 0'; $resultSet = $this->getAdapter()->fetchAll($sql, array('tag_group_id' => $tagGroup,'project_id' => $projectId, 'file_id' => $fileId)); return $resultSet; } /** * @param int $object_id * * @return string|null */ public function getTagsEbookSubject($object_id) { $tag_group_ids =$this::TAG_PRODUCT_EBOOK_SUBJECT_GROUPID; $tags = $this->getTagsArray($object_id, $this::TAG_TYPE_PROJECT,$tag_group_ids); $tag_names = array(); foreach ($tags as $tag) { $tag_names[]=$tag['tag_fullname']; } return $tag_names; } /** * @param int $object_id * * @return string|null */ public function getTagsEbookAuthor($object_id) { $tag_group_ids =$this::TAG_PRODUCT_EBOOK_AUTHOR_GROUPID; $tags = $this->getTagsArray($object_id, $this::TAG_TYPE_PROJECT,$tag_group_ids); $tag_names = array(); foreach ($tags as $tag) { $tag_names[]=$tag['tag_fullname']; } return $tag_names; } /** * @param int $object_id * * @return string|null */ public function getTagsEbookEditor($object_id) { $tag_group_ids =$this::TAG_PRODUCT_EBOOK_EDITOR_GROUPID; $tags = $this->getTagsArray($object_id, $this::TAG_TYPE_PROJECT,$tag_group_ids); $tag_names = array(); foreach ($tags as $tag) { $tag_names[]=$tag['tag_fullname']; } return $tag_names; } /** * @param int $object_id * * @return string|null */ public function getTagsEbookIllustrator($object_id) { $tag_group_ids =$this::TAG_PRODUCT_EBOOK_ILLUSTRATOR_GROUPID; $tags = $this->getTagsArray($object_id, $this::TAG_TYPE_PROJECT,$tag_group_ids); $tag_names = array(); foreach ($tags as $tag) { $tag_names[]=$tag['tag_fullname']; } return $tag_names; } /** * @param int $object_id * * @return string|null */ public function getTagsEbookTranslator($object_id) { $tag_group_ids =$this::TAG_PRODUCT_EBOOK_TRANSLATOR_GROUPID; $tags = $this->getTagsArray($object_id, $this::TAG_TYPE_PROJECT,$tag_group_ids); $tag_names = array(); foreach ($tags as $tag) { $tag_names[]=$tag['tag_fullname']; } return $tag_names; } /** * @param int $object_id * * @return string|null */ public function getTagsEbookShelf($object_id) { $tag_group_ids =$this::TAG_PRODUCT_EBOOK_SHELF_GROUPID; $tags = $this->getTagsArray($object_id, $this::TAG_TYPE_PROJECT,$tag_group_ids); $tag_names = array(); foreach ($tags as $tag) { $tag_names[]=$tag['tag_fullname']; } return $tag_names; } /** * @param int $object_id * * @return string|null */ public function getTagsEbookLanguage($object_id) { $tag_group_ids =$this::TAG_PRODUCT_EBOOK_LANGUAGE_GROUPID; $tags = $this->getTagsArray($object_id, $this::TAG_TYPE_PROJECT,$tag_group_ids); $tag_names = array(); foreach ($tags as $tag) { $tag_names[]=$tag['tag_fullname']; } return $tag_names; } /** * @param int $object_id * * @return string|null */ public function getTagsEbookType($object_id) { $tag_group_ids =$this::TAG_PRODUCT_EBOOK_TYPE_GROUPID; $tags = $this->getTagsArray($object_id, $this::TAG_TYPE_PROJECT,$tag_group_ids); $tag_names = array(); foreach ($tags as $tag) { $tag_names[]=$tag['tag_fullname']; } return $tag_names; } } \ No newline at end of file diff --git a/application/modules/default/plugins/InitGlobalStoreVars.php b/application/modules/default/plugins/InitGlobalStoreVars.php index 49427cd44..e45963178 100644 --- a/application/modules/default/plugins/InitGlobalStoreVars.php +++ b/application/modules/default/plugins/InitGlobalStoreVars.php @@ -1,291 +1,302 @@ . **/ class Default_Plugin_InitGlobalStoreVars extends Zend_Controller_Plugin_Abstract { private static $exceptionThrown = false; /** * @param Zend_Controller_Request_Abstract $request * * @throws Zend_Exception */ public function preDispatch(Zend_Controller_Request_Abstract $request) { /** @var Zend_Controller_Request_Http $request */ parent::preDispatch($request); $storeHost = $this->getStoreHost($request); Zend_Registry::set('store_host', $storeHost); $storeConfigName = $this->getStoreConfigName($storeHost); Zend_Registry::set('store_config_name', $storeConfigName); Zend_Registry::set('store_template', $this->getStoreTemplate($storeConfigName)); $config_store = $this->getConfigStore($storeHost); Zend_Registry::set('store_config', $config_store); Zend_Registry::set('config_store_tags', $this->getConfigStoreTags($config_store->store_id)); + Zend_Registry::set('config_store_taggroups', $this->getConfigStoreTagGroups($config_store->store_id)); Zend_Registry::set('store_category_list', $this->getStoreCategories($storeHost)); } /** * @param Zend_Controller_Request_Http $request * * @return mixed * @throws Zend_Exception */ private function getStoreHost($request) { $storeHost = ''; $storeConfigArray = Zend_Registry::get('application_store_config_list'); // search for store id param $requestStoreConfigName = null; if ($request->getParam('domain_store_id')) { $requestStoreConfigName = $request->getParam('domain_store_id') ? preg_replace('/[^-a-zA-Z0-9_\.]/', '', $request->getParam('domain_store_id')) : null; $result = $this->searchForConfig($storeConfigArray, 'name', $requestStoreConfigName); if (isset($result['host'])) { $storeHost = $result['host']; return $storeHost; } } // search for host $httpHost = strtolower($request->getHttpHost()); if (isset($storeConfigArray[$httpHost])) { return $storeConfigArray[$httpHost]['host']; } // search for default $result = $this->searchForConfig($storeConfigArray, 'default', 1); $storeHost = $result['host']; return $storeHost; } /** * alternative version which replace arraySearchConfig for PHP < 5.5.0 * * @param $haystack * @param $key * @param $value * * @return array */ private function searchForConfig($haystack, $key, $value) { if (false === is_array($haystack)) { return array(); } foreach ($haystack as $element) { if (isset($element[$key]) and (strtolower($element[$key]) == strtolower($value))) { return $element; } } return array(); } /** * @param string $storeHostName * * @return string * @throws Zend_Exception */ private function getStoreConfigName($storeHostName) { $storeIdName = Zend_Registry::get('config')->settings->client->default->name; //set to default $store_config_list = Zend_Registry::get('application_store_config_list'); // search for host $httpHost = strtolower($storeHostName); if (isset($store_config_list[$httpHost])) { return $store_config_list[$httpHost]['config_id_name']; } else { Zend_Registry::get('logger')->warn(__METHOD__ . '(' . __LINE__ . ') - $httpHost = ' . $httpHost . ' :: no config id name configured') ; } // search for default $result = $this->searchForConfig($store_config_list, 'default', 1); if (isset($result['config_id_name'])) { $storeIdName = $result['config_id_name']; } else { Zend_Registry::get('logger')->warn(__METHOD__ . '(' . __LINE__ . ') - no default store config name configured'); } return $storeIdName; } /** * @param string $storeConfigName * * @return array|mixed * @throws Zend_Exception */ private function getStoreTemplate($storeConfigName) { $storeTemplate = array(); $fileNameConfig = APPLICATION_PATH . '/configs/client_' . $storeConfigName . '.ini.php'; if (file_exists($fileNameConfig)) { $storeTemplate = require APPLICATION_PATH . '/configs/client_' . $storeConfigName . '.ini.php'; } else { Zend_Registry::get('logger')->warn(__METHOD__ . ' - ' . $storeConfigName . ' :: can not access config file for store context.') ; $this->raiseException(__METHOD__ . ' - ' . $storeConfigName . ' :: can not access config file for store context'); } return $storeTemplate; } /** * @param $message */ private function raiseException($message) { if (self::$exceptionThrown) { return; } $request = $this->getRequest(); // Repoint the request to the default error handler $request->setModuleName('default'); $request->setControllerName('error'); $request->setActionName('error'); //$request->setDispatched(true); // Set up the error handler $error = new Zend_Controller_Plugin_ErrorHandler(); $error->type = Zend_Controller_Plugin_ErrorHandler::EXCEPTION_OTHER; $error->request = clone($request); $error->exception = new Zend_Exception($message); $request->setParam('error_handler', $error); //$this->setRequest($request); self::$exceptionThrown = true; } /** * @param string $storeHostName * * @return Default_Model_ConfigStore */ private function getConfigStore($storeHostName) { $storeConfig = new Default_Model_ConfigStore($storeHostName); return $storeConfig; } private function getConfigStoreTags($store_id) { $modelConfigStoreTags = new Default_Model_ConfigStoreTags(); $result = $modelConfigStoreTags->getTagsAsIdForStore($store_id); return $result; } + + + private function getConfigStoreTagGroups($store_id) + { + $modelConfigStoreTagGroups = new Default_Model_ConfigStoreTagGroups(); + + $result = $modelConfigStoreTagGroups->getTagGroupsAsIdForStore($store_id); + + return $result; + } /** * @param string $storeHostName * * @return array * @throws Zend_Exception */ private function getStoreCategories($storeHostName) { $storeCategoryArray = Zend_Registry::get('application_store_category_list'); //check store_category_list to see if some categories are defined here if (isset($storeCategoryArray[$storeHostName])) { $storeCategories = $storeCategoryArray[$storeHostName]; if (is_string($storeCategories)) { return array($storeCategories); } return $storeCategories; } Zend_Registry::get('logger')->warn(__METHOD__ . '(' . __LINE__ . ') - ' . $storeHostName . ' :: no categories for domain context configured. Try to use categories from default store instead') ; // next step: check store_category_list to see if some categories are defined for the default store $storeConfigArray = Zend_Registry::get('application_store_config_list'); $defaultStore = $this->arraySearchConfig($storeConfigArray, 'default', '1'); if (isset($storeCategoryArray[$defaultStore['host']])) { $storeCategories = $storeCategoryArray[$defaultStore['host']]; if (is_string($storeCategories)) { return array($storeCategories); } return $storeCategories; } Zend_Registry::get('logger')->warn(__METHOD__ . '(' . __LINE__ . ') - ' . $storeHostName . ' :: no categories for default store found. Try to use main categories instead') ; // last chance: take the main categories from the tree $modelCategories = new Default_Model_DbTable_ProjectCategory(); $root = $modelCategories->fetchRoot(); $storeCategories = $modelCategories->fetchImmediateChildrenIds($root['project_category_id'], $modelCategories::ORDERED_TITLE); return $storeCategories; } /** * needs PHP >= 5.5.0 * * @param $haystack * @param $key * @param $needle * * @return array */ private function arraySearchConfig($haystack, $column, $needle) { if (PHP_VERSION_ID <= 50500) { return $this->searchForConfig($haystack, $column, $needle); } if (false === is_array($haystack)) { return array(); } $key = array_search($needle, array_column($haystack, $column, 'host')); if ($key) { return $haystack[$key]; } return array(); } } \ 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 bf8cf9bd1..ccfea5717 100644 --- a/application/modules/default/views/scripts/explore/index.phtml +++ b/application/modules/default/views/scripts/explore/index.phtml @@ -1,271 +1,298 @@ . **/ $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(); }); '); diff --git a/httpdocs/theme/flatui/js/script.js b/httpdocs/theme/flatui/js/script.js index fed46e3da..71601cc67 100644 --- a/httpdocs/theme/flatui/js/script.js +++ b/httpdocs/theme/flatui/js/script.js @@ -1,2415 +1,2438 @@ /** * ocs-webserver * * Copyright 2016 by pling GmbH. * * This file is part of ocs-webserver. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . **/ var newProductPage = (function () { return { setup: function () { function adjustScrollableContentHeight() { var pling_box_height = $('#pling-it-box').height(); $('.scrollable-content').height(pling_box_height); $('.scrollable-content').jScrollPane({ mouseWheelSpeed: 30 }); } function adjustSupportersHeight() { var comments_height = $('#donations-panel').find('#comments').height(); var supporters_height = $('#donations-panel').find('#supporters').height(); if (comments_height > supporters_height) { $('#donations-panel').find('#supporters').height(comments_height); } } $(document).ready(function () { adjustScrollableContentHeight(); adjustSupportersHeight(); $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) { adjustSupportersHeight(); }); }); } } })(); // only instantiate when needed to instantiate: var ImagePreview = { hasError: false, setup: function () { this.initProductPicture(); this.initTitlePicture(); this.initProfilePicture(); this.initProfilePictureBackground(); }, previewImage: function (input, img_id) { if (input.files && input.files[0]) { var reader = new FileReader(); var image = new Image(); var file = input.files[0]; reader.readAsDataURL(input.files[0]); reader.onload = function (_image) { var image_element = $('#' + img_id); image.src = _image.target.result; // url.createObjectURL(file); image.onload = function () { var w = this.width, h = this.height, t = file.type, // ext only: // file.type.split('/')[1], n = file.name, s = ~~(file.size / 1024); // + 'KB' ImagePreview.hasError = false; image_element.parent().parent().find('div.bg-danger').remove(); if (w > 2000 || w < 20 || h > 2000 || h < 20) { //image_element.attr('src', '').hide().parent().append('
Wrong image dimensions
'); image_element.parent().parent().append('
Wrong image dimensions
'); //input.val(null); //$(input).replaceWith(input = $(input).clone(true)); $($(input).closest('form')[0]).trigger('reset'); ImagePreview.hasError = true; } if (s > 2000) { //image_element.attr('src', '').hide().parent().append('
File too large
'); image_element.parent().parent().append('
File too large
'); //input.val(null); //$(input).replaceWith(input = $(input).clone(true)); $($(input).closest('form')[0]).trigger('reset'); ImagePreview.hasError = true; } var allowedExtensions = /(jpg|jpeg|png|gif)$/i; if(!allowedExtensions.exec(t)) { image_element.parent().parent().append('
Invalid file type: ' + file.type + '
'); //input.val(null); //$(input).replaceWith(input = $(input).clone(true)); $($(input).closest('form')[0]).trigger('reset'); ImagePreview.hasError = true; } if (false == ImagePreview.hasError) { ImagePreview.hasError = false; image_element.attr('src', _image.target.result); image_element.show(); } }; image.onerror = function () { image_element.parent().parent().find('div.bg-danger').remove(); image_element.parent().parent().append('
Invalid file type: ' + file.type + '
'); }; //image_element.attr('src', _image.target.result); //image_element.show(); if (img_id == 'product-picture-preview') { $('button#add-product-picture').text('CHANGE LOGO'); } else if (img_id == 'title-picture-preview') { $('button#add-title-picture').text('CHANGE BANNER'); } else if (img_id == 'profile-picture-preview') { $('button#add-profile-picture').text('CHANGE PICTURE'); $('input#profile_img_src').val('local'); } else if (img_id == 'profile-picture-bg-preview') { $('button#add-profile-picture-background').text('CHANGE PICTURE'); } }; } }, previewImageMember: function (input, img_id) { if (input.files && input.files[0]) { var reader = new FileReader(); var image = new Image(); var file = input.files[0]; reader.readAsDataURL(input.files[0]); reader.onload = function (_image) { var image_element = $('#' + img_id); image.src = _image.target.result; // url.createObjectURL(file); image.onload = function () { ImagePreview.hasError = false; image_element.parent().find('.image-error').remove(); if (false == ImagePreview.hasError) { image_element.attr('src', _image.target.result); image_element.show(); } }; image.onerror = function () { image_element.parent().append('
Invalid file type
'); }; if (img_id == 'profile-picture-background-preview') { $('button#add-profile-picture-background').text('CHANGE PICTURE'); } }; } }, readImage: function (file) { var reader = new FileReader(); var image = new Image(); reader.readAsDataURL(file); reader.onload = function (_file) { image.src = _file.target.result; // url.createObjectURL(file); image.onload = function () { var w = this.width, h = this.height, t = file.type, // ext only: // file.type.split('/')[1], n = file.name, s = ~~(file.size / 1024) + 'KB'; $('#uploadPreview').append(' ' + w + 'x' + h + ' ' + s + ' ' + t + ' ' + n + '
'); }; image.onerror = function () { alert('Invalid file type: ' + file.type); }; }; }, initProductPicture: function () { if ($('#image_small').length == 0) { return; } if ($('#image_small').attr('value').length == 0) { return; } var imageTarget = $('#image_small').data('target'); $(imageTarget).attr('src', 'https://cn.opendesktop.org/cache/200x200-2/img/' + $('#image_small').attr('value')); $(imageTarget).show(); $('button#add-product-picture').text('CHANGE LOGO'); }, initTitlePicture: function () { if ($('#image_big').length == 0) { return; } if ($('#image_big').attr('value').length == 0) { return; } var imageTarget = $('#image_big').data('target'); $(imageTarget).attr('src', 'https://cn.opendesktop.org/cache/200x200-2/img/' + $('#image_big').attr('value')); $(imageTarget).show(); $('button#add-title-picture').text('CHANGE BANNER'); }, initProfilePicture: function () { if ($('#profile_image_url').length == 0) { return; } if ($('#profile_image_url').attr('value').length == 0) { return; } var imageTarget = $('#profile_image_url').data('target'); $(imageTarget).attr('src', $('#profile_image_url').attr('value')); $('#profile-picture').attr('src', $('#profile_image_url').attr('value')); $(imageTarget).show(); $('button#add-profile-picture').text('CHANGE PICTURE'); }, initProfilePictureBackground: function () { if ($('#profile_image_url_bg').length == 0) { return; } if ($('#profile_image_url_bg').attr('value').length == 0) { return; } var imageTarget = $('#profile_image_url_bg').data('target'); $(imageTarget).attr('src', $('#profile_image_url_bg').attr('value')); $('#profile-picture-background-preview').attr('src', $('#profile_image_url_bg').attr('value')); $(imageTarget).show(); $('button#add-profile-picture-background').text('CHANGE PICTURE'); } }; var MenuHover = (function () { return { setup: function () { $('body').on('click', 'a#login-dropdown', function (event) { event.stopPropagation(); $('.header-login-container').toggleClass('active'); }).on('click', '.header-login-container', function (event) { event.stopPropagation(); }).on('click', 'a.menu-trigger', function (event) { event.stopPropagation(); var html_menu_element = '.' + $(this).attr('rel'); $(html_menu_element).toggleClass('active'); }).on('mouseup', function (event) { var container = $('ul.profile-menu'); var trigger = $('li.profile-menu-container a.menu-trigger'); if (trigger.is(event.target)) { return; } if (!container.is(event.target) // if the target of the click isn't the container... && container.has(event.target).length === 0) // ... nor a descendant of the container { container.removeClass('active'); } }).on('mouseup', function (event) { container = $('div.header-login-container'); trigger = $('a#login-dropdown'); if (trigger.is(event.target)) { return; } if (!container.is(event.target) // if the target of the click isn't the container... && container.has(event.target).length === 0) // ... nor a descendant of the container { container.removeClass('active'); } }).click(function () { $('.header-login-container.active').removeClass('active'); $('.profile-menu.active').removeClass('active'); }); } }; })(); var ButtonCode = (function () { return { setup: function () { $('#button-code-heading').click(function () { if ($(this).hasClass('button-code-active')) { $(this).removeClass('button-code-active'); $(this).parent().find('.button-code').slideUp('fast'); $(this).parent().find('.button-code').css('border-bottom', 'none'); $(this).find('.icon-expand-code').css('background-image', 'url(img/icon-expand.png)'); } else { $(this).addClass('button-code-active'); $(this).parent().find('.button-code').css('border-bottom', '1px solid #bdc3c7'); $(this).parent().find('.button-code').slideDown('fast'); $(this).find('.icon-expand-code').css('background-image', 'url(img/icon-contract.png)'); } }) }, setupClipboardCopy: function (containerId) { $(containerId).on('mouseover', function () { $(this).off('mouseover'); $(this).find('[data-clipboard-target]').each(function () { var clipboardTarget = $($(this).attr('data-clipboard-target')); $(this).zclip({ path: '/theme/flatui/js/lib/ZeroClipboard.swf', copy: $.trim($(clipboardTarget).text()) }); }); }); } }; })(); var ProductPage = (function () { return { setup: function () { $(".dropdown-toggle").dropdown(); $('.scroll-pane').jScrollPane({ mouseWheelSpeed: 30, animateScroll: true }); $('.love-it').on('click', function () { this_img_src = $(this).find('img').attr('src'); if (!$(this).hasClass('no-login') && this_img_src != '/theme/flatui/img/icon-like-color.png') { $(this).prev('.share-it').trigger('click'); } }); $('.payment-options').find('.options').find('span.option').on('click', function () { var this_number = $(this).attr('title'); var number_input = $('.payment-options').find('input[type="number"]'); number_input.attr('value', this_number).val(this_number); number_input.focus(); $('.options').find('.selected').removeClass('selected'); $(this).addClass('selected'); }); }, setupPlingButton: function () { $('#pling-amount').on('focus', function () { $('#pling-amount').popover('destroy'); }); $('#pling-start').on('click', function (event) { validateElement = $('#pling-amount'); validateValue = validateElement.val(); if (validateValue == '' || (isNaN(parseFloat(validateValue)) || !isFinite(validateValue))) { event.preventDefault(); $('#pling-amount').popover({ placement: 'bottom', html: 'true', content: '
Donation must be a numeric value.
' }).popover('show'); return false; } minValue = validateElement.attr('min'); if (parseFloat(validateValue) < parseFloat(minValue)) { event.preventDefault(); $('#pling-amount').popover({ placement: 'bottom', html: 'true', content: '
Donation must be equal or greater than ' + minValue + '.
' }).popover('show'); return false; } maxValue = validateElement.attr('max'); if (parseFloat(validateValue) > parseFloat(maxValue)) { event.preventDefault(); $('#pling-amount').popover({ placement: 'bottom', html: 'true', content: '
Donation must be smaller or equal than ' + maxValue + '.
' }).popover('show'); return false; } }); function minmax(value, min, max) { if (parseInt(value) < 0 || isNaN(value)) return 0; else if (parseInt(value) > 100) return 100; else return value; } } } })(); var SlideShowRender = (function () { return { setup: function () { // add the active class to the first image $('#slideshow-container').find('img:first').addClass('active'); $('#slideshow-container').find('#navigation').find('a:first').addClass('active'); // trigger slideshow //SlideShow.setup(); } } })(); var ProductSlideShow = (function () { return { setup: function () { // arrows function $('#slideshow-container').find('#arrows').find('a').on('click', function (e) { var this_id = $(this).attr('id'); var slides = $('#slideshow-container #slides'); var current_img = slides.find('img.active'); var current_img_rel = current_img.attr('rel'); var current_nav_link = $('#slideshow-container').find('#navigation').find('a.active'); if (this_id == 'prev') { var prev_img_rel = parseInt(current_img_rel) - parseInt(1); var next_active_img = $('#slideshow-container').find('img[rel="' + prev_img_rel + '"]'); var next_active_nav_link = $('#slideshow-container').find('#navigation').find('a[rel="' + prev_img_rel + '"]'); if (!next_active_img.size() == 1) { var next_active_img = slides.find('img:last'); var next_active_nav_link = $('#slideshow-container').find('#navigation').find('a:last'); } } else if (this_id == 'next') { var next_img_rel = parseInt(current_img_rel) + parseInt(1); var next_active_img = $('#slideshow-container').find('img[rel="' + next_img_rel + '"]'); var next_active_nav_link = $('#slideshow-container').find('#navigation').find('a[rel="' + next_img_rel + '"]'); if (!next_active_img.size() == 1) { var next_active_img = slides.find('img:first'); var next_active_nav_link = $('#slideshow-container').find('#navigation').find('a:first'); } } current_img.removeClass('active'); current_nav_link.removeClass('active'); next_active_img.addClass('active'); next_active_nav_link.addClass('active'); //clearTimeout(slideShowInterval); //SlideShow.setup(); }); // navigation function $('#slideshow-container').find('#navigation').find('a').on('click', function () { var this_rel = $(this).attr('rel'); var this_image = $('#slideshow-container').find('img[rel="' + this_rel + '"]'); $('#slideshow-container').find('img.active').removeClass('active'); this_image.addClass('active'); $('#slideshow-container').find('#navigation').find('a.active').removeClass('active'); $(this).addClass('active'); }); } } })(); var SlideShow = (function () { return { setup: function () { slideShowInterval = setTimeout(function () { var current_img = $('#slideshow-container').find('img.active'); var current_img_rel = current_img.attr('rel'); var next_img_rel = parseInt(current_img_rel) + parseInt(1); var next_img = $('#slideshow-container').find('img[rel="' + next_img_rel + '"]'); var current_nav_link = $('#slideshow-container').find('#navigation').find('a.active'); current_img.removeClass('active'); current_nav_link.removeClass('active'); if (next_img.size() == 1) { next_img.addClass('active'); $('#slideshow-container').find('#navigation').find('a[rel="' + next_img_rel + '"]').addClass('active'); } else { $('#slideshow-container').find('img:first').addClass('active'); $('#slideshow-container').find('#navigation').find('a:first').addClass('active'); } //SlideShow.setup(); }, 4000); } } })(); var Popuppanel = (function () { return { setup: function () { $('body').on('click', 'a.popuppanel', function (event) { if ($(this).attr('target') === "_blank"){ console.log('dont prevent default'); } else { event.preventDefault(); var hf = $(this).attr('href'); $.fancybox({ 'hideOnContentClick': true, 'autoScale': true, 'cyclic': 'true', 'transitionIn': 'elastic', 'transitionOut': 'elastic', 'type': 'iframe', 'scrolling': 'auto', helpers: { overlay: { locked: false } }, autoSize: true, href: hf, type: 'ajax' }); } }); } } })(); var PlingsRedirect = (function () { return { setup: function () { if(window.location.hash) { $link = $(window.location.hash); $link.trigger("click"); } else if (document.location.hash) { $link = $(document.location.hash); $link.trigger("click"); } } } })(); var ShowPopups = (function () { return { setup: function () { if(window.location.hash) { alert('Hash'); $('a[href="' + document.location.hash + '"]').trigger("click"); } if (document.location.hash) { alert('Hash'); $('a[href="' + document.location.hash + '"]').trigger("click"); } } } })(); /** PRODUCT PAGE **/ // tool tips $('body').on('mouseenter', '.supporter-thumbnail', function () { $(this).popover('show'); }); $('body').on('mouseleave', '.supporter-thumbnail', function () { $(this).popover('hide'); }); var Partials = (function () { return { setup: function () { $('body').on('click', 'a.partial', function (event) { event.preventDefault(); var url = this.href; var target = $(this).attr("data-target"); var toggle = $(this).data('toggle'); var pageFragment = $(this).attr("data-fragment"); $(target).load(url + ' ' + pageFragment, function (response, status, xhr) { if (status == "error") { if (xhr.status == 401) { if (response) { var data = jQuery.parseJSON(response); var redirect = data.login_url; if (redirect) { window.location = redirect; } else { window.location = "/login"; } } } else { $(target).empty().html('Service is temporarily unavailable. Our engineers are working quickly to resolve this issue.
Find out why you may have encountered this error.'); } } if (toggle) { $(toggle).modal('show'); } }); return false; }); } } })(); var Opendownloadfile= (function () { return { setup: function () { $('body').on('click', 'a.opendownloadfile', function (event) { event.preventDefault(); var file_id = $(this).attr("data-file_id"); var file_type = $(this).attr('data-file_type'); var file_name = $(this).attr('data-file_name'); var file_size = $(this).attr('data-file_size'); var project_id = $(this).attr('data-project_id'); var link_type = $(this).attr('data-link_type'); $.fancybox({ 'hideOnContentClick': true, 'autoScale': true, 'scrolling' : 'no', 'cyclic': 'true', 'transitionIn': 'elastic', 'transitionOut': 'elastic', 'type': 'iframe', 'width':'300', 'height':'200', 'iframe': {'scrolling': 'no'}, 'autoSize':false, 'id': 'opendownloadfilepopup', helpers: { overlay: { locked: false } }, href:'/dl?file_id='+file_id+'&file_type='+file_type+'&file_name='+file_name+'&file_size='+file_size+'&project_id='+project_id+'&link_type='+link_type }); return false; }); } } })(); var PartialsButton = (function () { return { setup: function () { $('body').on('click', 'Button.partialbutton', function (event) { event.preventDefault(); var url = $(this).attr("data-href"); var target = $(this).attr("data-target"); var toggle = $(this).data('toggle'); var pageFragment = $(this).attr("data-fragment"); var spin = $(''); $(target).append(spin); $(target).load(url + ' ' + pageFragment, function (response, status, xhr) { if (status == "error") { if (xhr.status == 401) { if (response) { var data = jQuery.parseJSON(response); var redirect = data.login_url; if (redirect) { window.location = redirect; } else { window.location = "/login"; } } } else { $(target).empty().html('Service is temporarily unavailable. Our engineers are working quickly to resolve this issue.
Find out why you may have encountered this error.'); } } if (toggle) { $(toggle).modal('show'); } }); return false; }); } } })(); var PartialsButtonHeartDetail = (function () { return { setup: function () { $('body').on('click', '.partialbuttonfollowproject', function (event) { event.preventDefault(); var url = $(this).attr("data-href"); var target = $(this).attr("data-target"); var auth = $(this).attr("data-auth"); var toggle = $(this).data('toggle'); var pageFragment = $(this).attr("data-fragment"); if (!auth) { $('#like-product-modal').modal('show'); return; } // product owner not allow to heart copy from voting.... var loginuser = $('#like-product-modal').find('#loginuser').val(); var productcreator = $('#like-product-modal').find('#productcreator').val(); if (loginuser == productcreator) { // ignore $('#like-product-modal').find('#votelabel').text('Project owner not allowed'); $('#like-product-modal').find('.modal-body').empty(); $('#like-product-modal').modal('show'); return; } var spin = $(''); $(target).prepend(spin); $.ajax({ url: url, cache: false }) .done(function( response ) { $(target).find('.spinning').remove(); if(response.status =='error'){ $(target).html( response.msg ); }else{ if(response.action=='delete'){ //$(target).find('.likelabel').html(response.cnt +' Likes'); $(target).find('.plingtext').html(response.cnt); $(target).find('.plingtext').addClass('heartnumberpurple'); $(target).find('.plingheart').removeClass('heartproject').addClass('heartgrey'); $(target).find('.plingheart').removeClass('fa-heart').addClass('fa-heart-o'); }else{ //$(target).find('.likelabel').html(response.cnt +' Likes'); $(target).find('.plingtext').html(response.cnt); //$(target).find('.plingtext').html(response.cnt+' Fans'); $(target).find('.plingtext').removeClass('heartnumberpurple'); $(target).find('.plingheart').removeClass('heartgrey').addClass('heartproject'); $(target).find('.plingheart').removeClass('fa-heart-o').addClass('fa-heart'); } } }); return false; }); } } })(); var PartialsButtonPlingProject = (function () { return { setup: function () { $('#plingbtn').hover(function(){ $(this).attr('src','/images/system/pling-btn-hover.png'); }, function(){ $(this).attr('src',$(this).attr('data-src')); }); $('body').on('click', '.partialbuttonplingproject', function (event) { event.preventDefault(); var url = $(this).attr("data-href"); var target = $(this).attr("data-target"); var auth = $(this).attr("data-auth"); var issupporter = $(this).attr("data-issupporter"); var toggle = $(this).data('toggle'); var pageFragment = $(this).attr("data-fragment"); if (!auth) { $('#like-product-modal').modal('show'); return; } // product owner not allow to heart copy from voting.... var loginuser = $('#like-product-modal').find('#loginuser').val(); var productcreator = $('#like-product-modal').find('#productcreator').val(); if (loginuser == productcreator) { // ignore $('#like-product-modal').find('#votelabel').text('Project owner not allowed'); $('#like-product-modal').find('.modal-body').empty(); $('#like-product-modal').modal('show'); return; } if (!issupporter) { // ignore $('#like-product-modal').find('#votelabel').html('
To pling a product and help the artist please consider becoming a supporter. Thanks!

Become a supporter
'); $('#like-product-modal').modal('show'); return; } $(target).find('.plingnum').html(''); $.ajax({ url: url, cache: false }) .done(function( response ) { //$(target).find('.spinning').remove(); if(response.status =='error'){ $(target).html( response.msg ); }else{ if(response.action=='delete'){ //pling deleted if(response.cnt==0) { $(target).find('.plingnum').html('Pling me'); }else { $(target).find('.plingnum').html(response.cnt+ ' Plings'); } $(target).find('#plingbtn').attr('src','/images/system/pling-btn-normal.png'); $(target).find('#plingbtn').attr('data-src','/images/system/pling-btn-normal.png'); }else{ //pling inserted $(target).find('.plingnum').html(response.cnt+ ' Plings'); $(target).find('#plingbtn').attr('src','/images/system/pling-btn-active.png'); $(target).find('#plingbtn').attr('data-src','/images/system/pling-btn-active.png'); } } }); return false; }); } } })(); var PartialsReview = (function () { return { setup: function () { $('body').on('click', 'a.partialreview', function (event) { event.preventDefault(); var url = this.href; var target = $(this).attr("data-target"); var toggle = $(this).data('toggle'); var pageFragment = $(this).attr("data-fragment"); // product owner not allow to vote var loginuser = $('#review-product-modal').find('#loginuser').val(); var productcreator = $('#review-product-modal').find('#productcreator').val(); if (loginuser == productcreator) { // ignore $('#review-product-modal').find('#votelabel').text('Project owner not allowed'); $('#review-product-modal').find('.modal-body').empty(); $('#review-product-modal').modal('show'); return; } var userrate = $('#review-product-modal').find('#userrate').val(); // -1 = no rate yet. 0= dislike 1=like if ($(this).hasClass("voteup")) { if (userrate == 1) { $('#review-product-modal').find('#votelabel').empty() .append(' is given already with comment:'); $('#review-product-modal').find('#commenttext').val($('#review-product-modal').find('#otxt').val()); //$('#review-product-modal').find(':submit').attr("disabled", "disabled").css("display", "none"); //$('#review-product-modal').find('#commenttext').attr("disabled", "disabled"); $('#review-product-modal').find(':submit').text("Remove Rating"); } else { $('#review-product-modal').find('input#voteup').val(1); $('#review-product-modal').find('#votelabel').empty() .append(' Add Comment (min. 1 char):'); $('#review-product-modal').find('#commenttext').val('+'); $('#review-product-modal').find(':submit').text("Rate Now"); $('#review-product-modal').find('#commenttext').removeAttr("disabled"); $('#review-product-modal').find(':submit').css("display", "block").removeAttr("disabled"); } } else { // vote down if (userrate == 0) { $('#review-product-modal').find('#votelabel').empty() .append(' is given already with comment: '); $('#review-product-modal').find('#commenttext').val($('#review-product-modal').find('#otxt').val()); // $('#review-product-modal').find('#commenttext').attr("disabled", "disabled"); // $('#review-product-modal').find(':submit').attr("disabled", "disabled").css("display", "none"); $('#review-product-modal').find(':submit').text("Remove Rating"); } else { $('#review-product-modal').find('input#voteup').val(2); $('#review-product-modal').find('#votelabel').empty() .append(' Add Comment (min. 5 char) Please explain the reason for downvote to help the creator to make it better '); $('#review-product-modal').find('#commenttext').val('-'); $('#review-product-modal').find('#commenttext').removeAttr("disabled"); $('#review-product-modal').find(':submit').removeAttr("disabled").css("display", "block"); $('#review-product-modal').find(':submit').text("Rate Now"); } } $('#review-product-modal').modal('show'); if ($('#review-product-modal').hasClass('noid')) { setTimeout(function () { $('#review-product-modal').modal('hide'); }, 2000); } return false; }); } } })(); var PartialsReviewDownloadHistory = (function () { return { setup: function () { $('body').on('click', 'button.partialReviewDownloadHistory', function (event) { event.preventDefault(); var userrate = $(this).attr("data-userrate"); // -1 = no rate yet. 0= dislike 1=like $('#review-product-modal').find('#commenttext').val($(this).attr("data-comment")); $('#review-product-modal').find('#form_p').val($(this).attr("data-project")); if ($(this).hasClass("voteup")) { if (userrate == 1) { $('#review-product-modal').find('#votelabel').empty() .append(' is given already with comment:'); $('#review-product-modal').find(':submit').attr("disabled", "disabled").css("display", "none"); $('#review-product-modal').find('#commenttext').attr("disabled", "disabled"); } else { $('#review-product-modal').find('input#voteup').val(1); $('#review-product-modal').find('#votelabel').empty() .append(' Add Comment (min. 1 char):'); $('#review-product-modal').find('#commenttext').val('+'); $('#review-product-modal').find('#commenttext').removeAttr("disabled"); $('#review-product-modal').find(':submit').css("display", "block").removeAttr("disabled"); } } else { // vote down if (userrate == 0) { $('#review-product-modal').find('#votelabel').empty() .append(' is given already with comment: '); $('#review-product-modal').find('#commenttext').attr("disabled", "disabled"); $('#review-product-modal').find(':submit').attr("disabled", "disabled").css("display", "none"); } else { $('#review-product-modal').find('input#voteup').val(2); $('#review-product-modal').find('#votelabel').empty() .append(' Add Comment (min. 5 chars): '); $('#review-product-modal').find('#commenttext').val('-'); $('#review-product-modal').find('#commenttext').removeAttr("disabled"); $('#review-product-modal').find(':submit').removeAttr("disabled").css("display", "block"); } } $('#review-product-modal').modal('show'); if ($('#review-product-modal').hasClass('noid')) { setTimeout(function () { $('#review-product-modal').modal('hide'); }, 2000); } return false; }); } } })(); var PartialForms = (function () { return { setup: function () { $('body').on("submit", 'form.partial', function (event) { event.preventDefault(); event.stopImmediatePropagation(); $(this).find(':submit').attr("disabled", "disabled"); $(this).find(':submit').css("white-space", "normal"); var spin = $(''); $(this).find(':submit').append(spin); var target = $(this).attr("data-target"); var trigger = $(this).attr("data-trigger"); console.log(this); jQuery.ajax({ data: $(this).serialize(), url: this.action, type: this.method, error: function () { $(target).empty().html("Service is temporarily unavailable. Our engineers are working quickly to resolve this issue.
Find out why you may have encountered this error.
"); return false; }, success: function (results) { $(target).empty().html(results); $(target).find(trigger).trigger('click'); return false; } }); return false; }); } } })(); var PartialJson = (function () { return { setup: function () { $('body').on("submit", 'form.partialjson', function (event) { event.preventDefault(); event.stopImmediatePropagation(); var target = $(this).attr("data-target"); var trigger = $(this).attr("data-trigger"); jQuery.ajax({ data: $(this).serialize(), url: this.action, type: this.method, dataType: "json", error: function () { $(target).empty().html("Service is temporarily unavailable. Our engineers are working quickly to resolve this issue.
Find out why you may have encountered this error.
"); }, success: function (data, textStatus) { if (data.redirect) { // data.redirect contains the string URL to redirect to window.location = data.redirect; return; } if (target) { // data.message contains the HTML for the replacement form $(target).empty().html(data.message); } if (trigger) { $(target).find(trigger).trigger('click'); } } }); return false; }); } } })(); var PartialJsonFraud = (function () { return { setup: function () { $('body').on("submit", 'form.partialjsonfraud', function (event) { event.preventDefault(); event.stopImmediatePropagation(); var target = $(this).attr("data-target"); var trigger = $(this).attr("data-trigger"); var text = $('form.partialjsonfraud').find('#report-text').val(); if(text.length<5) { $('form.partialjsonfraud').find('p.warning').remove(); $('form.partialjsonfraud').find('#report-text').parent().append('

at least 5 chars

'); return false; } jQuery.ajax({ data: $(this).serialize(), url: this.action, type: this.method, dataType: "json", error: function () { $(target).empty().html("Service is temporarily unavailable. Our engineers are working quickly to resolve this issue.
Find out why you may have encountered this error.
"); }, success: function (data, textStatus) { if (data.redirect) { // data.redirect contains the string URL to redirect to window.location = data.redirect; return; } if (target) { // data.message contains the HTML for the replacement form $(target).empty().html(data.message); } if (trigger) { $(target).find(trigger).trigger('click'); } } }); return false; }); } } })(); var PartialPayPal = (function () { return { setup: function () { this.initPayPalForm(); this.initPayPalFee(); }, initPayPalForm: function () { $('body').on("submit", 'form.partialpaypal', function (event) { event.preventDefault(); event.stopImmediatePropagation(); var target = $(this).attr("data-target"); var trigger = $(this).attr("data-trigger"); jQuery.ajax({ data: $(this).serialize(), url: this.action, type: this.method, error: function (jqXHR, textStatus, errorThrown) { $('#modal-dialog').modal('hide'); var msgBox = $(''); msgBox.html($(jqXHR.responseText).filter('.page-container').children()); msgBox.append(''); setTimeout(function () { msgBox.modal('show'); }, 900); }, success: function (results) { $(target).empty().html(results); $(target).find(trigger).trigger('click'); $('#modal-dialog').modal('hide'); } }); return false; }); }, initPayPalFee: function () { $('body').on("change", '#amount_plings', function (event) { PartialPayPal.changeFee(); }); }, changeFee: function () { var e = document.getElementById('amount_plings'); var value = parseFloat(e.value); var pling_fee = this.round((value) * 0.05, 2); var pling_sum = (pling_fee) + (value); var paypal_fee = (pling_sum + 0.3) * 0.03 + 0.3; paypal_fee = this.round(paypal_fee, 2); var sum = value + pling_fee + paypal_fee; document.getElementById('pling_fee').value = this.round(pling_fee, 2).toFixed(2); document.getElementById('paypal_fee').value = this.round(paypal_fee, 2).toFixed(2); document.getElementById('sum').value = this.round(sum, 2); }, round: function (x, n) { var a = Math.pow(10, n); return (Math.round(x * a) / a); } } })(); var PartialCommentReviewForm = (function () { return { setup: function () { this.initForm(); }, initForm: function () { $('body').on("submit", 'form.product-add-comment-review', function (event) { event.preventDefault(); event.stopImmediatePropagation(); var c = $.trim($('#commenttext').val()); var v = $('#voteup').val(); if(v==2) { // votedown if(c.length<5) { if($('#review-product-modal').find('#votelabel').find('.warning').length==0) { $('#review-product-modal').find('#votelabel').append("
Please give a comment, thanks!"); } return; } } if(c.length<1) { if($('#review-product-modal').find('#votelabel').find('.warning').length==0) { $('#review-product-modal').find('#votelabel').append("
Please give a comment, thanks!"); } return; } $(this).find(':submit').attr("disabled", "disabled"); $(this).find(':submit').css("white-space", "normal"); var spin = $(''); $(this).find(':submit').append(spin); jQuery.ajax({ data: $(this).serialize(), url: this.action, type: this.method, error: function (jqXHR, textStatus, errorThrown) { $('#review-product-modal').modal('hide'); var msgBox = $('#generic-dialog'); msgBox.modal('hide'); msgBox.find('.modal-header-text').empty().append('Please try later.'); msgBox.find('.modal-body').empty().append("Service is temporarily unavailable. Our engineers are working quickly to resolve this issue.
Find out why you may have encountered this error.
"); setTimeout(function () { msgBox.modal('show'); }, 900); }, success: function (results) { $('#review-product-modal').modal('hide'); location.reload(); } }); return false; }); } } })(); var PartialFormsAjax = (function () { return { setup: function () { var form = $('form.partialajax'); var target = form.attr("data-target"); var trigger = form.attr("data-trigger"); $(form).find(':submit').on('click', function (e) { e.preventDefault(); $(form).find(':submit').attr("disabled", "disabled"); $(form).find(':submit').css("white-space", "normal"); var spin = $(''); $(form).find(':submit').append(spin); $(form).submit(); }); form.ajaxForm({ error: function () { $(target).empty().html("Service is temporarily unavailable. Our engineers are working quickly to resolve this issue.
Find out why you may have encountered this error.
"); }, success: function (results) { $(target).empty().html(results); $(target).find(trigger).trigger('click'); } }); } } })(); var AjaxFormWithProgress = (function () { return { setup: function (idForm) { var form = $(idForm); var target = form.attr("data-target"); var trigger = form.attr("data-trigger"); var bar = form.find('.progress-bar'); var percent = form.find('.progress-percent'); $(form).find(':submit').on('click', function (e) { e.preventDefault(); $(form).find(':submit').attr("disabled", "disabled"); $(form).find(':submit').css("white-space", "normal"); var spin = $(''); $(form).find(':submit').append(spin); $(form).submit(); }); form.ajaxForm({ beforeSend: function() { var percentVal = '0%'; bar.parent().removeClass('hidden'); bar.width(percentVal); percent.html(percentVal); }, uploadProgress: function(event, position, total, percentComplete) { var percentVal = percentComplete + '%'; bar.width(percentVal); percent.html(percentVal); }, error: function () { $(target).empty().html("Service is temporarily unavailable. Our engineers are working quickly to resolve this issue.
Find out why you may have encountered this error.
"); }, success: function (results) { var percentVal = '100%'; bar.width(percentVal); percent.html(percentVal); $(target).empty().html(results); $(target).find(trigger).trigger('click'); } }); } } })(); var PartialFormsAjaxMemberBg = (function () { return { setup: function () { var form = $('form.partialajaxbg'); var target = form.attr("data-target"); var trigger = form.attr("data-trigger"); $(form).find(':submit').on('click', function (e) { e.preventDefault(); $(form).find(':submit').attr("disabled", "disabled"); $(form).find(':submit').css("white-space", "normal"); var spin = $(''); $(form).find(':submit').append(spin); $(form).submit(); }); form.ajaxForm({ error: function () { $(target).empty().html("Service is temporarily unavailable. Our engineers are working quickly to resolve this issue.
Find out why you may have encountered this error.
"); }, success: function (results) { $(target).empty().html(results); $(target).find(trigger).trigger('click'); } }); } } })(); var AjaxForm = (function () { return { setup: function (idElement, idTargetElement) { var target = $(idTargetElement); $('body').on("submit", 'form.product-add-comment', function (event) { event.preventDefault(); event.stopImmediatePropagation(); $(this).find('button').attr("disabled", "disabled"); $(this).find('.glyphicon.glyphicon-send').removeClass('glyphicon-send').addClass('glyphicon-refresh spinning'); jQuery.ajax({ data: $(this).serialize(), url: this.action, type: this.method, dataType: "json", error: function (jqXHR, textStatus, errorThrown) { var results = JSON && JSON.parse(jqXHR.responseText) || $.parseJSON(jqXHR.responseText); var msgBox = $('#generic-dialog'); msgBox.modal('hide'); msgBox.find('.modal-header-text').empty().append(results.title); msgBox.find('.modal-body').empty().append(results.message); setTimeout(function () { msgBox.modal('show'); }, 900); }, success: function (results) { if (results.status == 'ok') { $(target).empty().html(results.data); } if (results.status == 'error') { if (results.message != '') { alert(results.message); } else { alert('Service is temporarily unavailable.'); } } } }); return false; }); } } })(); var WidgetModalAjax = (function () { return { setup: function () { $('.my-product-item').find('a.widget-button').on('click', function () { var this_rel = $(this).attr('rel'); var this_product_id = this_rel.split('product')[1]; var target = $('.modal-body#widget-code-' + this_rel); $.ajax({ url: '/widget/config/' + this_product_id, type: 'html', success: function (results) { target.prepend(results); angular.bootstrap(target, ['widgetApp']); } }); }); } } })(); var LoginContainer = (function () { return { update: function () { if (!Date.now) { Date.now = function () { return new Date().getTime(); } } var timestamp = Date.now() / 1000 | 0; var target = '#login_container'; var url = '/authorization/htmllogin?' + timestamp; $(target).load(url, function (response, status, xhr) { // nothing to do }); } } })(); var RssNews = (function () { return { setup: function () { var json_url = "https://blog.opendesktop.org/?json=1&callback=?"; $.getJSON(json_url, function (res) { var crss = ''; $.each(res.posts, function (i, item) { if (i >= 3) { return false; } var m = moment(item.date); crss += '
' + item.title + '
' + '' + m.format('MMM DD YYYY') + ''+ item.comments.length +' Comment'+(item.comments.length>1?'s':'') +'
'; }); $("#rss-feeds").html(crss); }); } } })(); var BlogJson = (function () { return { setup: function () { var urlforum = 'https://forum.opendesktop.org/'; var json_url =urlforum+'latest.json'; $.ajax(json_url).then(function (result) { var topics = result.topic_list.topics; var crss = ''; var count =3; topics.sort(function(a,b){ return new Date(b.last_posted_at) - new Date(a.last_posted_at); }); $.each(topics, function (i, item) { if(!item.pinned){ var m = moment(item.last_posted_at); var r = 'Reply'; var t = item.posts_count -1; if(t==0){ r = 'Replies'; }else if(t==1){ r = 'Reply'; }else{ r = 'Replies'; } crss += '
' + item.title + '
' + '' + m.fromNow() + ''+ t +' '+ r +'
'; count--; } if(count==0) return false; }); $("#blogJson").html(crss); }); } } })(); var GitlabNewProjectsJson = (function () { return { setup: function (url_git) { var json_url = url_git+'/api/v4/projects?order_by=created_at&sort=desc&visibility=public&page=1&per_page=5'; $.ajax(json_url).then(function (result) { var topics = result; var crss = ''; $.each(topics, function (i, item) { var m = moment(item.created_at); crss += ''; }); $("#lastgitprojects").html(crss); }); } } })(); function showGitUserAvatar(url_git,username, projectid) { var json_url = url_git+'/api/v4/users?username=' + username; $.ajax(json_url).then(function (result) { var usr_list = result; $.each(usr_list, function (i,usr) { $img = $('#avatar_' + username + '_' + projectid); //alert(usr); //alert($img.attr('src')); $img.attr('src',usr.avatar_url); //alert($img.attr('src')); }); }); } var ProductDetailCarousel = (function () { return { setup: function () { $('.carousel-inner img').each(function (index) { $(this).on("click", function () { if ($("#product-main-img-container").hasClass("imgfull")) { $('#product-main-img-container').prependTo($('#product-main')); } else { $('#product-main-img-container').prependTo($('#product-page-content')); } $("#product-main-img-container").toggleClass("imgfull"); $("#product-main-img-container").toggleClass("imgsmall"); }); }); } } })(); var AppimagequestionOnClick = (function () { return { setup: function (projectid) { $('body').on('click', 'i.appimagequestion', function (event) { var msgBox = $('#generic-dialog'); msgBox.modal('show'); msgBox.find('.modal-header-text').empty().append('AppImage Info'); msgBox.find('.modal-body').empty().append(""); }); } } })(); var ProductDetailBtnGetItClick = (function () { return { setup: function (projectid) { $('body').on('click', 'button#project_btn_download', function (event) { $.fancybox({ 'hideOnContentClick': true, 'autoScale': true, 'cyclic': 'true', 'transitionIn': 'elastic', 'transitionOut': 'elastic', 'type': 'ajax', helpers: { overlay: { locked: false } }, autoSize: true, href:'/p/'+projectid+'/ppload' }); }); } } })(); var GhnsExcludedClick = (function () { return { setup: function (projectid) { $('body').on('click', '#ghns_excluded-this-checkbox', function (event) { event.stopPropagation(); var status = 1; var title = ''; var btntxt = ''; if (this.checked) { status = 1; title = 'Please specify why this product should be excluded (min 5 chars) :'; btntxt=' ghns exclude'; } else { status = 0; title = 'Please specify why this product should be included (min 5 chars) :'; btntxt=' ghns include'; } var msgBox = $('#generic-dialog'); msgBox.modal('show'); msgBox.find('.modal-header-text').empty().append('GHNS '); msgBox.find('.modal-body').empty().append(title+ '

'); $('body').on("click", "#btn-ghns-excluded", function(){ var txt = $('#ghns-excluded-text').val(); if(txt.length<5) { alert('min 5 chars'); return false; } var project_id = $(this).attr('data-projectid'); var status = $(this).attr('data-status'); var target = "/backend/project/doghnsexclude"; $.ajax({ url: target, method:'POST', data:{'project_id':project_id,'ghns_excluded':status,'msg':txt}, success: function (results) { var msgBox = $('#generic-dialog'); if (status == 0) { msgBox.find('.modal-body').empty().append('Project is successfully included into GHNS'); $('#ghns_excluded-this-checkbox').prop("checked", false); } else { msgBox.find('.modal-body').empty().append('Project is successfully excluded into GHNS'); $('#ghns_excluded-this-checkbox').prop("checked", true); } setTimeout(function () { msgBox.modal('hide'); }, 1000); }, error: function () { alert('Service is temporarily unavailable.'); } }); }); return false; }); } } })(); var AboutMeMyProjectsPaging = (function () { return { setup: function () { $(window).scroll(function() { var end = $("footer").offset().top; var viewEnd = $(window).scrollTop() + $(window).height(); var distance = end - viewEnd; if (distance < 300){ // } // if($(window).scrollTop() == $(document).height() - $(window).height()) { if(!$('button#btnshowmoreproducts').length) return; let indicator = ''; let nextpage = $('button#btnshowmoreproducts').attr('data-page'); $('button#btnshowmoreproducts').remove(); $url = window.location.href; target = '#my-products-list'; let container = $('

').append(indicator).load($url,{projectpage:nextpage},function (response, status, xhr) { if (status == "error") { if (xhr.status == 401) { if (response) { var data = jQuery.parseJSON(response); var redirect = data.login_url; if (redirect) { window.location = redirect; } else { window.location = "/login"; } } } else { $(target).empty().html('Service is temporarily unavailable. Our engineers are working quickly to resolve this issue.
Find out why you may have encountered this error.'); } } }); $('#my-products-list').append(container); } }); } } })(); var AboutMeMyProjectsPagingButton = (function () { return { setup: function () { let indicator = ''; $('body').on('click', 'button#btnshowmoreproducts', function (event) { let nextpage = $(this).attr('data-page'); $(this).remove(); $url = window.location.href; target = '#my-products-list'; let container = $('
').append(indicator).load($url,{projectpage:nextpage},function (response, status, xhr) { if (status == "error") { if (xhr.status == 401) { if (response) { var data = jQuery.parseJSON(response); var redirect = data.login_url; if (redirect) { window.location = redirect; } else { window.location = "/login"; } } } else { $(target).empty().html('Service is temporarily unavailable. Our engineers are working quickly to resolve this issue.
Find out why you may have encountered this error.'); } } }); $('#my-products-list').append(container); }); } } })(); var ProductDetailCommentTooltip = (function () { return { setup: function () { TooltipUser.setup('tooltipuser','right'); } } })(); function generateTooltipster(elements,tooltipSide) { $(elements).each(function() { $(this).tooltipster( { side: tooltipSide, theme: ['tooltipster-light', 'tooltipster-light-customized'], contentCloning: true, contentAsHTML: true, interactive: true, functionBefore: function (instance, helper) { var origin = $(helper.origin); var userid = origin.attr('data-user'); if (origin.data('loaded') !== true) { $.get('/member/' + userid + '/tooltip/', function (data) { var d = data.data; var tmp = '
' + d.username + ' ' + d.countrycity + '
' + '
' + '
' + d.cntProjects + ' products
' + '
' + d.totalComments + ' comments
' + '
Likes ' + d.cntLikesGave + ' products
' + '
Got ' + d.cntLikesGot + ' Likes
' + '
Last time active : ' + d.lastactive_at + '
' + '
Member since : ' + d.created_at + '
' + '
'; tmp = tmp + '
'; instance.content(tmp); origin.data('loaded', true); }); } } } ); }); } var TooltipUser = (function () { return { setup: function (tooltipCls, tooltipSide) { $('.'+tooltipCls).tooltipster( { side: tooltipSide, theme: ['tooltipster-light', 'tooltipster-light-customized'], contentCloning: true, contentAsHTML: true, interactive: true, functionBefore: function (instance, helper) { var origin = $(helper.origin); var userid = origin.attr('data-user'); if (origin.data('loaded') !== true) { $.get('/member/' + userid + '/tooltip/', function (data) { var d = data.data; var tmp = '
' + d.username + ' ' + d.countrycity + '
' + '
' + '
' + d.cntProjects + ' products
' + '
' + d.totalComments + ' comments
' + '
Likes ' + d.cntLikesGave + ' products
' + '
Got ' + d.cntLikesGot + ' Likes
' + '
Last time active : ' + d.lastactive_at + '
' + '
Member since : ' + d.created_at + '
' + '
'; tmp = tmp + '
'; instance.content(tmp); origin.data('loaded', true); }); } } } ); } } })(); function generateTooltipUserPlings(elements,tooltipSide) { $(elements).each(function() { $(this).tooltipster( { side: tooltipSide, theme: ['tooltipster-light', 'tooltipster-light-customized'], contentCloning: true, contentAsHTML: true, interactive: true, functionBefore: function (instance, helper) { var origin = $(helper.origin); var userid = origin.attr('data-user'); if (origin.data('loaded') !== true) { $.get('/plings/tooltip/id/'+userid, function (data) { var tmp = '
'; $.each(data.data, function( index, value ) { if(index>10) return false; if(value.profile_image_url.indexOf('http')<0) { value.profile_image_url = "https://cn.opendesktop.org/cache/40x40-2/img/"+value.profile_image_url ; } if(value.profile_image_url.indexOf('.gif')>0) { value.profile_image_url = "https://cn.opendesktop.org/img/"+value.profile_image_url ; } tmp = tmp+'
'+value.username+'
'; }); tmp = tmp + '
'; instance.content(tmp); origin.data('loaded', true); }); } } } ); }); } var TooltipUserPlings = (function () { return { setup: function (tooltipCls, tooltipSide) { $('.'+tooltipCls).tooltipster( { side: tooltipSide, theme: ['tooltipster-light', 'tooltipster-light-customized'], contentCloning: true, contentAsHTML: true, interactive: true, functionBefore: function (instance, helper) { var origin = $(helper.origin); var userid = origin.attr('data-user'); if (origin.data('loaded') !== true) { $.get('/plings/tooltip/id/'+userid, function (data) { var tmp = '
'; $.each(data.data, function( index, value ) { if(index>10) return false; if(value.profile_image_url.indexOf('http')<0) { value.profile_image_url = "https://cn.opendesktop.org/cache/40x40-2/img/"+value.profile_image_url ; } if(value.profile_image_url.indexOf('.gif')>0) { value.profile_image_url = "https://cn.opendesktop.org/img/"+value.profile_image_url ; } tmp = tmp+'
'+value.username+'
'; }); tmp = tmp + '
'; instance.content(tmp); origin.data('loaded', true); }); } } } ); } } })(); var AboutMePage = (function () { return { setup: function (username) { var t = $(document).prop('title'); var tnew = username + "'s Profile " + t; $(document).prop('title', tnew); } } })(); var InitActiveHashTab = (function () { return { setup: function () { var activeTab = document.location.hash; if($('a[href="'+ activeTab +'"]')) { $('a[href="'+ activeTab +'"]').tab('show'); } } } })(); var CommunityTabToplistMemberScrollPaging= (function () { return { setup: function (paramEl,paramUrl) { $(window).scroll(function() { var end = $("footer").offset().top; var viewEnd = $(window).scrollTop() + $(window).height(); var distance = end - viewEnd; if (distance < 300){ if(!$('button#toplistmemberscrollshowmore').length) return; var indicator = ''; var nextpage = $('button#toplistmemberscrollshowmore').attr('data-page'); $('button#toplistmemberscrollshowmore').remove(); var pagingurl = paramUrl+"/nopage/1/page/"+nextpage; var $newdiv = $('
'); $(paramEl).find('.product-list').append($newdiv); $($newdiv).load(pagingurl,function (){ generateTooltipster($($newdiv).find('.tooltipuser'),"right"); }) } }); } } })(); var CommunityTab= (function () { return { setup: function () { var indicator = ''; $('body').on('click', 'a.communitytab', function (event) { event.preventDefault(); var el = $(this).attr('href'); var url = $(this).attr('data-href'); if($(el).find('.list').find('.user').length==0) { // only load once $(el).find('.list').append(indicator).load(url,function (){ generateTooltipster($(el).find('.tooltipuser'),"right"); if($(el).find('.tooltipuserplings').length>0) { generateTooltipUserPlings($(el).find('.tooltipuserplings'),"right"); } if(el=='#toplistMemberPanel') { CommunityTabToplistMemberScrollPaging.setup(el,url); } // paging let spans = $(el).find('.opendesktopwidgetpager span'); spans.each(function(index) { $(this).on("click", function(){ $(this).parent().addClass('active').siblings().removeClass('active'); var pagingurl = url+"/nopage/1/page/"+$(this).html(); $(el).find('.product-list').html(''); $(el).find('.product-list').load(pagingurl,function (){ generateTooltipster($(el).find('.tooltipuser'),"right"); if($(el).find('.tooltipuserplings').length>0) { generateTooltipUserPlings($(el).find('.tooltipuserplings'),"right"); }}) }); }); //end paging }); } }); var activeTab = document.location.hash; if($('a[href="'+ activeTab +'"]').length>0) { $('a[href="'+ activeTab +'"]').tab('show'); $('a[href="'+ activeTab +'"]').trigger( "click" ); }else { activeTab = "#supportersPanel"; $('a[href="'+ activeTab +'"]').trigger( "click" ); } $('body').on('mouseenter', '.product-thumbnail-startpage', function () { $(this).popover('show'); }); $('body').on('mouseleave', '.product-thumbnail-startpage', function () { $(this).popover('hide'); }); } } })(); var TagingProduct = (function () { return { setup: function () { $('input[name=tagsuser]') .tagify({ whitelist: ['good', 'great'], autocomplete:true }) .on('remove', function(e, tagName){ console.log('removed', tagName) }) .on('add', function(e, tagName){ console.log('added', tagName) }); } } })(); var TagingProductSelect2 = (function () { return { setup: function () { $.fn.select2.amd.require(['select2/selection/search'], function (Search) { Search.prototype.searchRemoveChoice = function (decorated, item) { this.trigger('unselect', { data: item }); this.$search.val(''); this.handleSearch(); }; }, null, true); var t = $(".taggingSelect2").select2({ placeholder: "Add Tags here ...", //placeholder tags: true, tokenSeparators: [",", " "], minimumInputLength: 3, maximumSelectionLength: 5, width: 'resolve', ajax: { url: '/tag/filter', dataType: 'json', type: "GET", delay: 500, // wait 250 milliseconds before triggering the request processResults: function (data) { return { results : data.data.tags }; } } }); // Bind an event t.on('select2:select', function (e) { var data = e.params.data; var projectid = $("#tagsuserselect").attr('data-pid'); var lis = t.parent().find('ul.select2-selection__rendered').find('li.select2-selection__choice').length; if(lis>5){ t.find("option[value='"+data.id+"']").remove(); return; } var regexp=new RegExp("^[0-9A-Za-z_.-]+$"); if(!(regexp.test(data.text))){ t.find("option[value='"+data.id+"']").remove(); alert('Must be letter or number and can include hyphens'); } if(data.text.length>10){ t.find("option[value='"+data.id+"']").remove(); alert('Max. length 45 chars'); } }); } } })(); var TagingProductDetail = (function () { return { setup: function () { TagingProductDetailSelect2.setup(); $('body').on('click', 'button.topic-tags-btn', function (event) { $(this).toggleClass('Done'); $('.product_category').find('.usertagslabel').remove(); $('.tagsuserselectpanel').toggle(); if($(this).text() == 'Done'){ $(this).text('Manage tags'); var newhtml = ''; var lis = $('li.select2-selection__choice'); $.each(lis, function( index, value ) { newhtml=newhtml+''+value.title+''; }); $('.product_category').find('.topicslink').html(newhtml); }else{ $(this).text('Done'); } }); } } })(); var TagingProductDetailSelect2 = (function () { return { setup: function () { $.fn.select2.amd.require(['select2/selection/search'], function (Search) { Search.prototype.searchRemoveChoice = function (decorated, item) { this.trigger('unselect', { data: item }); this.$search.val(''); this.handleSearch(); }; }, null, true); var t = $("#tagsuserselect").select2({ placeholder: "Input tags please...", //placeholder tags: true, minimumInputLength: 3, closeOnSelect:true, maximumSelectionLength: 5, tokenSeparators: [",", " "], ajax: { url: '/tag/filter', dataType: 'json', type: "GET", delay: 500, // wait 250 milliseconds before triggering the request processResults: function (data) { return { results : data.data.tags }; } } }); // Bind an event t.on('select2:select', function (e) { var data = e.params.data; var projectid = $("#tagsuserselect").attr('data-pid'); $.post( "/tag/add", { p: projectid, t: data.id }) .done(function( data ) { if(data.status=='error'){ $('span.topic-tags-saved').css({ color: "red" }).html(data.message).show().delay(2000).fadeOut(); t.find("option[value='"+data.data.tag+"']").last().remove(); //t.find("option[value="+data.data.tag+"]").last().remove(); } else { $('span.topic-tags-saved').css({ color: "green" }).html(' Saved').show().delay(1000).fadeOut(); } }); }); // Unbind the event t.on('select2:unselect', function(e){ var data = e.params.data; var projectid = $("#tagsuserselect").attr('data-pid'); $.post( "/tag/del", { p: projectid, t: data.id }) .done(function( data ) { console.log(data); $('span.topic-tags-saved').css({ color: "green" }).html(''+data.message).show().delay(1000).fadeOut(); //$('span.topic-tags-saved').show().delay(1000).fadeOut(); }); }); } } })(); var TagingLoopMyProducts = (function () { return { setup: function () { TagingLoopMyProductsSelect2.setup(); $('body').on('click', 'button.topic-tags-btn', function (event) { $(this).toggleClass('Done'); $(this).parent().find('.topicsuser').html(''); $(this).parent().find('.tagsuserselectpanel').toggle(); if($(this).text() == 'Done'){ $(this).text('Manage tags'); var newhtml = ''; var lis = $(this).parent().find('li.select2-selection__choice'); $.each(lis, function( index, value ) { newhtml=newhtml+''+value.title+''; }); $(this).parent().find('.topicsuser').html(newhtml); }else{ $(this).text('Done'); } }); } } })(); var TagingLoopMyProductsSelect2 = (function () { return { setup: function () { $.fn.select2.amd.require(['select2/selection/search'], function (Search) { Search.prototype.searchRemoveChoice = function (decorated, item) { this.trigger('unselect', { data: item }); this.$search.val(''); this.handleSearch(); }; }, null, true); //var t = $("#tagsuserselect").select2({ var t = $(".taggingSelect2").select2({ placeholder: "Input tags please...", //placeholder tags: true, minimumInputLength: 3, closeOnSelect:true, maximumSelectionLength: 5, tokenSeparators: [",", " "], ajax: { url: '/tag/filter', dataType: 'json', type: "GET", delay: 500, // wait 250 milliseconds before triggering the request processResults: function (data) { return { results : data.data.tags }; } } }); // Bind an event t.on('select2:select', function (e) { var data = e.params.data; var projectid = $(this).attr('id').replace('tagsuserselect',''); //var projectid = $("#tagsuserselect").attr('data-pid'); $.post( "/tag/add", { p: projectid, t: data.id }) .done(function( data ) { if(data.status=='error'){ $('#topic-tags-saved'+projectid).css({ color: "red" }).html(data.message).show().delay(2000).fadeOut(); t.find("option[value='"+data.data.tag+"']").last().remove(); }else if(data.status=='existing'){ $('#topic-tags-saved'+projectid).css({ color: "red" }).html(data.message).show().delay(2000).fadeOut(); } else { $('#topic-tags-saved'+projectid).css({ color: "green" }).html(' Saved').show().delay(1000).fadeOut(); } }); }); // Unbind the event t.on('select2:unselect', function(e){ var data = e.params.data; //var projectid = $("#tagsuserselect").attr('data-pid'); var projectid = $(this).attr('id').replace('tagsuserselect',''); $.post( "/tag/del", { p: projectid, t: data.id }) .done(function( data ) { $('#topic-tags-saved'+projectid).css({ color: "green" }).html(''+data.message).show().delay(1000).fadeOut(); }); }); } } })(); var productRatingToggle = (function () { return { setup: function () { $('#showRatingAll').on('click', function () { $('#ratings-panel').find('.spinning').show(); setTimeout(function () { $('#ratings-panel').find('.spinning').hide(); }, 500); $('.btnRateFilter').removeClass('activeRating'); $(this).addClass('activeRating'); $('.productRating-rows').show(); $('.productRating-rows-inactive').show(); }); $('#showRatingActive').on('click', function () { $('#ratings-panel').find('.spinning').show(); setTimeout(function () { $('#ratings-panel').find('.spinning').hide(); }, 500); $('.btnRateFilter').removeClass('activeRating'); $(this).addClass('activeRating'); $('.productRating-rows').show(); $('.productRating-rows-inactive').hide(); }); $('#showRatingUpvotes').on('click', function () { $('#ratings-panel').find('.spinning').show(); setTimeout(function () { $('#ratings-panel').find('.spinning').hide(); }, 500); $('.btnRateFilter').removeClass('activeRating'); $(this).addClass('activeRating'); $('.productRating-rows').show(); $('.clsDownvotes').hide(); $('.productRating-rows-inactive').hide(); }); $('#showRatingDownvotes').on('click', function () { $('#ratings-panel').find('.spinning').show(); setTimeout(function () { $('#ratings-panel').find('.spinning').hide(); }, 500); $('.btnRateFilter').removeClass('activeRating'); $(this).addClass('activeRating'); $('.productRating-rows').show(); $('.productRating-rows-inactive').hide(); $('.clsUpvotes').hide(); }); } } })(); var FilterBrowseOriginalFn= (function () { - return { - setup: function () { - $('body').on('click', 'input#filter_browse_original', function (event) { - var checked = $(this).is( ":checked" ); - var url = window.location.href; - if(url.indexOf("browse")<0) - { - url = url+'/browse/'; - } - if(url.indexOf("filteroriginal")>0) - { - url = url.substring(0,url.indexOf("filteroriginal")); - } - if(checked){ - window.location.href = url+'filteroriginal/1'; - }else{ - window.location.href = url+'filteroriginal/0'; - } - }); + return { + setup: function () { + $('body').on('click', 'input#filter_browse_original', function (event) { + var checked = $(this).is( ":checked" ); + var url = window.location.href; + if(url.indexOf("browse")<0) + { + url = url+'/browse/'; } - } + if(url.indexOf("filteroriginal")>0) + { + url = url.substring(0,url.indexOf("filteroriginal")); + } + if(checked){ + window.location.href = url+'filteroriginal/1'; + }else{ + window.location.href = url+'filteroriginal/0'; + } + }); + } + } +})(); + + +var FilterBrowseTagGroupFn= (function () { + return { + setup: function () { + $('body').on('change', 'select.filter_browse_tag_group', function (event) { + var filterVal = $(this).val(); + var groupId = $(this).attr('data_group_id'); + + $.ajax({ + url: '/explore/savetaggroupfilter?group_id='+groupId+'&tag_id='+filterVal, + cache: false + }) + .done(function( response ) { + var url = window.location.href; + window.location.href = url; + }); + + + }); + } + } })(); diff --git a/sql_code/20190219_config_store_tag_group.sql b/sql_code/20190219_config_store_tag_group.sql new file mode 100644 index 000000000..221c6b4a1 --- /dev/null +++ b/sql_code/20190219_config_store_tag_group.sql @@ -0,0 +1,13 @@ +CREATE TABLE `config_store_tag_group` ( + `config_store_taggroup_id` INT(11) NOT NULL AUTO_INCREMENT, + `store_id` INT(11) NOT NULL, + `tag_group_id` INT(11) NOT NULL, + `is_active` INT(1) UNSIGNED NOT NULL DEFAULT '1', + `created_at` DATETIME NULL DEFAULT NULL, + `changed_at` DATETIME NULL DEFAULT NULL, + `deleted_at` DATETIME NULL DEFAULT NULL, + PRIMARY KEY (`config_store_taggroup_id`) +) +COLLATE='latin1_swedish_ci' +ENGINE=InnoDB +;