| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * dmarc-srg - A php parser, viewer and summary report generator for incoming DMARC reports. |
| 5 | * Copyright (C) 2021-2024 Aleksey Andreev (liuch) |
| 6 | * |
| 7 | * Available at: |
| 8 | * https://github.com/liuch/dmarc-srg |
| 9 | * |
| 10 | * This program is free software: you can redistribute it and/or modify it |
| 11 | * under the terms of the GNU General Public License as published by the Free |
| 12 | * Software Foundation, either version 3 of the License. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 17 | * more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License along with |
| 20 | * this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 | * |
| 22 | * ========================= |
| 23 | * |
| 24 | * This file contains the class DomainList |
| 25 | * |
| 26 | * @category API |
| 27 | * @package DmarcSrg |
| 28 | * @author Aleksey Andreev (liuch) |
| 29 | * @license https://www.gnu.org/licenses/gpl-3.0.html GNU/GPLv3 |
| 30 | */ |
| 31 | |
| 32 | namespace Liuch\DmarcSrg\Domains; |
| 33 | |
| 34 | use Liuch\DmarcSrg\Core; |
| 35 | |
| 36 | /** |
| 37 | * This class is designed to work with the list of domains |
| 38 | */ |
| 39 | class DomainList |
| 40 | { |
| 41 | private $db = null; |
| 42 | private $user = null; |
| 43 | |
| 44 | /** |
| 45 | * The constructor |
| 46 | * |
| 47 | * @param \Liuch\DmarcSrg\Users\User $user User to which domais are assigned |
| 48 | * @param \Liuch\DmarcSrg\Database\DatabaseController $db The database controller |
| 49 | */ |
| 50 | public function __construct($user, $db = null) |
| 51 | { |
| 52 | $this->user = $user; |
| 53 | $this->db = $db ?? Core::instance()->database(); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Returns a list of domains from the database |
| 58 | * |
| 59 | * @return array Array with instances of Domain class |
| 60 | */ |
| 61 | public function getList(): array |
| 62 | { |
| 63 | $list = []; |
| 64 | foreach ($this->db->getMapper('domain')->list($this->user->id()) as $dd) { |
| 65 | $list[] = new Domain($dd, $this->db); |
| 66 | } |
| 67 | return [ |
| 68 | 'domains' => $list, |
| 69 | 'more' => false |
| 70 | ]; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Returns an ordered array with domain names from the database |
| 75 | * |
| 76 | * @return array Array of strings |
| 77 | */ |
| 78 | public function names(): array |
| 79 | { |
| 80 | return $this->db->getMapper('domain')->names($this->user->id()); |
| 81 | } |
| 82 | } |