GetFilesToResumeAction.class.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. class GetFilesToResumeAction implements IAction {
  3. public function execute() {
  4. $projectId = $_POST['project_id'] ?? $_GET['project_id'];
  5. $userId = $_SESSION['user_id'];
  6. $startOffset = $_POST['start'] ?? $_GET['start'] ?? 0;
  7. $limit = $_POST['limit'] ?? $_GET['limit'] ?? 0;
  8. $limitString = "";
  9. if ($limit > 0) {
  10. $limitString = " LIMIT " . $limit . " OFFSET " . $startOffset;
  11. }
  12. $sql = "SELECT rowid as upload_id, filepath FROM upload_logs WHERE project_id = :project_id AND user_id = :user_id".$limitString.";";
  13. $db = SqliteDatabase::getSingleton();
  14. $preparedQuery = $db->prepare($sql);
  15. $preparedQuery->bindValue(':project_id', $projectId);
  16. $preparedQuery->bindValue(':user_id', $userId);
  17. $result = $preparedQuery->execute();
  18. $missingFiles = array();
  19. while($row = $result->fetchArray(SQLITE3_ASSOC)) {
  20. $missingFiles[] = $row;
  21. }
  22. $sql = "SELECT count(*) AS count FROM upload_logs WHERE project_id = :project_id AND user_id = :user_id;";
  23. $preparedQuery = $db->prepare($sql);
  24. $preparedQuery->bindValue(':project_id', $projectId);
  25. $preparedQuery->bindValue(':user_id', $userId);
  26. $result = $preparedQuery->execute();
  27. $remainingFilesResult = $result->fetchArray(SQLITE3_ASSOC);
  28. $remainingFiles = $remainingFilesResult["count"];
  29. return array("files" => $missingFiles, "total" => $remainingFiles);
  30. }
  31. }