function CheckifAdsavailable($ad_id, $module_id, $zone_id) { $session = JFactory::getSession(); $resultads = $session->get('SA_resultads'); $adRetriever = new adRetriever(); $ret = new stdClass(); shuffle($resultads[$zone_id]); //for getting random ads in ad rotation $is_ad = 0; foreach ($resultads[$zone_id] as $key => $ad_obj) { if (empty($ad_obj->seen)) { $is_ad = 1; $ret = $ad_obj; $resultads[$zone_id][$key]->seen = $module_id; if (empty($ad_obj->impression_done)) { $status_adcharge = $adRetriever->getad_status($ad_obj->ad_id); //reduce the credits if ($status_adcharge['status_ads'] == 1) { $adRetriever->reduceCredits($ad_obj->ad_id, 0, $status_adcharge['ad_charge'], $module_id); $resultads[$zone_id][$key]->impression_done = 1; } else { unset($resultads[$zone_id][$key]); } } break; } } if ($is_ad == 1) { foreach ($resultads[$zone_id] as $key => $ad_obj) { if ($ad_obj->ad_id == $ad_id) { $resultads[$zone_id][$key]->seen = ''; } } $session->set('SA_resultads', $resultads); if ($ret->ad_id != '') { return $ret; } } return false; }
function adreduceCredits() { /*$nodesModel=$this->getModel('nodes'); //call model function - polling $polling=$nodesModel->polling();*/ //output json response $input = JFactory::getApplication()->input; if ($input->get('token') == '1234') { if ($input->get('ad_id')) { $ad_id = $input->get('ad_id'); require_once JPATH_ROOT . DS . 'components' . DS . 'com_socialads' . DS . 'adshelper.php'; $adRetriever = new adRetriever(); $statue_adcharge = $adRetriever->getad_status($ad_id); $adRetriever->reduceCredits($ad_id, 0, $statue_adcharge['ad_charge']); header('Content-type: application/json'); echo json_encode(1); } } else { echo json_encode(-1); } jexit(); }