/** * removeGroup * Removes the group from the database * * @param int id_grp * @author Mikko Aatola */ public function removeGroup($id_grp = 0) { if (!$id_grp) { return false; } // Delete the group's campaigns. $data = $this->_db->select()->from('campaigns_cmp', 'id_cmp')->where('id_grp_cmp = ?', $id_grp); $campaigns = $this->_db->fetchAll($data); $cmpModel = new Default_Model_Campaigns(); foreach ($campaigns as $cmp) { $cmpModel->removeCampaign($cmp['id_cmp']); } // Delete group weblinks $grpWeblinksModel = new Default_Model_GroupWeblinks(); $grpWeblinksModel->removeGroupWeblinks($id_grp); // Delete group-admin links from grp_has_admin_usr. $grpAdm = new Default_Model_GroupAdmins(); $grpAdm->removeAdminsFromGroup($id_grp); // Delete groups files $filesModel = new Default_Model_Files(); $filesModel->removeFiles($id_grp, "group"); // Delete group. $where = $this->getAdapter()->quoteInto('id_grp = ?', $id_grp); $this->delete($where); }
public function removeAction() { $auth = Zend_Auth::getInstance(); if ($auth->hasIdentity()) { $cmpId = $this->_request->getParam('id'); if (!$cmpId) { $target = $this->_urlHelper->url(array('controller' => 'index', 'action' => 'index', 'language' => $this->view->language), 'lang_default', true); $this->_redirector->gotoUrl($target); } // Get group id from campaign info. $cmpModel = new Default_Model_Campaigns(); $cmp = $cmpModel->getCampaignById($cmpId)->toArray(); $grpId = $cmp['id_grp_cmp']; // Only group admins get to remove campaigns. $grpAdminsModel = new Default_Model_GroupAdmins(); $grpAdmins = $grpAdminsModel->getGroupAdmins($grpId); $userIsGroupAdmin = $this->checkIfArrayHasKeyWithValue($grpAdmins, 'id_usr', $auth->getIdentity()->user_id); if (!$userIsGroupAdmin) { $redirectUrl = $this->_urlHelper->url(array('controller' => 'campaign', 'action' => 'index', 'language' => $this->view->language), 'lang_default', true); $this->_redirector->gotoUrl($redirectUrl); } // Delete campaign. $cmpModel->removeCampaign($cmpId); // Redirect to the group page. $target = $this->_urlHelper->url(array('groupid' => $grpId, 'language' => $this->view->language), 'group_shortview', true); $this->_redirector->gotoUrl($target); } else { // Not logged in - redirect to the group page. $target = $this->_urlHelper->url(array('groupid' => $grpId, 'language' => $this->view->language), 'group_shortview', true); $this->_redirector->gotoUrl($target); } }
/** * * */ public function checkExistingCampaigns($contentId = -1, array $campaigns = array()) { $result = null; if ($contentId != -1 && !empty($campaigns)) { // Go through all existing campaigns $existingCmps = $this->getContentCampaigns($contentId); foreach ($existingCmps as $id => $campaign) { // If some of the existing campaigns aren't found in sent campaigns, // that campaign is deleted the from content and maybe even from the // database if (!in_array($campaign['name_cmp'], $campaigns)) { // Removing campaign from content $this->deleteCampaignFromContent($existingCmp['id_cmp'], $contentId); // If other content(s) doesn't have this campaign, the whole // campaign is going to be removed from the database if (!$this->checkIfOtherContentHasCampaign($existingCmp['id_cmp'], $contentId)) { $modelCmps = new Default_Model_Campaigns(); $modelCmps->removeCampaign($existingCmp['id_cmp']); } // Remove campaign from existingCmps array unset($existingCmps[$id]); } } $result = $existingCmps; } return $result; }