/** * Remove specified members * * @param integer|array $ids Members identifiers to delete * * @return boolean */ public function removeMembers($ids) { global $zdb, $hist; $list = array(); if (is_numeric($ids)) { //we've got only one identifier $list[] = $ids; } else { $list = $ids; } if (is_array($list)) { try { $zdb->connection->beginTransaction(); //Retrieve some informations $select = $zdb->select(self::TABLE); $select->columns(array(self::PK, 'nom_adh', 'prenom_adh'))->where->in(self::PK, $list); $results = $zdb->execute($select); $infos = null; foreach ($results as $member) { $str_adh = $member->id_adh . ' (' . $member->nom_adh . ' ' . $member->prenom_adh . ')'; $infos .= $str_adh . "\n"; $p = new Picture($member->id_adh); if ($p->hasPicture()) { if (!$p->delete(false)) { Analog::log('Unable to delete picture for member ' . $str_adh, Analog::ERROR); throw new \Exception('Unable to delete picture for member ' . $str_adh); } else { $hist->add(_T("Member Picture deleted"), $str_adh); } } } //delete contributions $del_qry = $zdb->delete(Contribution::TABLE); $del_qry->where->in(self::PK, $list); $del = $zdb->execute($del_qry); //delete transactions $del_qry = $zdb->delete(Transaction::TABLE); $del_qry->where->in(self::PK, $list); $del = $zdb->execute($del_qry); //delete groups membership/mamagmentship $del = Groups::removeMemberFromGroups((int) $member->id_adh); //delete reminders $del_qry = $zdb->delete(Reminder::TABLE); $del_qry->where->in('reminder_dest', $list); $del = $zdb->execute($del_qry); //delete members $del_qry = $zdb->delete(self::TABLE); $del_qry->where->in(self::PK, $list); $del = $zdb->execute($del_qry); //commit all changes $zdb->connection->commit(); //add an history entry $hist->add(_T("Delete members cards, transactions and dues"), $infos); return true; } catch (\Exception $e) { $zdb->connection->rollBack(); if ($e instanceof \Zend_Db_Statement_Exception && $e->getCode() == 23000) { Analog::log('Member still have existing dependencies in the ' . 'database, maybe a mailing or some content from a ' . 'plugin. Please remove dependencies before trying ' . 'to remove him.', Analog::ERROR); $this->_errors[] = _T("Cannot remove a member who still have dependencies (mailings, ...)"); } else { Analog::log('Unable to delete selected member(s) |' . $e->getMessage(), Analog::ERROR); } return false; } } else { //not numeric and not an array: incorrect. Analog::log('Asking to remove members, but without providing an array or a single numeric value.', Analog::WARNING); return false; } }