<?php

/**
 * Helper class file for audit logging.
 *
 * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 * @package clearFusionCMS
 * @copyright Copyright (c) 2016 clearFusionCMS. All rights reserved.
 * @link http://clearfusioncms.com
 */

/**
 * cfFileAudit Class
 *
 * Static class to provide file audit trail logging.
 *
 * @package clearFusionCMS
 */
abstract class cfFileAudit extends cfAudit {

	/**#@+
	 * Action codes.
	 */
	const UPLOADED = 1700;
	const NEWFOLDER = 1710;
	const RENAMEFOLDER = 1720;
	const DELFOLDER = 1730;
	const MOVEFOLDER = 1740;
	const RENAMEFILE = 1750;
	const RESIZEIMG = 1760;
	const DELFILE = 1770;
	const MOVEFILE = 1780;
	/**#@-*/

	/**
	 * Record a file upload event.
	 *
	 * @param string $file The file uploaded.
	 */
	static function uploaded($file) {
		self::record(self::UPLOADED, 'cfFile', 0, [
			'file' => $file
		]);
	}

	/**
	 * Record a folder create event.
	 *
	 * @param string $folder The new folder.
	 */
	static function newFolder($folder) {
		self::record(self::NEWFOLDER, 'cfFile', 0, [
			'folder' => $folder
		]);
	}

	/**
	 * Record a folder rename event.
	 *
	 * @param string $folder The folder.
	 * @param string $folderNew The new folder.
	 */
	static function renameFolder($folder, $folderNew) {
		self::record(self::RENAMEFOLDER, 'cfFile', 0, [
			'folder' => $folder,
			'newFolder' => $folderNew
		]);
	}

	/**
	 * Record a folder delete event.
	 *
	 * @param string $folder The deleted folder.
	 */
	static function deleteFolder($folder) {
		self::record(self::DELFOLDER, 'cfFile', 0, [
			'folder' => $folder
		]);
	}

	/**
	 * Record a folder move event.
	 *
	 * @param string $folder The folder.
	 * @param string $folderNew The new folder.
	 */
	static function moveFolder($folder, $folderNew) {
		self::record(self::MOVEFOLDER, 'cfFile', 0, [
			'folder' => $folder,
			'newFolder' => $folderNew
		]);
	}

	/**
	 * Record a file rename event.
	 *
	 * @param string $file The file.
	 * @param string $fileNew The new file.
	 */
	static function renameFile($file, $fileNew) {
		self::record(self::RENAMEFILE, 'cfFile', 0, [
			'file' => $file,
			'newFile' => $fileNew
		]);
	}

	/**
	 * Record an image resize event.
	 *
	 * @param string $file The file.
	 * @param string $fileNew The new file.
	 * @param string $w The new width.
	 * @param string $h The new height.
	 */
	static function resize($file, $fileNew, $w, $h) {
		self::record(self::RESIZEIMG, 'cfFile', 0, [
			'file' => $file,
			'newFile' => $fileNew,
			'w' => $w,
			'h' => $h
		]);
	}

	/**
	 * Record a file delete event.
	 *
	 * @param string $file The deleted file.
	 */
	static function deleteFile($file) {
		self::record(self::DELFILE, 'cfFile', 0, [
			'file' => $file
		]);
	}

	/**
	 * Record a file move event.
	 *
	 * @param string $file The file.
	 * @param string $fileNew The new file.
	 */
	static function moveFile($file, $fileNew) {
		self::record(self::MOVEFILE, 'cfFile', 0, [
			'file' => $file,
			'newFile' => $fileNew
		]);
	}
}
