コード例 #1
0
 public function predictAction()
 {
     //get common info of match
     $this->_getInfoMatch();
     // Disable render layout
     $this->_helper->layout->disableLayout(true);
     $this->_helper->viewRenderer->setNoRender(true);
     // Get user login
     $session = new Zend_Session_Namespace(SESSION_NAMESPACE);
     $arrParams = $this->_request->getParams();
     $intMatchID = (int) $arrParams['matchid'] ? $arrParams['matchid'] : 0;
     $intGoalTeam1 = (int) $arrParams['goalteam1'] ? $arrParams['goalteam1'] : 0;
     $intGoalTeam2 = (int) $arrParams['goalteam2'] ? $arrParams['goalteam2'] : 0;
     //get site id
     $client_ip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) && !empty($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
     // Prepare for reading cache
     $memcacheInstance = Thethao_Global::getCache();
     $keyCache = vsprintf(CACHING_PREFIX . 'client_ip:%s:%s', array($intMatchID, $client_ip));
     //get memcache
     $predict = $memcacheInstance->read($keyCache);
     if ($predict === false) {
         //Check matchID
         if (!$intMatchID) {
             echo -1;
             return;
         }
         //Check input data
         if ($intGoalTeam1 < 0 || $intGoalTeam2 < 0) {
             echo -2;
             return;
         }
         $params = array('match_id' => $intMatchID, 'mobile' => NULL, 'userid' => (int) $session->userid, 'goal_team1' => (int) $arrParams['goalteam1'], 'goal_team2' => (int) $arrParams['goalteam2'], 'numpeople' => NULL, 'codepre' => NULL, 'type' => 1);
         //Insert predict
         $matchModel = Thethao_Model_Match::getInstance();
         $arrReponse = $matchModel->pushJobInsertMatchPredict($params);
         // Write to cache
         if ($arrReponse) {
             $memcacheInstance->write($keyCache, $arrReponse, 60);
             Thethao_Global::writeMemcache($keyCache, $arrReponse, 'all', NULL, 60);
         }
         echo Zend_Json::encode($arrReponse);
     } else {
         echo -1;
         return;
     }
 }
コード例 #2
0
ファイル: Player.php プロジェクト: Nhan-Huynh-FO/nhan-repo
 /**
  * Get list players by team
  * @param int $teamId
  * @return array
  * @author ThuyNT
  */
 public function getListPlayersByTeam($teamId)
 {
     $memcacheInstance = Thethao_Global::getCache();
     $keyCache = vsprintf($this->_player_by_team, array($teamId));
     // Read from cache
     $arrListPlayers = $memcacheInstance->read($keyCache);
     // Miss cache
     if ($arrListPlayers === FALSE) {
         try {
             // Get application's configuation
             $config = Thethao_Global::getApplicationIni();
             // Get mysql object access player
             $playerMysqlObj = $this->factory('Player', $config['database']['default']['adapter']);
             // Get data from db
             $arrListPlayers = $playerMysqlObj->getListPlayersByTeam($teamId);
             if (!empty($arrListPlayers)) {
                 // Write to cache
                 $memcacheInstance->write($keyCache, $arrListPlayers);
                 Thethao_Global::writeMemcache($keyCache, $arrListPlayers);
             } else {
                 // Store into cache
                 $memcacheInstance->write($keyCache, -1);
                 Thethao_Global::writeMemcache($keyCache, -1);
             }
         } catch (Exception $ex) {
             Thethao_Global::sendlog($ex, 1);
         }
     } else {
         if ($arrListPlayers == -1) {
             $arrListPlayers = array();
         }
     }
     return $arrListPlayers;
 }
