public function get_my_voices($bundle = array()) { // set return result $result = array("status" => true, "message" => "", "is_data" => false, "is_more_data" => false, "data" => array()); // get valid logging id $uid = $this->get_logged_uid(); // first user is valid if ($uid) { $start = c_pick_param($bundle, "start", 0); $limit = c_pick_param($bundle, "limit", 10); // calculate start $next_start = ($start + 1) * $limit; $start = $start * $limit; $query = "SELECT * FROM user_voices WHERE user_id=%d AND is_blocked=0 ORDER BY id DESC LIMIT %d, %d"; $sql = sprintf($query, $uid, $start, $limit); $bundle = array("sql" => $sql); // get voices $voices = $this->get_voices($bundle); $result["is_more_data"] = $this->is_more_data(sprintf($query, $uid, $next_start, $limit)); $result["status"] = $voices["status"]; $result["message"] = $voices["message"]; $result["is_data"] = $voices["is_data"]; $result["data"] = $voices["data"]; } else { $result["status"] = false; $result["message"] = "User ID is not valid"; } // return result with info return $result; }
public function get_feeds($bundle = array()) { // set return result $result = array("status" => true, "message" => "", "is_data" => false, "is_more_data" => false, "data" => array()); $start = c_pick_param($bundle, "start", 0); $limit = c_pick_param($bundle, "limit", 10); // calculate start $next_start = ($start + 1) * $limit; $start = $start * $limit; $query = "\n SELECT \n\n voices.`id` AS id, \n voices.`user_id` AS user_id, \n voices.`voice_cat_id` AS cat_id,\n voices.`voice_tag_ids` AS tag_ids,\n voices.`question_text` AS title,\n voices.`voice_details` AS details,\n voices.`voice_pic` AS eco_pic,\n voices.`is_blocked` AS is_blocked,\n voices.`added_on` AS created_on,\n 'voice' AS data_type\n \n FROM user_voices AS voices\n WHERE voices.`is_blocked`=0\n \n UNION \n SELECT \n \n streams.`id` AS id, \n streams.`user_id` AS user_id,\n streams.`voice_cat_id` AS cat_id,\n streams.`voice_tag_ids` AS tag_ids,\n streams.`question_text` AS title,\n streams.`voice_details` AS details,\n streams.`voice_pic` AS eco_pic,\n streams.`is_blocked` AS is_blocked,\n streams.`added_on` AS created_on,\n 'stream' AS data_type\n \n FROM streams_voice AS streams\n WHERE streams.`is_blocked`=0\n \n UNION\n SELECT\n \n eco.`id` AS id,\n eco.`moderator_id` AS user_id,\n eco.`voice_cat_id` AS cat_id,\n eco.`voice_tag_ids` AS tag_ids,\n eco.`title` AS title,\n eco.`description` AS details,\n eco.`eco_pic` AS eco_pic,\n eco.`is_admin_blocked` AS is_blocked,\n eco.`created_on` AS created_on,\n CASE\n WHEN eco.`level`=1 THEN 'stream'\n WHEN eco.`level`=2 THEN 'river'\n WHEN eco.`level`=3 THEN 'ocean'\n END\n AS data_type\n \n FROM eco_system AS eco\n \n WHERE eco.`level`!=1\n AND eco.`is_admin_blocked`=0\n \n ORDER BY created_on DESC\n LIMIT %d, %d"; $sql = sprintf($query, $start, $limit); $bundle = array("sql" => $sql); // get feeds $feeds = $this->get_voices($bundle); $result["is_more_data"] = $this->is_more_data(sprintf($query, $next_start, $limit)); $result["status"] = $feeds["status"]; $result["message"] = $feeds["message"]; $result["is_data"] = $feeds["is_data"]; $result["data"] = $feeds["data"]; // return result with info return $result; }
public function get_eco_comments($bundle = array()) { // set return result $result = array("status" => true, "message" => "", "is_data" => false, "is_more_data" => false, "data" => array()); $id = c_pick_param($bundle, "id", 0); $start = c_pick_param($bundle, "start", 0); $limit = c_pick_param($bundle, "limit", 10); if ($this->is_valid_river($id)) { // calculate start $next_start = ($start + 1) * $limit; $start = $start * $limit; $query = "SELECT * FROM eco_discussion_comments WHERE eco_sys_id=%d ORDER BY id DESC LIMIT %d, %d"; $sql = sprintf($query, $id, $start, $limit); $bundle = array("sql" => $sql); // get comments $comments = $this->get_comments_data($bundle); $result["is_more_data"] = $this->is_more_data(sprintf($query, $id, $next_start, $limit)); $result["status"] = $comments["status"]; $result["message"] = $comments["message"]; $result["is_data"] = $comments["is_data"]; $result["data"] = $comments["data"]; } else { $result['status'] = false; $result['message'] = "Invalid river id."; } // return result with info return $result; }
public function get_comments_data($bundle = array()) { // set return result $result = array("status" => true, "message" => "", "is_data" => false, "data" => array()); $sql = c_pick_param($bundle, "sql", "SELECT * FROM eco_discussion_comments"); $query = $this->db->query($sql); // check query have data if ($query->num_rows() > 0) { $result["message"] = "Data successfully load."; $result["is_data"] = true; $result["data"] = $query->result_array(); } else { $result["message"] = "There is no data available."; } // return result return $result; }