diff options
-rw-r--r-- | application/controllers/file.php | 16 | ||||
-rw-r--r-- | application/service/files.php | 32 |
2 files changed, 37 insertions, 11 deletions
diff --git a/application/controllers/file.php b/application/controllers/file.php index ac2c4b4ca..5451836de 100644 --- a/application/controllers/file.php +++ b/application/controllers/file.php @@ -640,6 +640,22 @@ class File extends MY_Controller { $lengths[$length_key] = mb_strlen($value); } + foreach ($history["multipaste_items"] as $key => $item) { + $size = 0; + foreach ($item["items"] as $i) { + $size += $i["filesize"]; + } + + $history["items"][] = array( + "id" => $item["url_id"], + "filename" => count($item["items"])." file(s)", + "mimetype" => "", + "date" => $item["date"], + "hash" => "", + "filesize" => $size, + ); + } + $order = is_cli_client() ? "ASC" : "DESC"; uasort($history["items"], function($a, $b) use ($order) { 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; |