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

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

	/**#@+
	 * Action codes.
	 */
	const CREATESNIPPET = 1200;
	const UPDATESNIPPET = 1210;
	const DELETESNIPPET = 1220;

	const CREATETASK = 1230;
	const UPDATETASK = 1240;
	const DELETETASK = 1250;

	const CREATEFIELD = 1260;
	const UPDATEFIELD = 1270;
	const DELETEFIELD = 1280;

	const CREATECHUNK = 1290;
	const UPDATECHUNK = 1300;
	const DELETECHUNK = 1310;

	const CREATETPL = 1320;
	const UPDATETPL = 1330;
	const DELETETPL = 1340;

	const CREATECAT = 1350;
	const UPDATECAT = 1360;
	const DELETECAT = 1370;

	const CREATETHEME = 1380;
	const UPDATETHEME = 1390;
	const DELETETHEME = 1400;
	/**#@-*/

	/**
	 * Record a snippet create event.
	 *
	 * @param int $id The item ID.
	 * @param string $name The name of the snippet.
	 */
	static function createSnippet($id, $name) {
		self::record(self::CREATESNIPPET, 'cfElement', $id, ['name' => $name]);
	}

	/**
	 * Record a snippet update event.
	 *
	 * @param int $id The item ID.
	 * @param array $prevData Previous data.
	 */
	static function updateSnippet($id, $prevData) {
		self::record(self::UPDATESNIPPET, 'cfElement', $id, ['name' => $prevData['snippetname']], $prevData);
	}

	/**
	 * Record a snippet delete event.
	 *
	 * @param int $id The item ID.
	 * @param array $prevData Previous data.
	 */
	static function deleteSnippet($id, $prevData) {
		self::record(self::DELETESNIPPET, 'cfElement', $id, ['name' => $prevData['snippetname']], $prevData);
	}

	/**
	 * Record a task create event.
	 *
	 * @param int $id The item ID.
	 * @param string $name The name of the task.
	 */
	static function createTask($id, $name) {
		self::record(self::CREATETASK, 'cfElement', $id, ['name' => $name]);
	}

	/**
	 * Record a task update event.
	 *
	 * @param int $id The item ID.
	 * @param array $prevData Previous data.
	 */
	static function updateTask($id, $prevData) {
		self::record(self::UPDATETASK, 'cfElement', $id, ['name' => $prevData['taskname']], $prevData);
	}

	/**
	 * Record a task delete event.
	 *
	 * @param int $id The item ID.
	 * @param array $prevData Previous data.
	 */
	static function deleteTask($id, $prevData) {
		self::record(self::DELETETASK, 'cfElement', $id, ['name' => $prevData['taskname']], $prevData);
	}

	/**
	 * Record a field create event.
	 *
	 * @param string $name The name of the task.
	 */
	static function createField($name) {
		self::record(self::CREATEFIELD, 'cfElement', 0, ['name' => $name]);
	}

	/**
	 * Record a field update event.
	 *
	 * @param string $name The name of the task.
	 * @param array $prevData Previous data.
	 */
	static function updateField($name, $prevData) {
		self::record(self::UPDATEFIELD, 'cfElement', 0, ['name' => $name], $prevData);
	}

	/**
	 * Record a field delete event.
	 *
	 * @param array $prevData Previous data.
	 */
	static function deleteField($prevData) {
		self::record(self::DELETEFIELD, 'cfElement', 0, ['name' => $prevData['placeholder']], $prevData);
	}

	/**
	 * Record a chunk create event.
	 *
	 * @param bool $isTemplate true if template chunk; else false.
	 * @param int $id The item ID.
	 * @param string $name The name of the chunk.
	 */
	static function createChunk($isTemplate, $id, $name) {
		self::record($isTemplate ? self::CREATETPL : self::CREATECHUNK, 'cfElement', $id, ['name' => $name]);
	}

	/**
	 * Record a chunk update event.
	 *
	 * @param bool $isTemplate true if template chunk; else false.
	 * @param string $name The name of the chunk.
	 * @param array $prevData Previous data.
	 */
	static function updateChunk($isTemplate, $id, $prevData) {
		self::record($isTemplate ? self::UPDATETPL : self::UPDATECHUNK, 'cfElement', $id, ['name' => $prevData['chunkname']], $prevData);
	}

	/**
	 * Record a chunk delete event.
	 *
	 * @param bool $isTemplate true if template chunk; else false.
	 * @param int $id The item ID.
	 * @param array $prevData Previous data.
	 */
	static function deleteChunk($isTemplate, $id, $prevData) {
		self::record($isTemplate ? self::DELETETPL : self::DELETECHUNK, 'cfElement', $id, ['name' => $prevData['chunkname']], $prevData);
	}

	/**
	 * Record a category create event.
	 *
	 * @param int $id The item ID.
	 * @param string $name The name of the category.
	 */
	static function createCategory($id, $name) {
		self::record(self::CREATECAT, 'cfElement', $id, ['name' => $name]);
	}

	/**
	 * Record a category update event.
	 *
	 * @param int $id The item ID.
	 * @param array $prevData Previous data.
	 */
	static function updateCategory($id, $prevData) {
		self::record(self::UPDATECAT, 'cfElement', $id, ['name' => $prevData['catname']], $prevData);
	}

	/**
	 * Record a category delete event.
	 *
	 * @param int $id The item ID.
	 * @param array $prevData Previous data.
	 */
	static function deleteCategory($id, $prevData) {
		self::record(self::DELETECAT, 'cfElement', $id, ['name' => $prevData['catname']], $prevData);
	}

	/**
	 * Record a theme create event.
	 *
	 * @param int $id The item ID.
	 * @param string $name The name of the theme.
	 */
	static function createTheme($id, $name) {
		self::record(self::CREATETHEME, 'cfElement', $id, ['name' => $name]);
	}

	/**
	 * Record a theme update event.
	 *
	 * @param int $id The item ID.
	 * @param array $prevData Previous data.
	 */
	static function updateTheme($id, $prevData) {
		self::record(self::UPDATETHEME, 'cfElement', $id, ['name' => $prevData['themename']], $prevData);
	}

	/**
	 * Record a theme delete event.
	 *
	 * @param int $id The item ID.
	 * @param array $prevData Previous data.
	 */
	static function deleteTheme($id, $prevData) {
		self::record(self::DELETETHEME, 'cfElement', $id, ['name' => $prevData['themename']], $prevData);
	}

}
