function getrecentcontentAction() { // Get requests $offset = isset($this->params['offset']) ? $this->params['offset'] : 0; $contentType = isset($this->params['type']) ? $this->params['type'] : 'all'; // Get models $contentModel = new Default_Model_Content(); $contentHasTagModel = new Default_Model_ContentHasTag(); // Get recent post data $recentposts_raw = $contentModel->listRecent($contentType, $offset, 15, 'created', $this->view->language, -1); $recentposts = array(); // Gather data for recent posts $i = 0; foreach ($recentposts_raw as $post) { $tags = $contentHasTagModel->getContentTags($post['id_cnt']); $this->gtranslate->setLangFrom($post['language_cnt']); $translang = $this->gtranslate->getLangPair(); $recentposts[$i]['original'] = $post; $recentposts[$i]['translated'] = $this->gtranslate->translateContent($post); $recentposts[$i]['original']['tags'] = $tags; $recentposts[$i]['translated']['tags'] = $tags; $recentposts[$i]['original']['translang'] = $translang; $recentposts[$i]['translated']['translang'] = $translang; $i++; } $this->view->recentposts = $recentposts; }
/** * listAction * * Lists content by content type. * */ public function listAction() { $url = $this->_urlHelper->url(array('controller' => 'index', 'language' => $this->view->language), 'lang_default', true); // Get cache from registry $cache = Zend_Registry::get('cache'); // Set array for content data $data = array(); // Get requests $params = $this->getRequest()->getParams(); // Get content type $cty = isset($params['type']) ? $params['type'] : 'all'; if ($cty != "idea" && $cty != "finfo" && $cty != "problem") { $this->_redirect($url); } // Get page nummber and items per page $page = isset($params['page']) ? $params['page'] : 1; $count = isset($params['count']) ? $params['count'] : 15; // Get list oreder value $order = isset($params['order']) ? $params['order'] : 'created'; $ind = isset($params['ind']) ? $params['ind'] : 0; // Get current language id // $languages = new Default_Model_Languages(); // $idLngInd = $languages->getLangIdByLangName($this->view->language); // Get recent content by type $contentModel = new Default_Model_Content(); $data = $contentModel->listRecent($cty, $page, $count, $order, $this->view->language, $ind); $results = array(); // gather other content data and insert to results array if (isset($data[0])) { $contentHasTagModel = new Default_Model_ContentHasTag(); // $contentRatingsModel = new Default_Model_ContentRatings(); $i = 0; foreach ($data as $content) { $results[$i] = $content; $results[$i]['tags'] = $contentHasTagModel->getContentTags($content['id_cnt']); //$results[$i]['ratingdata'] = $contentRatingsModel // ->getPercentagesById($content['id_cnt']); $i++; } } // Get total content count $contentCount = $contentModel->getContentCountByContentType($cty, $this->view->language); // Calculate total page count $pageCount = ceil($contentCount / $count); // Most viewed content $mostViewedData = $contentModel->getMostViewedType($cty, $page, $count, 'views', 'en', $ind); // Get all industries //$industries = new Default_Model_Industries(); //$this->view->industries = $industries->getNamesAndIdsById($ind, $idLngInd); // Get industry data by id //$this->view->industryParent = $industries->getById($ind); // Load most popular tags from cache if (!($result = $cache->load('IndexTags'))) { $tagsModel = new Default_Model_Tags(); $tags = $tagsModel->getPopular(20); /* // resize tags foreach ($tags as $k => $tag) { $size = round(50 + ($tag['count'] * 30)); if ($size > 300) { $size = 300; } $tags[$k]['tag_size'] = $size; } */ // Action helper for tags $tags = $this->_helper->tagsizes->popularTagCalc($tags); //Action helper for define is tag running number divisible by two $tags = $this->_helper->tagsizes->isTagDivisibleByTwo($tags); // Save most popular tags data to cache $cache->save($tags, 'IndexTags'); } else { $tags = $result; } // Custom pagination to fix memory error on large amount of data /* $paginator = new Zend_View(); $paginator->setScriptPath('../application/views/scripts'); $paginator->pageCount = $pageCount; $paginator->currentPage = $page; $paginator->pagesInRange = 10; */ // Send to view $this->view->tags = $tags; //$this->view->contentPaginator = $paginator; $this->view->contentData = $results; $this->view->type = $cty; $this->view->count = $count; $this->view->page = $page; $this->view->contentCount = $contentCount; $this->view->ind = $ind; $this->view->mostViewedData = $mostViewedData; // RSS type for the layout $this->view->rsstype = $cty; }
/** * Show mainpage and list newest and most viewed ideas and problems */ function indexAction() { // Variable for number recent campaigns to be sent to view $recentCampaignsCount = 0; $this->view->title = "index-home"; // Get cache from registry $cache = Zend_Registry::get('cache'); // $contentTypesModel = new Default_Model_ContentTypes(); // $userModel = new Default_Model_User(); // Load recent posts from cache $cachePosts = 'IndexPosts_' . $this->view->language; if (!($result = $cache->load($cachePosts))) { $contentModel = new Default_Model_Content(); $contentHasTagModel = new Default_Model_ContentHasTag(); // get data //($cty = 'all', $page = 1, $count = -1, $order = 'created', $lang = 'en', $ind = 0) $recentposts_raw = $contentModel->listRecent('all', 12, -1, 'created', $this->view->language, -1); $recentposts = array(); $i = 0; // gather data for recent posts foreach ($recentposts_raw as $post) { $recentposts[$i] = $post; $recentposts[$i]['tags'] = $contentHasTagModel->getContentTags($post['id_cnt']); $i++; } // Save recent posts data to cache $cache->save($recentposts, $cachePosts); } else { $recentposts = $result; } // Load most popular tags from cache if (!($result = $cache->load('IndexTags'))) { $tagsModel = new Default_Model_Tags(); $tags = $tagsModel->getPopular(20); /* // resize tags foreach ($tags as $k => $tag) { $size = round(50 + ($tag['count'] * 30)); if ($size > 300) { $size = 300; } $tags[$k]['tag_size'] = $size; } */ // Action helper for tags $tags = $this->_helper->tagsizes->popularTagCalc($tags); // Action helper for define is tag running number divisible by two $tags = $this->_helper->tagsizes->isTagDivisibleByTwo($tags); // Save most popular tags data to cache $cache->save($tags, 'IndexTags'); } else { $tags = $result; } // Laod most active users from cache if (!($result = $cache->load('IndexUsers'))) { $contentHasUserModel = new Default_Model_ContentHasUser(); $activeusers = $contentHasUserModel->getMostActive(5); // Save most active users data to cache $cache->save($activeusers, 'IndexUsers'); } else { $activeusers = $result; } // inject data to view if (isset($recentposts)) { $this->view->recentposts = $recentposts; } else { $this->view->recentposts = ''; } // Get recent campaigns $grpmodel = new Default_Model_Groups(); $campaignModel = new Default_Model_Campaigns(); $recentcampaigns = $campaignModel->getRecent(5); // If you find (time to think of) a better way to do this, be my guest. $cmps_new = array(); foreach ($recentcampaigns as $cmp) { $grp = $grpmodel->getGroupData($cmp['id_grp_cmp']); $cmp['group_name_grp'] = $grp['group_name_grp']; $cmps_new[] = $cmp; } // Get recent groups $grps = $grpmodel->getRecent(5); $grps_new = array(); $grpadm = new Default_Model_GroupAdmins(); foreach ($grps as $grp) { $adm = $grpadm->getGroupAdmins($grp['id_grp']); $grp['id_admin'] = $adm[0]['id_usr']; $grp['login_name_admin'] = $adm[0]['login_name_usr']; $grps_new[] = $grp; } $this->view->campaigns = $cmps_new; $this->view->groups = $grps_new; $this->view->poptags = $tags; $this->view->activeusers = $activeusers; $this->view->isLoggedIn = Zend_Auth::getInstance()->hasIdentity(); $this->view->recentCampaignsCount = $recentCampaignsCount; }
/** * generateAction * * Generate RSS feeds * * @param type string (optional) Content type ('problem' / 'finfo' / 'idea' / 'all'), 'all' by default * @param count integer (optional) How many items to generate * */ public function generateAction() { // Set an empty layout for view $this->_helper->layout()->setLayout('empty'); // Set custom RSS cache (lifetime 10 minutes) $cacheFrontend = array('lifetime' => 600, 'automatic_serialization' => true); $cacheBackend = array('cache_dir' => '../tmp/'); $cache = Zend_Cache::factory('core', 'File', $cacheFrontend, $cacheBackend); // Make baseurl absolute URL $absoluteBaseUrl = strtolower(trim(array_shift(explode('/', $_SERVER['SERVER_PROTOCOL'])))) . '://' . $_SERVER['HTTP_HOST'] . Zend_Controller_Front::getInstance()->getBaseUrl(); $this->view->absoluteBaseUrl = $absoluteBaseUrl; // Get parameters $params = $this->getRequest()->getParams(); // Get content type $cty = isset($params['type']) ? $params['type'] : 'all'; // Get number of items $count = isset($params['count']) ? $params['count'] : 10; // Set array for content data $data = array(); // Get recent content by type $content = new Default_Model_Content(); $data = $content->listRecent($cty, 1, $count, null, $this->view->language, null); // Set to view $this->view->cache = $cache; $this->view->cacheIdentifier = 'RSS_' . md5($cty . $count); $this->view->contentData = $data; }