private function updateAvgRating($content_id) { $chk = GenFun::error_chk(array($this->setRating_tbl, $this->avgRating_tbl)); //---------------------------------------------------------- if (!$chk['bool']) { return $chk; } //---------------------------------------------------------- $queryString = "UPDATE " . $this->avgRating_tbl . " SET " . $this->avgRating_tbl . ".avg_rating = (SELECT AVG(" . $this->setRating_tbl . ".rating) FROM " . $this->setRating_tbl . " WHERE content_id = '{$content_id}') WHERE " . $this->avgRating_tbl . ".id = '{$content_id}'"; $chk = Result::go($queryString, array('resetQueries' => true)); //---------------------------------------------------------- return $chk; }
private function getAccountRow($hash) { //---------------------------------------------------------- //init var //---------------------------------------------------------- $chk = array("bool" => true, 'traceID' => "getAccountRow"); //----------------------------------------------------------' $queryString = "SELECT forgotPwRequest.* FROM forgotPwRequest, accounts, confirmLinks WHERE confirmLinks.hash= '{$hash}' AND confirmLinks.disabled= '0' AND forgotPwRequest.accounts_id = accounts.id And confirmLinks.confirming_id = forgotPwRequest.id"; //---------------------------------------------------------- if (Constants::$debug) { $chk["queryString"] = $queryString; } //---------------------------------------------------------- $chk = Result::go($queryString); //---------------------------------------------------------- return $chk; }
private function _getTopComments($content_id = NULL, $returnQuery = NULL) { //---------------------------------------------------------- //init var //---------------------------------------------------------- $queryString = AddToQuery::go($this->commentMngr->_getComments($content_id, NULL, NULL, true, false), array("{last}AND" => " topComments.comments_id = comments.id AND ", "FROM" => " topComments, ")); //---------------------------------------------------------- $resultObj = array_merge(array('returnQuery' => $returnQuery), $this->resultObj); //---------------------------------------------------------- $chk = Result::go($queryString, $this->resultObj); //---------------------------------------------------------- $chk['result'] = $this->commentMngr->getReplies($chk['result']); //---------------------------------------------------------- return $chk; }
public function searchCampaigns($search) { //---------------------------------------------------------- //init var //---------------------------------------------------------- $getTotalRows = NULL; $chk = array("bool" => true, 'result' => array(), "func" => "searchCampaigns"); $mysqli = new mysqli("127.0.0.1:9306"); $resultObj = array_merge(array("mysqli" => $mysqli, 'returnQuery' => $returnQuery), $this->resultObj); //---------------------------------------------------------- if (isset($resultObj['getTotalRows'])) { $getTotalRows = true; unset($resultObj['getTotalRows']); } //---------------------------------------------------------- $queryString = "\r\n\t\t\tselect * \r\n\t\t\tFROM \r\n\t\t\tprojects,\r\n\t\t\tcampaigns,\r\n\t\t\tcomments\r\n\t\t\tWHERE \r\n\t\t\tMATCH('" . $search . "*') \r\n\t\t"; //---------------------------------------------------------- $resultObj['addToQuery'] = array("{end}" => " \r\n\t\t\tOPTION \r\n\t\t\tranker=bm25, \r\n\t\t\tmax_matches=15,\r\n\t \tfield_weights=(name=1, comment=10)\r\n\t "); //---------------------------------------------------------- $chk = Result::go($queryString, $resultObj); //---------------------------------------------------------- if (!is_null($getTotalRows)) { $total = Result::go(str_replace("select *", "select COUNT(*)", $queryString), array("mysqli" => $mysqli)); $chk['totalRows'] = $total['result'][0]['count(*)']; } //---------------------------------------------------------- return $chk; }
public function _getComments($content_id = NULL, $comment_id = NULL, $reply_comments_id = NULL, $returnQuery = NULL, $withReplies = true, $setResultObj = true) { //---------------------------------------------------------- //init var //---------------------------------------------------------- $resultObj = array("chkForQuery" => true, 'returnQuery' => $returnQuery); $resultObj = $setResultObj ? array_merge($resultObj, $this->resultObj) : $resultObj; $chk = array("bool" => true, "traceID" => "getComments"); //---------------------------------------------------------- //Select comments.*, agreeWith.accounts_id as shit FROM comments LEFT JOIN agreeWith ON agreeWith.accounts_id = 125 AND agreeWith.comments_id = comments.id $queryString = "Select "; $queryString .= "CONCAT(accounts.first,' ',accounts.last) as name, "; $queryString .= "comments.reply_comments_id, "; $queryString .= "comments.content_id, "; $queryString .= "comments.id,"; //$queryString .= "Count(*) as num_agree from (Select agreeWith.* From agreeWith where agreeWith.comments_id = 150) as t $queryString .= "comments.accounts_id, "; $queryString .= "CONCAT('" . $this->thumbPath . "',files.hash,'/', files.name) as img_url, "; $queryString .= "comments.comment, "; $queryString .= "comments.avg_rating, "; $queryString .= "comments.date "; $queryString .= "FROM "; $queryString .= "comments, "; $queryString .= "accounts, "; $queryString .= "files "; $queryString .= "WHERE "; $queryString .= "accounts.id = comments.accounts_id AND "; $queryString .= "files.id = accounts.profile_files_id AND "; if (!is_null($content_id)) { $queryString .= "comments.content_id = {$content_id} AND "; } $queryString .= "comments.disabled is NULL "; $queryString .= "Group by comments.id "; $queryString .= "ORDER BY comments.id DESC"; //SELECT agreeWith.comments_id FROM agreeWith,comments Where agreeWith.comments_id = 156 AND agreeWith.accounts_id = 125 Group BY comments.id //---------------------------------------------------------- //if (!is_null($content_id)) $queryString = AddToQuery::go($queryString, array("{last}AND" => " comments.content_id = $content_id AND ")); //---------------------------------------------------------- if (is_null($reply_comments_id)) { if (is_null($comment_id)) { $queryString = AddToQuery::go($queryString, array("{last}AND" => " comments.reply_comments_id IS NULL AND ")); } } else { $queryString = AddToQuery::go($queryString, array("{last}AND" => " comments.reply_comments_id = {$reply_comments_id} AND ")); } //---------------------------------------------------------- if (!is_null($comment_id)) { $queryString = AddToQuery::go($queryString, array("{last}AND" => " comments.id = {$comment_id} AND ")); } //---------------------------------------------------------- $chk = Result::go($queryString, $resultObj); //---------------------------------------------------------- if (sizeof($chk['result']) == 0) { return $chk; } //---------------------------------------------------------- if ($withReplies) { $chk = $this->getReplies($chk); } //---------------------------------------------------------- return $chk; }
private function _getLooks($orderBy = "false", $limitFrom = NULL, $limitTo = NULL) { //---------------------------------------------------------- //init var //---------------------------------------------------------- $chk = array("bool" => 1); //---------------------------------------------------------- $num = !is_null($limitFrom) ? $limitFrom : 0; //---------------------------------------------------------- $queryString = $orderBy == "true" ? "SELECT * FROM (" : ""; $queryString .= "SELECT * FROM ("; $queryString .= "SELECT " . Mstyle_031312::TBL_LOOKS . "." . Mstyle_031312::CLM_VOTES . ","; $queryString .= Mstyle_031312::TBL_LOOKS . "." . Mstyle_031312::CLM_ID . ","; $queryString .= Mstyle_031312::TBL_LOOKS . "." . Mstyle_031312::CLM_NAME . ","; $queryString .= Mstyle_031312::TBL_LOOKS . "." . Mstyle_031312::CLM_STYLE . ","; $queryString .= "CONCAT('{$this->absolute}', " . Mstyle_031312::TBL_LOOKS . "." . Mstyle_031312::CLM_IMAGE . ") as image,"; $queryString .= "CONCAT('{$this->absolute}', " . Mstyle_031312::TBL_LOOKS . "." . Mstyle_031312::CLM_THUMBNAIL . ") as thumbnail,"; $queryString .= "DATE_FORMAT(" . Mstyle_031312::TBL_LOOKS . "." . Mstyle_031312::CLM_DATETIME . ",'%M %e, %Y, %l:%i%p') as dateTimeFormat"; $queryString .= " FROM " . Mstyle_031312::TBL_LOOKS; $queryString .= " ORDER BY " . Mstyle_031312::CLM_DATETIME . " DESC"; $queryString .= ") table1 "; $queryString .= "UNION ALL "; $queryString .= "SELECT * FROM ("; $queryString .= "SELECT " . Mstyle_031312::TBL_MACYSLOOKS . "." . Mstyle_031312::CLM_VOTES . ","; $queryString .= Mstyle_031312::TBL_MACYSLOOKS . "." . Mstyle_031312::CLM_ID . ","; $queryString .= Mstyle_031312::TBL_MACYSLOOKS . "." . Mstyle_031312::CLM_NAME . ","; $queryString .= Mstyle_031312::TBL_MACYSLOOKS . "." . Mstyle_031312::CLM_STYLE . ","; $queryString .= "CONCAT('{$this->absolute}', " . Mstyle_031312::TBL_MACYSLOOKS . "." . Mstyle_031312::CLM_IMAGE . ") as image,"; $queryString .= "CONCAT('{$this->absolute}', " . Mstyle_031312::TBL_MACYSLOOKS . "." . Mstyle_031312::CLM_THUMBNAIL . ") as thubmnail,"; $queryString .= "DATE_FORMAT(" . Mstyle_031312::TBL_MACYSLOOKS . "." . Mstyle_031312::CLM_DATETIME . ",'%M %e, %Y, %l:%i%p') as dateTimeFormat"; $queryString .= " FROM " . Mstyle_031312::TBL_MACYSLOOKS; $queryString .= " ORDER BY " . Mstyle_031312::CLM_ID . " DESC"; $queryString .= ") table2"; $queryString .= $orderBy == "true" ? ")table3 ORDER BY " . Mstyle_031312::CLM_VOTES . " DESC" : ""; $result = Result::go($queryString); //---------------------------------------------------------- if (sizeof($result) > 0) { //------------------------------------------------------ $commentsArr = array(); //------------------------------------------------------ foreach ($result['result'] as $row) { $chk = $this->_getTotal(); //-------------------------------------------------- if ((bool) $chk["bool"]) { $row["index"] = $chk["result"] - $num; $row["image"] = $row["image"]; $row["thumbnail"] = $row["thumbnail"]; array_push($commentsArr, $row); $num++; } else { break; } } //------------------------------------------------------ $json = json_encode(array("item" => $commentsArr)); if ((bool) $chk["bool"]) { $chk["result"] = $this->json_to_xml($json); } } else { $chk["bool"] = "0"; } //---------------------------------------------------------- $chk["func"] = $this->traceID . ": _getLooks"; //---------------------------------------------------------- return $chk; }
private function getAccountRow($hash) { //---------------------------------------------------------- //init var //---------------------------------------------------------- $chk = array("bool" => true, 'traceID' => "getAccountRow"); //----------------------------------------------------------' $queryString = "\n\t\tSELECT \n\t\taccounts.id, \n\t\t" . $this->confirmLinkTbl . ".disabled \n\t\tFROM \n\t\taccounts, \n\t\t" . $this->confirmLinkTbl . " \n\t\tWHERE " . $this->confirmLinkTbl . ".hash= '{$hash}' \n\t\tAND " . $this->confirmLinkTbl . ".disabled IS NULL \n\t\tAnd " . $this->confirmLinkTbl . ".accounts_id = accounts.id"; //---------------------------------------------------------- if (Constants::$debug) { $chk["queryString"] = $queryString; } //---------------------------------------------------------- $chk = Result::go($queryString); //---------------------------------------------------------- return $chk; }
private function _insertContents($dirArray, $close = FALSE) { Trace::output($this->traceID, "_insertContents"); //---------------------------------------------------------- //init var //---------------------------------------------------------- $i; $queryString = ""; $chk = array("bool" => true, 'function' => "_insertContents"); //---------------------------------------------------------- for ($i = 0; $i < sizeof($dirArray); $i++) { $queryString .= 'CALL insertVideo("' . $dirArray[$i]['title'] . '","' . $dirArray[$i]['hash'] . '","' . $dirArray[$i]['mp4'] . '","' . $dirArray[$i]['thumbnail_url'] . '"); '; } //---------------------------------------------------------- $chk = Result::go($queryString); krumo($chk); //---------------------------------------------------------- return Constants::$mysqli->escape_string($queryString); }
public function _getComments($content_id = NULL, $comment_id = NULL, $reply_comments_id = NULL, $returnQuery = NULL) { //---------------------------------------------------------- //init var //---------------------------------------------------------- $resultObj = array_merge(array("chkForQuery" => true, 'returnQuery' => $returnQuery), $this->resultObj); $chk = array("bool" => true, "traceID" => "getComments"); //---------------------------------------------------------- $queryString = "Select CONCAT(accounts.first,' ',accounts.last) as name, "; $queryString .= $this->contentComments_tbl . ".reply_comments_id, comments.id, "; $queryString .= $this->contentComments_tbl . ".content_id, files.name as img_url, comments.comment, comments.avg_rating, comments.date FROM "; $queryString .= $this->contentComments_tbl . ", accounts, files, comments WHERE "; $queryString .= $this->contentComments_tbl . ".comments_id = comments.id AND files.id = accounts.profile_files_id AND "; $queryString .= "comments.accounts_id = accounts.id AND "; $queryString .= $this->contentComments_tbl . ".disabled is NULL Group by comments.id ORDER BY comments.id DESC"; //---------------------------------------------------------- if (!is_null($content_id)) { $queryString = AddToQuery::go($queryString, array("{last}AND" => " " . $this->contentComments_tbl . ".content_id = {$content_id} AND " . $this->contentComments_tbl . ".reply_comments_id IS NULL AND ")); } //---------------------------------------------------------- if (!is_null($reply_comments_id)) { $queryString = AddToQuery::go($queryString, array("{last}AND" => " " . $this->contentComments_tbl . ".reply_comments_id = {$reply_comments_id} AND ")); } //---------------------------------------------------------- if (!is_null($comment_id)) { $queryString = AddToQuery::go($queryString, array("{last}AND" => " comments.id = {$comment_id} AND ")); } //---------------------------------------------------------- $chk = Result::go($queryString, $resultObj); //---------------------------------------------------------- //$totalRows = $chk['totalRows']; //unset($resultObj['getTotalRows']); //---------------------------------------------------------- if (sizeof($chk['result']) == 0) { return $chk; } //---------------------------------------------------------- $chk['result'] = $this->encodeResult($chk['result']); //---------------------------------------------------------- //if ($chk['bool'] && is_null($reply_comments_id)) $chk = $this->getReplies($chk['result']); //---------------------------------------------------------- //$chk['totalRows'] = $totalRows; //---------------------------------------------------------- return $chk; }
public function getTeamParticipants($event_id, $limitFrom = NULL, $limitTo = NULL, $returnQuery = NULL) { $arr = array("from" => "events, rosterPresets,eventParticipants,"); $arr['condition'] = "rosterPresets.id = eventParticipants.rosterPresets_id AND rosterPresets.teams_id = teams.id AND eventParticipants.events_id = events.id AND"; //---------------------------------------------------------- $queryString = AddToQuery::getQuery($this->getTeams(NULL, $limitFrom, $limitTo, true), $arr); //---------------------------------------------------------- if (is_null($returnQuery)) { $chk = Result::go($queryString); } else { return $queryString; } //---------------------------------------------------------- return $chk; }
public function getTagsConcat($id, $returnQuery = false) { //---------------------------------------------------------- //init var //---------------------------------------------------------- $resultObj = array_merge(array("chkForQuery" => true, 'returnQuery' => $returnQuery), $this->resultObj); //---------------------------------------------------------- $queryString = "SELECT GROUP_CONCAT(DISTINCT keywords.word SEPARATOR ' ') AS tags_concat FROM setKeywords, keywords WHERE setKeywords.disabled IS NULL AND setKeywords.keywords_id = keywords.id AND setKeywords.videos_id = {$id} "; //---------------------------------------------------------- if ($returnQuery) { return $queryString; } else { $chk = Result::go($queryString, $resultObj); } //---------------------------------------------------------- return $chk; }
public function getResult() { if (is_null($this->mysqli)) { $this->mysqli = GlobalMas::$mysqli; } //---------------------------------------------------------- //init var //---------------------------------------------------------- $chk = array("bool" => true, 'traceID' => "getResult"); $update = false; //---------------------------------------------------------- if ($this->returnQuery) { return $this->queryString; } //---------------------------------------------------------- $chk = GenFun::debugChk($chk, array("queryString" => $this->queryString)); //---------------------------------------------------------- $debug = GlobalMas::$debug; //---------------------------------------------------------- if ($this->chkForQuery) { $query_chk = Result::go("SELECT queries.result, queries.last_update FROM queries WHERE queries.query = '" . $this->mysqli->escape_string($this->queryString) . "'"); //------------------------------------------------------ if (sizeof($query_chk['result']) > 0) { if (empty($query_chk['result'][0]['last_update']) || is_null($query_chk['result'][0]['last_update'])) { $update = true; } if (!$update) { $chk = json_decode($query_chk['result'][0]['result'], true); //---------------------------------------------- $chk = self::debug_chk($chk); //---------------------------------------------- return $chk; } } } //---------------------------------------------------------- $result = $this->multi ? $this->mysqli->multi_query($this->queryString) : $this->mysqli->query($this->queryString); //---------------------------------------------------------- if (!$result) { $chk['bool'] = false; $chk['error'] = false; $chk = GenFun::debugCHK($chk, array('message' => $this->mysqli->error)); if (strpos($chk['message'], "Duplicate") !== false) { return $chk['duplicate'] = true; } } //---------------------------------------------------------- if ($this->multi) { $result = $this->getMultiQueryResult($result); } else { $result = $this->getSingleQueryResult($result); //---------------------------------------------- if ($this->greaterZero) { if (sizeof($result) == 0) { $chk['bool'] = false; } } } $chk['result'] = $result; //---------------------------------------------------------- $this->insert_id = $this->mysqli->insert_id; $chk['insert_id'] = $this->insert_id; //-------------------------------------------------- if ($this->chkForQuery) { $queryString = $this->mysqli->real_escape_string($this->queryString); $resultString = $this->mysqli->real_escape_string(json_encode($chk)); if (!$update) { $query_chk = Result::go("INSERT INTO queries (query, result)\r\n\t\t\t\t SELECT * FROM (SELECT '" . $queryString . "', '" . $resultString . "') AS tmp\r\n\t\t\t\tWHERE NOT EXISTS (\r\n\t\t\t\t\tSELECT query FROM queries WHERE query = '" . $queryString . "'\r\n\t\t\t\t) LIMIT 1"); } else { $query_chk = Result::go("UPDATE queries SET queries.query = '" . $queryString . "', queries.result = '" . $resultString . "', queries.last_update = NOW() WHERE queries.query = '" . $queryString . "'"); } //---------------------------------------------- GlobalMas::$debug = $debug; } //------------------------------------------------------ $chk = self::debug_chk($chk); //------------------------------------------------------ if ($this->resetQueries) { $chk['resetQueries'] = Result::resetQueries(); } //------------------------------------------------------ return $chk; }
public function getResult() { //---------------------------------------------------------- //init var //---------------------------------------------------------- $chk = array("bool" => true, 'traceID' => "getResult"); $update = false; //---------------------------------------------------------- if ($this->returnQuery) { return $this->queryString; } //---------------------------------------------------------- $chk = GenFun::debugChk($chk, array("queryString" => $this->queryString)); //---------------------------------------------------------- $debug = Constants::$debug; //---------------------------------------------------------- if ($this->chkForQuery) { $query_chk = Result::go("SELECT queries.result, queries.last_update FROM queries WHERE queries.query = '" . Constants::$mysqli->escape_string($this->queryString) . "'"); //------------------------------------------------------ if (sizeof($query_chk['result']) > 0) { if (empty($query_chk['result'][0]['last_update']) || is_null($query_chk['result'][0]['last_update'])) { $update = true; } if (!$update) { $chk = json_decode($query_chk['result'][0]['result'], true); //---------------------------------------------- $chk = self::debug_chk($chk); //---------------------------------------------- return $chk; } } } //---------------------------------------------------------- $result = $multi ? Constants::$mysqli->multi_query($this->queryString) : Constants::$mysqli->query($this->queryString); //---------------------------------------------------------- if ($result) { $chk['bool'] = true; $arr = array(); if ($result) { if ($multi) { $result = Constants::$mysqli->use_result(); } //-------------------------------------------------- if ($result && is_object($result)) { while ($row = $result->fetch_assoc()) { array_push($arr, $row); } //---------------------------------------------- if ($this->greaterZero) { if (sizeof($arr) == 0) { $chk['bool'] = false; } } //---------------------------------------------- $chk['result'] = $arr; } } //Constants::$debug = false; //-------------------------------------------------- if ($this->chkForQuery) { $queryString = Constants::$mysqli->real_escape_string($this->queryString); $resultString = Constants::$mysqli->real_escape_string(json_encode($chk)); if (!$update) { $query_chk = Result::go("INSERT INTO queries (query, result)\n\t\t\t\t\t SELECT * FROM (SELECT '" . $queryString . "', '" . $resultString . "') AS tmp\n\t\t\t\t\tWHERE NOT EXISTS (\n\t\t\t\t\t\tSELECT query FROM queries WHERE query = '" . $queryString . "'\n\t\t\t\t\t) LIMIT 1"); } else { $query_chk = Result::go("UPDATE queries SET queries.query = '" . $queryString . "', queries.result = '" . $resultString . "', queries.last_update = NOW() WHERE queries.query = '" . $queryString . "'"); } //---------------------------------------------- Constants::$debug = $debug; } } else { $chk['bool'] = false; $chk['error'] = true; $chk = GenFun::debugCHK($chk, array('message' => Constants::$mysqli->error)); if (strpos($chk['message'], "Duplicate") !== false) { $chk['duplicate'] = true; } } //------------------------------------------------------ $chk = self::debug_chk($chk); //------------------------------------------------------ if ($this->resetQueries) { $chk['resetQueries'] = $this->resetQueries_CFG(); } //------------------------------------------------------ return $chk; }