/** * Migrate contacts to other Contact Group */ public function migrationAction() { $this->view->breadcrumb = Snep_Breadcrumb::renderPath(array($this->view->translate("Manage"), $this->view->translate("Contact Group"), $this->view->translate("Migrate Contacts"))); $id = $this->_request->getParam('id'); $groupAll = new Snep_ContactGroups_Manager(); $_allGroups = $groupAll->fetchAll(); foreach ($_allGroups as $group) { if ($group['id_contact_group'] != $id) { $allGroups[$group['id_contact_group']] = $group['ds_name']; } } Zend_Registry::set('cancel_url', $this->getFrontController()->getBaseUrl() . '/' . $this->getRequest()->getControllerName() . '/index'); $form = new Snep_Form(new Zend_Config_Xml("modules/default/forms/contact_groups_migration.xml")); $form->setAction($this->getFrontController()->getBaseUrl() . '/contact-groups/migration/stage/2'); if (isset($allGroups)) { $form->getElement('group')->setMultiOptions($allGroups); $form->getElement('option')->setMultiOptions(array('migrate' => 'migrate contacts to group', 'remove' => 'remove all'))->setValue('migrate'); } else { $form->removeElement('group'); $form->getElement('option')->setMultiOptions(array('remove' => 'remove all')); } $this->view->message = $this->view->translate("The excluded group has associated contacts."); $form->getElement('id')->setValue($id); $stage = $this->_request->getParam('stage'); if (isset($stage['stage']) && $id) { if ($_POST['option'] == 'migrate') { $obj = new Snep_Contacts_Manager(); $select = $obj->select()->where('id_contact_group = ?', $id); $contacts = $obj->fetchAll($select)->toarray(); $idGroup = $_POST['group']; $dadosUpdate = array('id_contact_group' => $idGroup); foreach ($contacts as $contactselect) { $idContact = $contactselect['id_contact']; $obj->update($dadosUpdate, "id_contact = {$idContact}"); } $groupAll->delete("id_contact_group ={$id}"); } elseif ($_POST['option'] == 'remove') { $obj = new Snep_Contacts_Manager(); $select = $obj->select()->where('id_contact_group = ?', $id); $contacts = $obj->fetchAll($select)->toArray(); foreach ($contacts as $contact) { $idContact = $contact['id_contact']; $obj->delete("id_contact = {$idContact}"); } $groupAll->delete("id_contact_group ={$id}"); } $this->_redirect($this->getRequest()->getControllerName()); } $this->view->form = $form; }