public function run() { // user must be authorized if (!isset($_SESSION['authorized_user_id'])) { $this->application->outputHeaders[] = 'HTTP/1.1 302 Found'; $this->application->outputHeaders[] = 'Location: /login.php'; $this->application->outputContent = ''; return; } // load user's information $user = new ApplicationModel_User($this->application); try { $user->setId($_SESSION['authorized_user_id']); $user->load(); } catch (ApplicationModelException_User $e) { throw new ApplicationException($e->getMessage(), 500); } // get the page number if (isset($this->application->parameters['page'])) { $page = (int) $this->application->parameters['page']; } else { $page = 1; } if ($page <= 0) { $page = 1; } // build list of files, this user owns $userUuids = $user->getUuids(); $userFiles = array(); $fileLoadQueueTimestamps = array(); $fileLoadQueue = array(); foreach ($userUuids as $time => $uuid) { $userUuidFileIds = ApplicationModel_File::getIdsForUploader($this->application, $uuid); $userFiles = array_merge($userFiles, $userUuidFileIds); } foreach ($userFiles as $userFile) { if ($userFile["value"] != "virtual") { $fileLoadQueue[] = (int) substr($userFile["value"], strlen('file_')); } $fileLoadQueueTimestamps[] = (int) $userFile["score"]; } array_multisort($fileLoadQueueTimestamps, SORT_DESC, $fileLoadQueue, SORT_ASC); // make sure that the requested page number is not too high $totalPages = ceil(count($fileLoadQueue) / $this->application->config['user_files_per_page']); if ($page > $totalPages) { $page = 1; } // cut off the part of the file list which we need to display on selected page $fileLoadQueue = array_slice($fileLoadQueue, ($page - 1) * $this->application->config['user_files_per_page'], $this->application->config['user_files_per_page']); // load file information for every file which we need to display on this page foreach ($fileLoadQueue as $fileId) { try { // load file $file = new ApplicationModel_File($this->application); $file->setId($fileId); $file->load(); // put it into the list of user's files $files[] = $file; } catch (ApplicationModelException_File $e) { // skip this file } } // render the html $view = new ApplicationView($this->application, $this->application->path . '/views/user_files.php'); $view->user = $user; $view->files = $files; $view->currentPage = $page; $view->totalPages = $totalPages; $view->render(); }