mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-03-31 16:45:27 +00:00
implement api methods
This commit is contained in:
parent
dc489e26cc
commit
3949c9ee27
1 changed files with 99 additions and 0 deletions
|
|
@ -27,4 +27,103 @@ class Auth
|
||||||
)
|
)
|
||||||
');
|
');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function add(
|
||||||
|
int $identity,
|
||||||
|
string $request,
|
||||||
|
?int $time = null
|
||||||
|
): int
|
||||||
|
{
|
||||||
|
$query = $this->_connection->prepare(
|
||||||
|
'INSERT INTO `auth` (
|
||||||
|
`time`,
|
||||||
|
`identity`,
|
||||||
|
`request`
|
||||||
|
) VALUES (
|
||||||
|
:time,
|
||||||
|
:identity,
|
||||||
|
:request
|
||||||
|
)'
|
||||||
|
);
|
||||||
|
|
||||||
|
$query->execute(
|
||||||
|
[
|
||||||
|
':time' => $time ? $time : time(),
|
||||||
|
':identity' => $identity,
|
||||||
|
':request' => $request
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
return intval(
|
||||||
|
$this->_connection->lastInsertId()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete(
|
||||||
|
int $id
|
||||||
|
): int
|
||||||
|
{
|
||||||
|
$query = $this->_connection->prepare(
|
||||||
|
'DELETE FROM `auth` WHERE `id` = :id'
|
||||||
|
);
|
||||||
|
|
||||||
|
$query->execute(
|
||||||
|
[
|
||||||
|
':id' => $id
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
return $query->rowCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get(
|
||||||
|
int $id
|
||||||
|
): ?object
|
||||||
|
{
|
||||||
|
$query = $this->_connection->prepare(
|
||||||
|
'SELECT * FROM `auth` WHERE `id` = :id'
|
||||||
|
);
|
||||||
|
|
||||||
|
$query->execute(
|
||||||
|
[
|
||||||
|
':id' => $id
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($record = $query->fetch())
|
||||||
|
{
|
||||||
|
return $record;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function find(
|
||||||
|
string $request = '',
|
||||||
|
int $start = 0,
|
||||||
|
int $limit = 1000
|
||||||
|
): array
|
||||||
|
{
|
||||||
|
$query = $this->_connection->prepare(
|
||||||
|
sprintf(
|
||||||
|
'SELECT * FROM `auth`
|
||||||
|
WHERE `request` LIKE :request
|
||||||
|
ORDER BY `request` ASC
|
||||||
|
LIMIT %d,%d',
|
||||||
|
$start,
|
||||||
|
$limit
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$query->execute(
|
||||||
|
[
|
||||||
|
':request' => sprintf(
|
||||||
|
'%%%s%%',
|
||||||
|
$request
|
||||||
|
)
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
return $query->fetchAll();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue