flush
[pharext/pharext.org] / app / Model / Account.php
1 <?php
2
3 namespace app\Model;
4
5 use pq\Gateway\Row;
6
7 class Account extends Row
8 {
9 function updateToken($authority, $token, $json) {
10 $tokens = $this->table->getTokens();
11
12 $existing = $tokens->find([
13 "authority=" => $authority,
14 "account=" => $this->account,
15 ]);
16
17 if (count($existing)) {
18 $found = $existing->current();
19 $found->token = $token;
20 $found->oauth = $json;
21 $found->update();
22 return $found;
23 }
24
25 return $tokens->create([
26 "authority" => $authority,
27 "account" => $this->account,
28 "token" => $token,
29 "oauth" => $json
30 ])->current();
31 }
32
33 function updateOwner($authority, $user, $json) {
34 $owners = $this->table->getOwners();
35
36 $existing = $owners->find([
37 "authority=" => $authority,
38 "account=" => $this->account,
39 ]);
40
41 if (count($existing)) {
42 $found = $existing->current();
43 $found->login = $user;
44 $found->owner = $json;
45 $found->update();
46 return $found;
47 }
48
49 return $owners->create([
50 "authority" => $authority,
51 "login" => $user,
52 "owner" => $json
53 ])->current();
54 }
55 }