/** * Select all objects from the database where the WHERE clause is entirely true. * Every argument will match a value in a column in the database. * @param DAO $dao a reference to a instance of DAO * @param string $table the name of the table of the objects * @param array $keys the associative array naming the properties of these objects for selection * @param array $where the associative array describing the properties of these objects (used in the WHERE clause) * @return array An array of DataObject instances with the variables specified in $assoc which can * be committed to the table $table. */ static function select_all($dao, $table, $keys, $where) { $obj = new DataObject(); $obj->table = $table; $obj->dao = $dao; //Reference to the dao stored $obj->update = true; //This will be updated on commit $objects = array(); $query_where = $obj->key_values($where); $query_part = implode(",", $keys); $query = "SELECT " . $query_part . " FROM " . $table . " WHERE " . implode(" AND ", $query_where) . " ORDER BY " . $keys[0] . " DESC;"; $dao->myquery($query); $query_objects = $dao->fetch_all_part($keys); //determine primary key and value $dao->myquery("SHOW index FROM {$obj->table} where Key_name = 'PRIMARY';"); // var_dump($dao->fetch_one_obj()); $obj->primary_key = $dao->fetch_one_obj()->Column_name; foreach ($query_objects as $query_obj) { $new_obj = clone $obj; //Copy the default obj foreach ($keys as $key) { $new_obj->{$key} = $query_obj[$key]; } $new_obj->primary_id = $new_obj->{$new_obj->primary_key}; $objects[] = $new_obj; } return $objects; }
$conversation->user_picture = $user2->user_picture; $conversations[$convo_id] = $conversation; } else { $conversation = $conversations[$convo_id]; } $conversation->messages[$message->msg_id] = $message; } return $conversations; } $dao = new DAO(false); if (isset($_POST["user_id"])) { if ($_POST["user_id"] == "-1") { //Get an array of all the conversations $conversations_query = "(SELECT user_id2 AS user_id FROM chat_msg WHERE user_id1={$user->user_id} GROUP BY user_id2) \n\t\t\t\t\t\t\t\t\tUNION \n\t\t\t\t\t\t\t\t\t(SELECT user_id1 AS user_id FROM chat_msg WHERE user_id2={$user->user_id} GROUP BY user_id1)"; $dao->myquery($conversations_query); $conversation_requests = $dao->fetch_all_part(array("user_id")); $conversations = array(); foreach ($conversation_requests as $request) { $c = get_conversations($dao, $request["user_id"], -1, -1)[$request["user_id"]]; $conversations[$request["user_id"]] = $c; } echo json_encode_strip($conversations); } else { $conversations = get_conversations($dao, $_POST["user_id"], -1, -1)[$_POST["user_id"]]; echo json_encode_strip($conversations); } } else { $conversation_requests = $_POST; $conversations = array(); foreach ($conversation_requests as $request) { $c = get_conversations($dao, $request["user_id"], $request["latest_pulled"], $request["latest_seen_by_u2"])[$request["user_id"]];