<?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
 */

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

	/**#@+
	 * Action codes.
	 */
	const CREATE = 2300;
	const UPDATE = 2310;
	const DELETE = 2320;
	const SET403 = 2330;
	const SET404 = 2340;
	const SETHOME = 2350;
	const SETERROR = 2360;
	/**#@-*/

	/**
	 * Record a new site event.
	 *
	 * @param string $name The name of the site.
	 */
	static function created($name) {
		self::record(self::CREATE, 'cfSite', 0, [
			'name' => $name
		]);
	}

	/**
	 * Record a site update event.
	 *
	 * @param string $name The name of the site.
	 * @param array $prev The previous data.
	 */
	static function update($name, $prev) {
		self::record(self::UPDATE, 'cfSite', 0, [
			'name' => $name
		], $prev);
	}

	/**
	 * Record a site delete event.
	 *
	 * @param string $name The name of the site.
	 * @param array $prev The previous data.
	 */
	static function delete($name, $prev) {
		self::record(self::DELETE, 'cfSite', 0, [
			'name' => $name
		], $prev);
	}

	/**
	 * Record a set 403 page event.
	 *
	 * @param int $id The ID of the 403 document.
	 * @param string $path The new document path.
	 * @param array $prev The previous document.
	 */
	static function set403($id, $path, $prev) {
		self::record(self::SET403, 'cfSite', 0, [
			'id' => $id,
			'path' => empty($path) ? __('Root', 'cfBackend') : $path
		], $prev);
	}

	/**
	 * Record a set 404 page event.
	 *
	 * @param int $id The ID of the 404 document.
	 * @param string $path The new document path.
	 * @param array $prev The previous document.
	 */
	static function set404($id, $path, $prev) {
		self::record(self::SET404, 'cfSite', 0, [
			'id' => $id,
			'path' => empty($path) ? __('Root', 'cfBackend') : $path
		], $prev);
	}

	/**
	 * Record a set home page event.
	 *
	 * @param int $id The ID of the home document.
	 * @param string $path The new document path.
	 * @param array $prev The previous document.
	 */
	static function setHome($id, $path, $prev) {
		self::record(self::SETHOME, 'cfSite', 0, [
			'id' => $id,
			'path' => empty($path) ? __('Root', 'cfBackend') : $path
		], $prev);
	}

	/**
	 * Record a set error page event.
	 *
	 * @param int $id The ID of the error document.
	 * @param string $path The new document path.
	 * @param array $prev The previous document.
	 */
	static function setError($id, $path, $prev) {
		self::record(self::SETERROR, 'cfSite', 0, [
			'id' => $id,
			'path' => empty($path) ? __('Root', 'cfBackend') : $path
		], $prev);
	}
}
