public function indexAction() { $grpmodel = new Default_Model_Groups(); $cmpmodel = new Default_Model_Campaigns(); $grpadm = new Default_Model_GroupAdmins(); // If you find a better way to do this, be my guest. $cmps = $cmpmodel->getRecent(15); $cmps_new = array(); foreach ($cmps as $cmp) { $grp = $grpmodel->getGroupData($cmp['id_grp_cmp']); $cmp['group_name_grp'] = $grp['group_name_grp']; $cmps_new[] = $cmp; } // See previous comment. $grps = $grpmodel->getRecent(12); $grps_new = array(); 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; }
function getrecentcampaignsAction() { $offset = isset($this->params['offset']) ? $this->params['offset'] : 0; $status = isset($this->params['status']) ? $this->params['status'] : 'active'; $grpmodel = new Default_Model_Groups(); $campaignModel = new Default_Model_Campaigns(); // If you find (time to think of) a better way to do this, be my guest. if ($status === 'forthcoming') { $recentcampaigns = $campaignModel->getRecentForthcomingFromOffset($offset, 10); } else { if ($status === 'ended') { $recentcampaigns = $campaignModel->getRecentEndedFromOffset($offset, 10); } else { $recentcampaigns = $campaignModel->getRecentFromOffset($offset, 10); } } $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; } $this->view->recentcampaigns = $cmps_new; }
private function getGroupTitle() { $grpModel = new Default_Model_Groups(); $grp = $grpModel->getGroupData($this->id); return $grp['group_name_grp']; }
/** * viewAction * * Show the campaign view page */ public function viewAction() { $auth = Zend_Auth::getInstance(); $user = $auth->getIdentity(); $cmpid = $this->_request->getParam('cmpid'); $cmpmodel = new Default_Model_Campaigns(); // Check if campaign exists if (!isset($cmpid) || !$cmpmodel->campaignExists($cmpid)) { $target = $this->_urlHelper->url(array('controller' => 'campaign', 'action' => 'index', 'language' => $this->view->language), 'lang_default', true); $this->_redirector->gotoUrl($target); } // Get campaign & its contents. $cmp = $cmpmodel->getCampaignById($cmpid)->toArray(); $cmp['ingress_cmp'] = str_replace("\n", '<br>', $cmp['ingress_cmp']); $cmp['description_cmp'] = str_replace("\n", '<br>', $cmp['description_cmp']); $cnts = $cmpmodel->getAllContentsInCampaign($cmpid); // If user has identity if ($auth->hasIdentity()) { $this->view->identity = true; $uhgModel = new Default_Model_UserHasGroup(); $this->view->userHasGroup = $uhgModel->userHasGroup($cmp['id_grp_cmp'], $user->user_id); // Get group admins. $grpAdminsModel = new Default_Model_GroupAdmins(); $grpAdmins = $grpAdminsModel->getGroupAdmins($cmp['id_grp_cmp']); $this->view->userIsGroupAdmin = $this->checkIfArrayHasKeyWithValue($grpAdmins, 'id_usr', $user->user_id); } else { $this->view->identity = false; } // Campaign weblinks $campaignWeblinksModel = new Default_Model_CampaignWeblinks(); $cmp['campaignWeblinks'] = $campaignWeblinksModel->getCampaignWeblinks($cmpid); $i = 0; foreach ($cmp['campaignWeblinks'] as $weblink) { if (strlen($weblink['name_cwl']) == 0 || strlen($weblink['url_cwl']) == 0) { unset($cmp['campaignWeblinks'][$i]); } $i++; } // Get group info. $grpmodel = new Default_Model_Groups(); $grp = $grpmodel->getGroupData($cmp['id_grp_cmp']); $grpname = $grp['group_name_grp']; // Get campaign campaigns $cmpHasCmpModel = new Default_Model_CampaignHasCampaign(); $linkedcampaigns = $cmpHasCmpModel->getCampaignCampaigns($cmpid); $linkedcampaigns = array_merge($linkedcampaigns['parents'], $linkedcampaigns['childs']); // Get files $filesModel = new Default_Model_Files(); $files = $filesModel->getFilenames($cmpid, "campaign"); $comments = new Oibs_Controller_Plugin_Comments("campaign", $cmpid); if ($this->view->identity) { $comments->allowComments(true); } $this->view->jsmetabox->append('commentUrls', $comments->getUrls()); $comments->loadComments(); $this->view->hasFeeds = Oibs_Controller_Plugin_RssReader::hasFeeds($cmpid, "campaign"); $this->view->comments = $comments; $this->view->campaign = $cmp; $this->view->cmpcnts = $cnts; $this->view->grpname = $grpname; $this->view->linkedcampaigns = $linkedcampaigns; $this->view->status = $cmpmodel->getStatus($cmpid); $this->view->files = $files; }
/** * 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; }
/** * getGroupData - Get group data and realted stuff * * @param int $grpId * @return array */ private function getGroupData($grpId) { // Get authentication $auth = Zend_Auth::getInstance(); // Get group data $grpModel = new Default_Model_Groups(); $grpData = $grpModel->getGroupData($grpId); $grpData['description_grp'] = $this->oibs_nl2p($grpData['description_grp']); //$grpData['description_grp'] = str_replace("\n", '<br>', $grpData['description_grp']); $grpData['body_grp'] = $this->oibs_nl2p($grpData['body_grp'], ""); //$grpData['body_grp'] = str_replace("\n", '<br>', $grpData['body_grp']); // User has identity if ($auth->hasIdentity()) { $grpData['user_identity'] = true; $grpData['user_id'] = $auth->getIdentity()->user_id; } else { $grpData['user_identity'] = false; } // Group admins $grpAdminsModel = new Default_Model_GroupAdmins(); $grpAdmins = $grpAdminsModel->getGroupAdmins($grpId); $grpData['grp_admins'] = $grpAdmins; $user = $auth->getIdentity(); $grpData['user_is_group_admin'] = isset($user->user_id) ? $this->checkIfArrayHasKeyWithValue($grpAdmins, 'id_usr', $user->user_id) : false; // Group type $grpTypeId = $grpModel->getGroupTypeId($grpId); $grpTypeModel = new Default_Model_GroupTypes(); $grpData['is_closed'] = $grpTypeModel->isClosed($grpTypeId); // usrHasGrp models if (isset($user->user_id)) { $usrHasGrpModel = new Default_Model_UserHasGroup(); $grpData['user_has_group'] = $usrHasGrpModel->userHasGroup($grpId, $user->user_id); $usrHasGrpWaitingModel = new Default_Model_UserHasGroupWaiting(); $grpData['user_has_group_waiting'] = $usrHasGrpWaitingModel->userWaitingGroup($grpId, $user->user_id); $grpData['usr_waiting_count'] = $usrHasGrpWaitingModel->getUserCountByGroup($grpId); } else { $grpData['user_has_group'] = false; $grpData['user_has_group_waiting'] = false; } return $grpData; }
/** * waitinlistAction * * Waiting list for group */ public function waitinglistAction() { $auth = Zend_Auth::getInstance(); if ($auth->hasIdentity()) { $usrId = $auth->getIdentity()->user_id; $grpId = $this->_request->getParam('grpid'); if (!isset($grpId)) { $redirectUrl = $this->_urlHelper->url(array('controller' => 'group', 'action' => 'index', 'language' => $this->view->language), 'lang_default', true); $this->_redirector->gotoUrl($redirectUrl); } $this->view->grpid = $grpId; $usrHasGrpModel = new Default_Model_UserHasGroup(); $usrHasGrpWaitingModel = new Default_Model_UserHasGroupWaiting(); $grpmodel = new Default_Model_Groups(); $grp = $grpmodel->getGroupData($grpId); // Accept or deny button was pressed if ($this->getRequest()->isPost()) { // Get the IDs of the first and last selected user $firstUsrId = $this->getRequest()->getPost('accept_or_deny_first'); $lastUsrId = $this->getRequest()->getPost('accept_or_deny_last'); $privateMessagesModel = new Default_Model_PrivateMessages(); // Accept or deny selected user for ($i = $firstUsrId; $i <= $lastUsrId; $i++) { if ($this->getRequest()->getPost('select_' . $i) == 'accept') { $usrHasGrpWaitingModel->removeUserWaitingFromGroup($grpId, $i); $usrHasGrpModel->addUserToGroup($grpId, $i); // Send privamessage $usermessage = array(); $usermessage['privmsg_sender_id'] = 0; $usermessage['privmsg_receiver_id'] = $i; $usermessage['privmsg_header'] = $grp['group_name_grp'] . ' waiting list'; $link = $this->_urlHelper->url(array('groupid' => $grpId, 'language' => $this->view->language), 'group_shortview', true); $usermessage['privmsg_message'] = 'You have been accepted to <a href="' . $link . '">' . $grp['group_name_grp'] . ' group.</a>'; $privateMessagesModel->addMessage($usermessage); } else { if ($this->getRequest()->getPost('select_' . $i) == 'deny') { $usrHasGrpWaitingModel->removeUserWaitingFromGroup($grpId, $i); // Send privamessage $usermessage = array(); $usermessage['privmsg_sender_id'] = 0; $usermessage['privmsg_receiver_id'] = $i; $usermessage['privmsg_header'] = $grp['group_name_grp'] . ' waiting list'; $link = $this->_urlHelper->url(array('groupid' => $grpId, 'language' => $this->view->language), 'group_shortview', true); $usermessage['privmsg_message'] = 'You have not been approved by the <a href="' . $link . '">' . $grp['group_name_grp'] . ' group.</a>'; $privateMessagesModel->addMessage($usermessage); } } } } $users = $usrHasGrpWaitingModel->getAllWaitingUsersInGroup($grpId); // Is user group admin? $grpadminmodel = new Default_Model_GroupAdmins(); if (!$grpadminmodel->userIsAdmin($grpId, $usrId)) { $redirectUrl = $this->_urlHelper->url(array('controller' => 'group', 'action' => 'index', 'language' => $this->view->language), 'lang_default', true); $this->_redirector->gotoUrl($redirectUrl); } $this->view->grp = $grp; $this->view->users = $users; } else { // If not logged, redirecting to system message page $message = 'You must login in!'; $url = $this->_urlHelper->url(array('controller' => 'msg', 'action' => 'index', 'language' => $this->view->language), 'lang_default', true); $this->flash($message, $url); } }
/** * listAction - shows a list of all campaigns */ function listAction() { $grpmodel = new Default_Model_Groups(); $cmpmodel = new Default_Model_Campaigns(); // If you find a better way to do this, be my guest. $cmps = $cmpmodel->getAll()->toArray(); $cmps_new = array(); foreach ($cmps as $cmp) { $grp = $grpmodel->getGroupData($cmp['id_grp_cmp']); $cmp['group_name_grp'] = $grp['group_name_grp']; $cmps_new[] = $cmp; } $this->view->campaigns = $cmps_new; }
/** * viewAction - shows an individual group's page * * @author Mikko Aatola */ function viewAction() { // Get authentication $auth = Zend_Auth::getInstance(); // If user has identity if ($auth->hasIdentity()) { // Get data for this specific group. $grpId = $this->_request->getParam('groupid'); $grpModel = new Default_Model_Groups(); $usrHasGrpModel = new Default_Model_UserHasGroup(); $grpAdminsModel = new Default_Model_GroupAdmins(); $campaignModel = new Default_Model_Campaigns(); $grpAdmins = $grpAdminsModel->getGroupAdmins($grpId); $user = $auth->getIdentity(); // Add data to the view. $this->view->grpId = $grpId; $this->view->grpData = $grpModel->getGroupData($grpId); $this->view->grpUsers = $usrHasGrpModel->getAllUsersInGroup($grpId); $this->view->grpAdmins = $grpAdmins; $this->view->userHasGroup = $usrHasGrpModel; $this->view->campaigns = $campaignModel->getCampaignsByGroup($grpId); $this->view->userIsGroupAdmin = $this->checkIfArrayHasKeyWithValue($grpAdmins, 'id_usr', $user->user_id); } else { // Groups are only visible to registered users. $target = $this->_urlHelper->url(array('controller' => 'index', 'action' => 'index', 'language' => $this->view->language), 'lang_default', true); $this->_redirector->gotoUrl($target); } }