diff options
author | Florian Pritz <bluewind@xinu.at> | 2015-01-04 17:08:51 +0100 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2015-01-16 17:38:38 +0100 |
commit | 7f74792c2f82aee3cd98bd6304ced55894b43683 (patch) | |
tree | 8692e2cbeac5c50c3a7c558a06a3030b04a788f2 /application/service | |
parent | 0c53ebac6e0328aea4551f5f1a97783f34c82866 (diff) |
Improve history api for multipastes
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'application/service')
-rw-r--r-- | application/service/files.php | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/application/service/files.php b/application/service/files.php index 68072e95a..7b320078e 100644 --- a/application/service/files.php +++ b/application/service/files.php @@ -14,7 +14,8 @@ class files { static public function history($user) { $CI =& get_instance(); - $query = array(); + $multipaste_items_grouped = array(); + $multipaste_items = array(); $fields = array("id", "filename", "mimetype", "date", "hash", "filesize"); @@ -23,17 +24,25 @@ class files { ->where('user', $user) ->get()->result_array(); - // TODO: split this and provide an array of pastes for a multipaste? - $query = $CI->db->query(" - SELECT m.url_id id, sum(f.filesize) filesize, m.date, '' hash, '' mimetype, concat(count(*), ' file(s)') filename - FROM multipaste m - JOIN multipaste_file_map mfm ON m.multipaste_id = mfm.multipaste_id - JOIN files f ON f.id = mfm.file_url_id - WHERE m.user_id = ? - GROUP BY m.url_id - ", array($user))->result_array(); + $multipaste_items_query = $CI->db + ->select("m.url_id, f.filename, f.id, f.filesize, f.date, f.hash, f.mimetype") + ->from("multipaste m") + ->join("multipaste_file_map mfm", "m.multipaste_id = mfm.multipaste_id") + ->join("files f", "f.id = mfm.file_url_id") + ->where("m.user_id", $user) + ->get()->result_array(); + + foreach ($multipaste_items_query as $item) { + $key = $item["url_id"]; + unset($item["url_id"]); + $multipaste_items_grouped[$key][] = $item; + } - $items = array_merge($items, $query); + foreach ($multipaste_items_grouped as $key => $items) { + $multipaste_info = $CI->db->get_where("multipaste", array("url_id" => $key))->row_array(); + $multipaste_info["items"] = $items; + $multipaste_items[] = $multipaste_info; + } $total_size = $CI->db->query(" SELECT sum(filesize) sum @@ -45,6 +54,7 @@ class files { ", array($user))->row_array(); $ret["items"] = $items; + $ret["multipaste_items"] = $multipaste_items; $ret["total_size"] = $total_size["sum"]; return $ret; |