63 lines
1.8 KiB
PHP
63 lines
1.8 KiB
PHP
<?php
|
|
|
|
class RadioService
|
|
{
|
|
|
|
private $CI;
|
|
|
|
const TOKEN_MAXAGE = 3600;
|
|
|
|
const APP_ID = 75;
|
|
|
|
|
|
public function __construct()
|
|
{
|
|
$this->CI = &get_instance();
|
|
}
|
|
|
|
public function getAppId($appId = null) {
|
|
return $appId ? $appId : self::APP_ID;
|
|
}
|
|
|
|
public function checkToken()
|
|
{
|
|
$key = $this->CI->input->server('HTTP_ACCESS_TOKEN');
|
|
$key = $this->CI->rest->db->where('key', $key)->get(config_item('rest_keys_table'));
|
|
if ($key->num_rows() == 0) {
|
|
return 401;
|
|
} else if ($key->row()->date_created < time() - self::TOKEN_MAXAGE) {
|
|
return 402;
|
|
}
|
|
}
|
|
|
|
public function getSchedule($categoryId, $day)
|
|
{
|
|
$this->CI->load->model('station_schedule_model');
|
|
return $this->CI->station_schedule_model->findSchedulesByCategoryIdAndDayName($categoryId, $day)->result();
|
|
}
|
|
|
|
public function getApp($appId)
|
|
{
|
|
$this->CI->load->model('app_model');
|
|
$app = $this->CI->app_model->findByAppId($appId)->row();
|
|
$customInfos = unserialize($app->customInfo);
|
|
$app->customInfo = array();
|
|
for ($i = 0; $i < count($customInfos['link']); $i++) {
|
|
foreach ($customInfos as $field => $values) {
|
|
$app->customInfo[$i][$field] = $values[$i];
|
|
}
|
|
}
|
|
$app->customInfo = array_filter($app->customInfo, function ($info) {
|
|
return count(array_filter(array_values($info)));
|
|
});
|
|
return $app;
|
|
}
|
|
|
|
public function getCategory($appId)
|
|
{
|
|
$this->CI->load->model('category_model');
|
|
$categories = $this->CI->category_model->findCategoriesByAppId($appId)->result();
|
|
return $categories;
|
|
}
|
|
}
|