context->table('addresslists')->insert([ 'name' => $uid, 'private' => $private, 'luser' => $owner, 'lusergroup' => $ownergroup, ]); return $database->createModel('Addresslist', $activerow); } public function delete() { $this->activerow->delete(); } public function getName() { return $this->activerow->name; } public function setName($name) { $this->activerow->update(['name' => $name]); } public function getPrivate() { return $this->activerow->private; } public function setPrivate($private) { $this->activerow->update(['private' => $private]); } public function getOwner() { return $this->activerow->luser; } public function setOwner($owner) { $this->activerow->update(['luser' => $owner]); } public function getOwnergroup() { return $this->activerow->lusergroup; } public function getUsergroup() { $row = $this->activerow->ref('lusergroup'); return $row ? $this->database->createModel('Usergroup', $row) : null; } public function setOwnergroup($ownergroup) { $this->activerow->update(['lusergroup' => $ownergroup]); } public function getMtime() { return $this->activerow->mtime; } public function getCount() { return count($this->getAddresses()); } public function hasAddresses() { $rows = $this->context->table('emailaddresses') ->where(':addresslistentries.addresslist', $this->activerow->addresslist) ->limit(1); foreach($rows as $row) return true; return false; } public function getAddresses() { $rows = $this->context->table('emailaddresses') ->where(':addresslistentries.addresslist', $this->activerow->addresslist); $addresses = []; $database = $this->database; foreach($rows as $row) { $e = $database->createModel('Emailaddress', $row); $addresses[strtolower($e->address)] = $e; } return $addresses; } public function pagedAddresses($pagesize, $pageoff, $query = null) { $rows = $this->context->table('emailaddresses') ->where(':addresslistentries.addresslist', $this->activerow->addresslist) ->limit($pagesize)->offset($pageoff); if($query !== null && $query != '') { $escaped_query = preg_replace('/([\\\\%_])/', '\\\\$1', $query); $rows->where("address LIKE ? ESCAPE '\\'", "%$escaped_query%"); } $addresses = []; $database = $this->database; foreach($rows as $row) { $e = $database->createModel('Emailaddress', $row); $addresses[strtolower($e->address)] = $e; } return $addresses; } public function getAddressResults() { $types = []; $addresses = $this->getAddresses(); foreach($addresses as $address) { $type = $address->laststatus; if (array_key_exists($type, $types)) { $types[$type]++; } else { $types[$type] = 1; } } return $types; } public function addAddresses($addaddresses) { $currentaddresses = $this->getAddresses(); $context = $this->context; $addresslistentries = $this->context->table('addresslistentries'); $addresslist = $this->activerow->addresslist; // own database ID foreach($addaddresses as $newaddress) { if(is_object($newaddress)) { $key = strtolower($newaddress->address); } else { $key = strtolower($newaddress); if(array_key_exists($key, $currentaddresses)) $newaddress = $currentaddresses[$key]; else $newaddress = Emailaddress::create($this->database, $newaddress); } $newaddresses[$key] = $newaddress; if(!array_key_exists($key, $currentaddresses)) $newaddress->attach_to_addresslist($addresslist); } } public function setAddresses($addresses) { $oldaddresses = $this->getAddresses(); $newaddresses = []; $context = $this->context; $addresslistentries = $this->context->table('addresslistentries'); $addresslist = $this->activerow->addresslist; // own database ID foreach($addresses as $newaddress) { if(is_object($newaddress)) { $key = strtolower($newaddress->address); } else { $key = strtolower($newaddress); if(array_key_exists($key, $oldaddresses)) $newaddress = $oldaddresses[$key]; else $newaddress = Emailaddress::create($this->database, $newaddress); } $newaddresses[$key] = $newaddress; if(!array_key_exists($key, $oldaddresses)) $newaddress->attach_to_addresslist($addresslist); } foreach($oldaddresses as $oldaddress) if(!array_key_exists(strtolower($oldaddress->address), $newaddresses)) $oldaddress->detach_from_addresslist($addresslist); } }