コード例 #3
0
ファイル: News.php プロジェクト: Nhan-Huynh-FO/nhan-repo
 /**
  * Get news by rule 3 : folder X + subfolder X  => order by publish_time
  * @param array $arrParams array(category_id, offset, limit)
  * @return array
  * @author HungNT1
  */
 public function getListArticleIdsByRule3($arrParams)
 {
     //default return
     $arrReturn = array('total' => 0, 'data' => array());
     //set paramt default
     $arrDefault = array('category_id' => 0, 'limit' => 10, 'offset' => 0);
     //merge param with default
     $arrParams = array_merge($arrDefault, $arrParams);
     //format params
     $arrParams['limit'] = intval($arrParams['limit']);
     $arrParams['offset'] = intval($arrParams['offset']);
     //check limit with max_limit to reset limit
     //$arrParams['limit'] = $arrParams['limit']>$this->_max_limit?$this->_max_limit:$arrParams['limit'];
     //valid data
     if ($arrParams['category_id'] > 0 && $arrParams['limit'] > 0 && $arrParams['limit'] <= $this->_max_limit) {
         //Check is from job
         $isFromJob = defined('FROM_JOB') && FROM_JOB == 1;
         // Get instance memcache
         $memCacheInstance = Thethao_Global::getCache('all');
         $keyCache = vsprintf($this->_list_article_ids_by_rule_3, array($arrParams['category_id']));
         //get data from mem cached
         $arrReturn = $memCacheInstance->read($keyCache);
         //check data empty
         if ($isFromJob || $arrReturn === false) {
             //get app conf
             $config = Thethao_Global::getApplicationIni();
             //init mysql instance
             $newsMysql = $this->factory('News', $config['database']['default']['adapter']);
             //get db list
             $arrReturn = $newsMysql->getListArticleIdsByRule3(array('category_id' => $arrParams['category_id'], 'offset' => 0, 'limit' => 10));
             //max record
             //set memcached
             $memCacheInstance->write($keyCache, $arrReturn);
             if ($isFromJob) {
                 Thethao_Global::writeMemcache($keyCache, $arrReturn, 'all');
             }
         }
     }
     //end check valid category_id
     //process data return
     if (!empty($arrReturn['data'])) {
         //only get array id
         $arrReturn['data'] = array_slice(array_keys($arrReturn['data']), $arrParams['offset'], $arrParams['limit']);
     }
     return $arrReturn;
 }
コード例 #4
0
ファイル: Match.php プロジェクト: Nhan-Huynh-FO/nhan-repo
 /**
  * Function rewrite match cache for football Live
  */
 public function rewriteMatchLive($params)
 {
     $modelObject = new Fpt_Data_Materials_Object();
     $arrMatch = array();
     // Execute data match
     if (isset($params['match']) && !empty($params['match'])) {
         $memcacheInstance = Thethao_Global::getCache();
         foreach ($params['match'] as $id => $match) {
             //add match id=>time-happen
             $arrMatch[$id] = $match['time_happen'];
             if (!empty($match['player'])) {
                 $keyCache1 = vsprintf($this->_player_team_match_list, array($id, $match['team1_id']));
                 $keyCache2 = vsprintf($this->_player_team_match_list, array($id, $match['team2_id']));
                 Thethao_Global::deleteMemcache(array($keyCache1, $keyCache2));
                 $arrPlayersTeamHome = $match['player'][$match['team1_id']];
                 $arrPlayersTeamAway = $match['player'][$match['team2_id']];
                 $memcacheInstance->write($keyCache1, $arrPlayersTeamHome);
                 Thethao_Global::writeMemcache($keyCache1, $arrPlayersTeamHome);
                 $memcacheInstance->write($keyCache2, $arrPlayersTeamAway);
                 Thethao_Global::writeMemcache($keyCache2, $arrPlayersTeamAway);
             }
             if (isset($match['Event']) && !empty($match['Event'])) {
                 $keyMatchDetail = vsprintf($this->_match_extend, '');
                 //set extend match detail
                 $keyMatchDetail = $keyMatchDetail . $id;
                 Thethao_Global::deleteMemcache(array($keyMatchDetail));
                 //write cache memcache
                 $memcacheInstance->write($keyMatchDetail, $match['Event']);
                 Thethao_Global::writeMemcache($keyMatchDetail, $match['Event']);
             }
             //update detail match
             if (isset($match['Result']) && $match['Result']) {
                 $modelObject->getMatch()->updateObject($id, true);
             }
         }
     }
 }
