diff --git a/plugin/AD_Server/Objects/VastCampaignsLogs.php b/plugin/AD_Server/Objects/VastCampaignsLogs.php index c23b77e57..7ae8bdaeb 100644 --- a/plugin/AD_Server/Objects/VastCampaignsLogs.php +++ b/plugin/AD_Server/Objects/VastCampaignsLogs.php @@ -1,100 +1,115 @@ id; } function getUsers_id() { return $this->users_id; } function getType() { return $this->type; } function getVast_campaigns_has_videos_id() { return $this->vast_campaigns_has_videos_id; } function setId($id) { $this->id = $id; } function setUsers_id($users_id) { $this->users_id = $users_id; } function setType($type) { $this->type = $type; } function setVast_campaigns_has_videos_id($vast_campaigns_has_videos_id) { $this->vast_campaigns_has_videos_id = $vast_campaigns_has_videos_id; } function getIp() { return $this->ip; } function save() { $this->ip = getRealIpAddr(); return parent::save(); } + static function getViews(){ + global $global; + $sql = "SELECT count(*) as total FROM vast_campaigns_logs WHERE `type` = 'start'"; + + $res = sqlDAL::readSql($sql, "i", array($id)); + $data = sqlDAL::fetchAssoc($res); + sqlDAL::close($res); + if ($res) { + $row = $data; + } else { + $row = false; + } + return $row['total']; + } + static function getData($vast_campaigns_has_videos_id){ global $global; $sql = "SELECT `type`, count(*) as total FROM vast_campaigns_logs WHERE vast_campaigns_has_videos_id = $vast_campaigns_has_videos_id GROUP BY `type`"; $res = sqlDAL::readSql($sql); $fullData = sqlDAL::fetchAllAssoc($res); sqlDAL::close($res); $data = array(); if ($res!=false) { foreach ($fullData as $row) { $data[$row['type']] = $row['total']; } } else { die($sql . '\nError : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error); } return $data; } static function getDataFromCampaign($vast_campaigns_id){ global $global; $sql = "SELECT `type`, count(vast_campaigns_id) as total FROM vast_campaigns_logs vcl " . " LEFT JOIN vast_campaigns_has_videos vchv ON vast_campaigns_has_videos_id = vchv.id " . " WHERE vast_campaigns_id = $vast_campaigns_id GROUP BY `type`"; //echo $sql."\n"; $res = sqlDAL::readSql($sql); $fullData = sqlDAL::fetchAllAssoc($res); sqlDAL::close($res); $data = array(); if ($res!=false) { foreach ($fullData as $row) { $data[$row['type']] = $row['total']; } } else { die($sql . '\nError : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error); } return $data; } } diff --git a/plugin/AD_Server/getData.json.php b/plugin/AD_Server/getData.json.php new file mode 100644 index 000000000..2a3629a6f --- /dev/null +++ b/plugin/AD_Server/getData.json.php @@ -0,0 +1,19 @@ +error = true; +$obj->msg = ""; +$obj->views = 0; +$ad_server = YouPHPTubePlugin::loadPluginIfEnabled('AD_Server'); +if(empty($ad_server)){ + $obj->msg = "not enabled"; + die(json_encode($obj)); +} + +$obj->error = false; +$obj->views = VastCampaignsLogs::getViews(); + +echo json_encode($obj); \ No newline at end of file