/** * Get list article ids by rule 1, set on folder * @param type $arrParams * @return type array * @author HungNT1 */ public function getListArticleIdsByRule1($arrParams) { if (!isset($arrParams['article_type']) || $arrParams['article_type'] == 0) { $arrParams['article_type'] = NULL; } $site_id = $arrParams['category_id'] == SITE_ID ? NULL : SITE_ID; $arrResult = array('total' => 0, 'data' => array()); $arrParams['from_date'] = isset($arrParams['from_date']) ? $arrParams['from_date'] : NULL; $arrParams['to_date'] = isset($arrParams['to_date']) ? $arrParams['to_date'] : NULL; try { // Get DB $db_s = Thethao_Global::getDB('sport', 'slave'); $stmt = $db_s->prepare('CALL sp_getNewsByRule1(:p_siteid, :p_categoryid, :p_articletype, :p_fromdate, :p_todate, :p_offset, :p_LIMIT)'); //Bind param $stmt->bindParam('p_siteid', $site_id); $stmt->bindParam('p_categoryid', $arrParams['category_id']); $stmt->bindParam('p_articletype', $arrParams['article_type'], PDO::PARAM_STR); $stmt->bindParam('p_fromdate', $arrParams['from_date'], PDO::PARAM_INT); $stmt->bindParam('p_todate', $arrParams['to_date'], PDO::PARAM_INT); $stmt->bindParam('p_offset', $arrParams['offset'], PDO::PARAM_INT); $stmt->bindParam('p_LIMIT', $arrParams['limit'], PDO::PARAM_INT); // Fetch result $stmt->execute(); while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $arrResult['data'][$row['article_id']] = $row['score']; } // Close cursor $stmt->closeCursor(); // Query total row $stmt = $db_s->prepare('CALL sp_getTotalByRule1(:p_siteid, :p_categoryid, :p_articletype, :p_fromdate, :p_todate)'); // Bind param $stmt->bindParam('p_siteid', $site_id); $stmt->bindParam('p_categoryid', $arrParams['category_id']); $stmt->bindParam('p_articletype', $arrParams['article_type'], PDO::PARAM_STR); $stmt->bindParam('p_fromdate', $arrParams['from_date'], PDO::PARAM_INT); $stmt->bindParam('p_todate', $arrParams['to_date'], PDO::PARAM_INT); // Exec func $stmt->execute(); // Fetch total $arrResult['total'] = $stmt->fetchColumn(); // Release unset($stmt); } catch (Zend_Exception $ex) { Fpt_Data_Model::sendLog($ex); } return $arrResult; }
/** * write log file to send mail * @param Exception $ex * @param int $level * @return null * @author LamTX */ public static function sendLog($ex, $message = '', $trace = '', $errorCode = 0, $intAction = 0) { try { if (APPLICATION_ENV == 'development') { var_dump('<pre><br><br><h2>' . $ex->getMessage() . '<br></h2><br>' . $ex->getTraceAsString() . '<br>'); return; } Fpt_Data_Model::sendLog($ex); } catch (Exception $ex) { return false; } }
/** * Get list match ids by league * @param int $teamID * @param int $beginHappenDateTime * @param int $endHappenDateTime * @param boolean - asort array * @return array|boolean * @author ThuyNT */ public function getMatchIDsByLeague($leagueID, $beginHappenDateTime = NULL, $endHappenDateTime = NULL, $rev = TRUE) { // Default result to return $result = FALSE; $flag = TRUE; try { // Get application config $config = Thethao_Global::getApplicationIni(); //get object redis $matchNosqlInstance = $this->factory('Match', $config['database']['nosql']['adapter']); // Read from redis first $result = $matchNosqlInstance->getListMatchesByHappenTime($leagueID, $beginHappenDateTime, $endHappenDateTime); // If miss cache redis => read from DB if (empty($result['data']) && FROM_JOB == 1) { //get mysql instance $matchMysqlInstance = $this->factory('Match', $config['database']['default']['adapter']); // Read data from MySQL $result = $matchMysqlInstance->getListMatchesByHappenTime($beginHappenDateTime, $endHappenDateTime, $leagueID, $gmt = 0, $flag); //check to set redis if (!empty($result)) { $matchNosqlInstance->setMatchIDsByLeague($leagueID, $result); } $intTotal = count($result); $arrTest = array_values($result); if ($beginHappenDateTime) { for ($i = $intTotal - 1; $i > 0; $i--) { if ($arrTest[$i] >= $beginHappenDateTime) { $result = array_slice($result, 0, $i + 1, true); $i = 0; } } } if ($endHappenDateTime) { for ($i = 0; $i < $intTotal; $i++) { if ($arrTest[$i] <= $endHappenDateTime) { $result = array_slice($result, $i, NULL, true); $i = $intTotal; } } } } else { $result = $result['data']; } if (!$rev && !empty($result)) { asort($result); } } catch (Exception $ex) { Fpt_Data_Model::sendLog($ex); } return $result; }
/** * Get detail player by id * @param int $player_id, $type * @return array|boolean * @author QuangTM */ public function getDetailPlayerByID($player_id, $type) { try { // Get DB Obj $dbObj = Thethao_Global::getDB('sport', 'slave'); $stmt = $dbObj->prepare('Call sp_sport_gePlayerAwardByType(:p_playerid,:p_type);'); // bind params $stmt->bindParam('p_playerid', $player_id, PDO::PARAM_INT); $stmt->bindParam('p_type', $type, PDO::PARAM_INT); // execute $stmt->execute(); //Fetch Result $result = $stmt->fetchAll(); // Close cursor $stmt->closeCursor(); // Release unset($stmt); //Return array return $result; } catch (Exception $ex) { Fpt_Data_Model::sendLog($ex); return FALSE; } }
/** * Get extend of match detail * @param type $arrMatchId * @return boolean|array */ public function getMatchExtendByIDs($arrMatchId) { $result = array(); try { if (!is_array($arrMatchId) || !count($arrMatchId)) { return FALSE; } $strMatchId = implode(',', $arrMatchId); // Get DB Obj $dbObj = Thethao_Global::getDB('sport', 'slave'); // Prepare SQL $stmt = $dbObj->prepare('CALL sp_fesport_getDetailMatchByIDs(:p_matchids);'); // Bind param $stmt->bindParam('p_matchids', $strMatchId, PDO::PARAM_STR); // Execute $stmt->execute(); while ($row = $stmt->fetch()) { if (!isset($result[$row['match_id']])) { $result[$row['match_id']] = array(); } $result[$row['match_id']] = Zend_Json::decode($row['event']); } // Close $stmt->closeCursor(); // Release variables unset($stmt); } catch (Exception $ex) { Fpt_Data_Model::sendLog($ex); return FALSE; } return $result; }