コード例 #5
0
ファイル: Football.php プロジェクト: Nhan-Huynh-FO/nhan-repo
 /**
  * Get list league by group
  * @param int $group
  * @return array
  */
 public function getListLeagueByGroup($group)
 {
     $memcacheInstance = Thethao_Global::getCache();
     $keyCache = vsprintf($this->_league_by_group_list, array($group));
     // Read cache
     $listLeagues = $memcacheInstance->read($keyCache);
     // Miss cache
     if ($listLeagues === FALSE) {
         try {
             $config = Thethao_Global::getApplicationIni();
             // Get db teamseason instance
             $leagueObj = $this->factory('Football', $config['database']['default']['adapter']);
             // Get data from db
             $listLeagues = $leagueObj->getListLeagueByGroup($group);
             // Write to cache
             $memcacheInstance->write($keyCache, $listLeagues);
             Thethao_Global::writeMemcache($keyCache, $listLeagues);
         } catch (Exception $ex) {
             Thethao_Global::sendlog($ex);
         }
     }
     return $listLeagues;
 }
コード例 #6
0
ファイル: Category.php プロジェクト: Nhan-Huynh-FO/nhan-repo
 /**
  * Get full category include all sub category
  * @return array
  * @author LamTX
  */
 public function getFullCategoryByParentId($preCache = false)
 {
     if ($this->_cate == null) {
         $intCategoryID = SITE_ID;
         // Get instance memcache
         $memcacheInstance = Thethao_Global::getCache();
         $keyCache = vsprintf($this->_key_cache, array($intCategoryID));
         // Get full category from Memcache
         $arrMenuCate = $memcacheInstance->read($keyCache);
         //$arrFullCatInfo = array();
         // Data not in cache
         if ($preCache || empty($arrMenuCate['menu']) && empty($arrMenuCate['cate'])) {
             // Get application config
             $config = Thethao_Global::getApplicationIni();
             // Get instance mysql
             $cateMysql = $this->factory('Category', $config['database']['default']['adapter']);
             $arrMenuCate = array('menu' => array(), 'cate' => array());
             // Get cate in DB
             $arrFullCatInfo = $cateMysql->getFullCategoryByParentId($intCategoryID);
             if (!empty($arrFullCatInfo)) {
                 $arrTemp = array();
                 foreach ($arrFullCatInfo as $detail) {
                     $detail['child'] = $detail['child_recursive'] = array();
                     //update cate share_url
                     if ($detail['parent_id'] == SITE_ID) {
                         switch ($detail['category_id']) {
                             case CATE_ID_VIDEO:
                             case CATE_ID_PHOTO:
                             case CATE_ID_FIXTURE:
                                 $detail['link'] = '/' . $detail['catecode'];
                                 break;
                             case SITE_ID:
                                 $detail['link'] = '/';
                                 break;
                             default:
                                 $detail['link'] = '/tin-tuc/' . $detail['catecode'];
                                 break;
                         }
                     } else {
                         //check world cup
                         if ($detail['parent_id'] == WORLD_CUP || $detail['parent_id'] == SEA_GAMES) {
                             $detail['link'] = '/' . $detail['catecode'];
                         } else {
                             $detail['link'] = $arrTemp[$detail['parent_id']]['link'] . '/' . $detail['catecode'];
                         }
                     }
                     //end if
                     //explode parent => array
                     $detail['full_parent'] = $detail['full_parent_original'] = explode(',', $detail['full_parent']);
                     //remove site_id
                     unset($detail['full_parent'][0]);
                     //pre order key
                     $detail['full_parent'] = array_values($detail['full_parent']);
                     //assign array temp
                     $arrTemp[$detail['category_id']] = $detail;
                     //update share_url + parent to original array
                     $arrFullCatInfo[$detail['category_id']] = $detail;
                     //if this cate have parent
                     if (!empty($arrTemp[$detail['category_id']]['full_parent_original'])) {
                         foreach ($arrTemp[$detail['category_id']]['full_parent_original'] as $intParentId) {
                             //if not SITE_ID (cate_id=parent_id)
                             if ($intParentId != $detail['category_id']) {
                                 //update child
                                 $arrTemp[$intParentId]['child_recursive'][] = $detail['category_id'];
                                 $arrFullCatInfo[$intParentId]['child_recursive'][] = $detail['category_id'];
                             }
                             //end if
                         }
                         //end foreach
                         //update current cate child list
                         if ($intParentId != $detail['category_id']) {
                             $arrTemp[$detail['parent_id']]['child'][$detail['category_id']] = $detail;
                             $arrFullCatInfo[$detail['parent_id']]['child'][] = $detail['category_id'];
                         }
                         //end if
                     }
                     //end if
                 }
                 //end foreach
                 //format output
                 $arrMenuCate['menu'] = array(SITE_ID => $arrTemp[SITE_ID]);
                 $arrMenuCate['cate'] = $arrFullCatInfo;
                 //wriet memcache
                 $memcacheInstance->write($keyCache, $arrMenuCate);
                 //check from job to write memcached hcm
                 if ($preCache) {
                     Thethao_Global::writeMemcache($keyCache, $arrMenuCate, 'all');
                 }
                 //end if
             }
             //end if
         }
         //end if
         $this->_menu = $arrMenuCate['menu'];
         $this->_cate = $arrMenuCate['cate'];
     }
     //end if
     return $this->_cate;
 }
