stwalkerster /
waca
| 1 | <?php |
||
| 2 | /****************************************************************************** |
||
| 3 | * Wikipedia Account Creation Assistance tool * |
||
| 4 | * * |
||
| 5 | * All code in this file is released into the public domain by the ACC * |
||
| 6 | * Development Team. Please see team.json for a list of contributors. * |
||
| 7 | ******************************************************************************/ |
||
| 8 | |||
| 9 | namespace Waca\DataObjects; |
||
| 10 | |||
| 11 | use Exception; |
||
| 12 | use Waca\DataObject; |
||
| 13 | |||
| 14 | class UserDomain extends DataObject |
||
| 15 | { |
||
| 16 | /** @var int */ |
||
| 17 | private $user; |
||
| 18 | |||
| 19 | /** @var int */ |
||
| 20 | private $domain; |
||
| 21 | |||
| 22 | public function save() |
||
| 23 | { |
||
| 24 | if ($this->isNew()) { |
||
| 25 | // insert |
||
| 26 | $statement = $this->dbObject->prepare(<<<SQL |
||
| 27 | INSERT INTO userdomain ( |
||
| 28 | user, domain |
||
| 29 | ) VALUES ( |
||
| 30 | :user, :domain |
||
| 31 | ); |
||
| 32 | SQL |
||
| 33 | ); |
||
| 34 | |||
| 35 | $statement->bindValue(":user", $this->user); |
||
| 36 | $statement->bindValue(":domain", $this->domain); |
||
| 37 | |||
| 38 | if ($statement->execute()) { |
||
| 39 | $this->id = (int)$this->dbObject->lastInsertId(); |
||
| 40 | } |
||
| 41 | else { |
||
| 42 | throw new Exception($statement->errorInfo()); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 43 | } |
||
| 44 | } |
||
| 45 | else { |
||
| 46 | // insert / delete only, no updates please. |
||
| 47 | throw new Exception('Updating domain membership is not available'); |
||
| 48 | } |
||
| 49 | } |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @return int |
||
| 53 | */ |
||
| 54 | public function getUser(): int |
||
| 55 | { |
||
| 56 | return $this->user; |
||
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @param int $user |
||
| 61 | */ |
||
| 62 | public function setUser(int $user): void |
||
| 63 | { |
||
| 64 | $this->user = $user; |
||
| 65 | } |
||
| 66 | |||
| 67 | /** |
||
| 68 | * @return int |
||
| 69 | */ |
||
| 70 | public function getDomain(): int |
||
| 71 | { |
||
| 72 | return $this->domain; |
||
| 73 | } |
||
| 74 | |||
| 75 | /** |
||
| 76 | * @param int $domain |
||
| 77 | */ |
||
| 78 | public function setDomain(int $domain): void |
||
| 79 | { |
||
| 80 | $this->domain = $domain; |
||
| 81 | } |
||
| 82 | |||
| 83 | |||
| 84 | } |