<?php

class RevisionController {

	public static function show($id) {

		$rev = new Revision($id);
		$rev->load("document");

		return blade("revision", ["rev" => $rev]);
	}

	public static function api_set($id) {
		$r = new Revision($id);
		if ($r !== false) {
			foreach ($_POST as $k=>$v) {
				$r->$k = trim($v);
			}
			$r->save();
		}

		return $r;
	}

	public static function delete($id) {
		$r = new Revision($id);
		$r->load("document");
		$doc = $r->document;
		$r->delete();
		return redirect("/document/" . $doc->id);
	}

	public static function redownload($id) {
		$r = new Revision($id);
		$j = new DownloadJob($r->id, $r->origtitle, $r->path() . "/doc.pdf");
		$jobid = $j->queue();
        flash("success", "Job queued as ID " . $jobid);
        return redirect("/revision/" . $id);
	}

	public static function purge($id) {
		$r = new Revision($id);
		$r->purge();
        return redirect("/revision/" . $id);
	}
}