コード例 #7
0
ファイル: Tennis.php プロジェクト: Nhan-Huynh-FO/nhan-repo
 /**
  * Get tennis table ranking from cache.<br />
  * If miss cache => get data from database and write cache.
  * @param int $gender Only 0 or 1. 0 => woman (WTA), 1 => man (ATP)
  * @param int|NULL $year  If this parameter is NULL, that means current year
  * @return array|boolean
  * @author QuangTM
  */
 public function getTennisTableRanking($gender, $year = NULL)
 {
     // Create validate
     $validInt = new Zend_Validate_Int();
     // Validate gender
     if (!$validInt->isValid($gender) || $gender < 0 || $gender > 1) {
         return FALSE;
     }
     // Standardized year
     $currentYear = intval(date('Y'));
     if ($year == NULL) {
         $year = $currentYear;
     }
     // Validate year
     if (!$validInt->isValid($year) || $year > $currentYear) {
         return FALSE;
     }
     // Create key cache about tennis player
     $keyTableRanking = vsprintf($this->_table_ranking, array($gender, $year));
     // Get memcache instance
     $memcacheInstance = Thethao_Global::getCache();
     // Read data from cache
     $tableRanking = $memcacheInstance->read($keyTableRanking);
     // If miss cache
     if ($tableRanking === FALSE) {
         // Get table ranking from DB
         $tableRanking = $this->_getTennisTableRankingFromDb($gender, $year);
         // Write cache
         if (is_array($tableRanking) && count($tableRanking)) {
             $memcacheInstance->write($keyTableRanking, $tableRanking);
             Thethao_Global::writeMemcache($keyTableRanking, $tableRanking);
         } else {
             $memcacheInstance->write($keyTableRanking, -1);
             Thethao_Global::writeMemcache($keyTableRanking, -1);
         }
     }
     // Return table ranking
     if ($tableRanking == -1) {
         return array('table' => NULL, 'updateTime' => NULL);
     }
     return $tableRanking;
 }
コード例 #8
0
ファイル: Block.php プロジェクト: Nhan-Huynh-FO/nhan-repo
 /**
  * Function get data from table keybox by key_box_id
  * @param array $params
  * @return array data
  */
 public function getKeyBox($params)
 {
     try {
         // Build key cache
         $keyCache = Thethao_Global::makeCacheKey($params['key_id']);
         if (!$keyCache) {
             $keyCache = $params['key_id'];
         }
         // Get instance memcache
         $memcacheInstance = Thethao_Global::getCache();
         // Read hot match in memcache
         $arrReturn = $memcacheInstance->read($keyCache);
         //check cache
         if ($arrReturn === FALSE) {
             //get app config
             $config = Thethao_Global::getApplicationIni();
             //get mysql instance
             $mysqlInstance = $this->factory('Block', $config['database']['default']['adapter']);
             // Get data in DB
             $arrReturn = $mysqlInstance->getKeyBox('"' . $params['key_id'] . '"');
             //Decode Json for write memcache
             $arrReturn = Zend_Json::decode($arrReturn[$params['key_id']]);
             if (!empty($arrReturn)) {
                 // Store into cache
                 $memcacheInstance->write($keyCache, $arrReturn);
                 Thethao_Global::writeMemcache($keyCache, $arrReturn);
             } else {
                 // Store into cache
                 $memcacheInstance->write($keyCache, -1);
                 Thethao_Global::writeMemcache($keyCache, -1);
             }
         } else {
             if ($arrReturn == -1) {
                 $arrReturn = array();
             }
         }
     } catch (Exception $ex) {
         //log error
         Thethao_Global::sendLog($ex);
     }
     return $arrReturn;
 }