1
0
mirror of https://github.com/cydrobolt/polr.git synced 2024-11-14 22:22:32 +01:00
polr/app/Helpers/ApiHelper.php
2016-04-14 12:37:28 -03:00

27 lines
704 B
PHP

<?php
namespace App\Helpers;
use App\Models\Link;
use App\Helpers\UserHelper;
class ApiHelper {
public static function checkUserApiQuota($username) {
/**
*
* @return boolean; whether API quota is met
*/
$last_minute_unix = time() - 60;
$last_minute = new \DateTime();
$last_minute->setTimestamp($last_minute_unix);
$user = UserHelper::getUserByUsername($username);
$links_last_minute = Link::where('is_api', 1)
->where('creator', $username)
->where('created_at', '>=', $last_minute)
->count();
return ($user->api_quota > -1 && $links_last_minute >= $user->api_quota);
}
}