rendered paste body<?phpclass Processor{ private $mailingListsNew; private $mailingListsAll; private $emailIndex; private $db; public function __construct( $db, $mailingListsNew, $emailIndex ) { $this->db = $db; $this->emailIndex = $emailIndex; $this->mailingListsNew = $mailingListsNew; } public function insertMailingListsToDB() { $mailingLists = array_keys( $this->mailingListsNew ); $dbMailingLists = $this->db->getMailingListsFromDB(); foreach($mailingLists as $ML) { if(!in_array($ML, $dbMailingLists)) { $this->db->insertOneMailingListToDB($ML); Report::$newMailingLists++; } } $this->mailingListsAll = $this->db->getMailingListsFromDB(); } public function saveAllDataToDb($rows) { foreach($rows as $index=>$row) { $this->db->setEmail( $row[$this->emailIndex] ); $mailingListIdsUserHasInFile = $this->mailingListIdsUserHasInFile($row); $mailingListIdsUserHasInDB = $this->db->mailingListIdsUserHasInDB(); foreach($mailingListIdsUserHasInFile as $mailingListId) { if(in_array($mailingListId, $mailingListIdsUserHasInDB)) { $this->db->update($row, $mailingListId); Report::$duplicates++; } else { $this->db->insert($row, $mailingListId); Report::$imported++; } } } } private function mailingListIdsUserHasInFile($row) { $MLs = array_flip( $this->mailingListsNew ); $MLsAll = array_flip( $this->mailingListsAll ); $result = array(); foreach($row as $key=>$value) { if(( intval($value) == 1)&&( in_array($key, $this->mailingListsNew))) { $result[] = $MLsAll[ $MLs[$key] ]; } } return $result; } }