<?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\module\property
 * @copyright Copyright (c) 2017 clearFusionCMS. All rights reserved.
 * @link http://clearfusioncms.com
 */

/**
 * propertyAudit Class
 *
 * Static class to provide audit trail logging.
 *
 * @package clearFusionCMS\module\property
 */
abstract class propertyAudit extends cfAudit {

	/**#@+
	 * Action codes.
	 */
	const CREATEFEATURE = 8000;
	const UPDATEFEATURE = 8010;
	const DELETEFEATURE = 8020;
	const MOVEFEATURE = 8030;

	const CREATEFIELD = 8040;
	const UPDATEFIELD = 8050;
	const DELETEFIELD = 8060;

	const CREATERGNFIELD = 8070;
	const UPDATERGNFIELD = 8080;
	const DELETERGNFIELD = 8090;

	const CREATEREGION = 8100;
	const UPDATEREGION = 8110;
	const DELETEREGION = 8120;
	const MOVEREGION = 8130;

	const CREATETYPE = 8140;
	const UPDATETYPE = 8150;
	const DELETETYPE = 8160;
	const MOVETYPE = 8170;

	const CREATEPROPERY = 8180;
	const UPDATEPROPERTY = 8190;
	const DELETEPROPERTY = 8200;
	const CREATEGALLERY = 8210;
	const UPDATEGALLERY = 8220;
	const DELETEGALLERY = 8230;
	/**#@-*/

	/**
	 * Record a create feature event.
	 *
	 * @param int $id The item ID.
	 * @param string $title The title of the new blog.
	 */
	static function createFeature($id, $title) {
		self::record(self::CREATEFEATURE, 'property', $id, ['title' => $title]);
	}

	/**
	 * Record an update to the given item.
	 *
	 * @param int $id The item ID.
	 * @param string $title The title of the post.
	 * @param array $prevData The previous data.
	 */
	static function updateFeature($id, $title, $prevData) {
		self::record(self::UPDATEFEATURE, 'property', $id, ['title' => $title], $prevData);
	}

	/**
	 * Record a delete event.
	 *
	 * @param int $id The item ID.
	 * @param array $prevData The previous data.
	 */
	static function deleteFeature($id, $prevData) {
		self::record(self::DELETEFEATURE, 'property', $id, ['title' => $prevData['title']], $prevData);
	}

	/**
	 * Record feature move event.
	 *
	 * @param int $id The item ID.
	 * @param string $position The position relative to the target.
	 * @param string $origPath The original path.
	 * @param string $newPath The new path.
	 */
	static function moveFeature($id, $position, $origPath, $newPath) {
		self::record(self::MOVEFEATURE, 'property', $id, [
			'position' => $position,
			'origPath' => $origPath,
			'newPath' => $newPath
		]);
	}

	/**
	 * Record a create field event.
	 *
	 * @param int $id The item ID.
	 * @param string $title The title of the new item.
	 */
	static function createField($id, $title) {
		self::record(self::CREATEFIELD, 'property', $id, ['title' => $title]);
	}

	/**
	 * Record an update to the given item.
	 *
	 * @param int $id The item ID.
	 * @param string $title The title of the post.
	 * @param array $prevData The previous data.
	 */
	static function updateField($id, $title, $prevData) {
		self::record(self::UPDATEFIELD, 'property', $id, ['title' => $title], $prevData);
	}

	/**
	 * Record a delete event.
	 *
	 * @param int $id The item ID.
	 * @param array $prevData The previous data.
	 */
	static function deleteField($id, $prevData) {
		self::record(self::DELETEFIELD, 'property', $id, ['title' => $prevData['fieldname']], $prevData);
	}

	/**
	 * Record a create field event.
	 *
	 * @param int $id The item ID.
	 * @param string $title The title of the new item.
	 */
	static function createRgnField($id, $title) {
		self::record(self::CREATERGNFIELD, 'property', $id, ['title' => $title]);
	}

	/**
	 * Record an update to the given item.
	 *
	 * @param int $id The item ID.
	 * @param string $title The title of the post.
	 * @param array $prevData The previous data.
	 */
	static function updateRgnField($id, $title, $prevData) {
		self::record(self::UPDATERGNFIELD, 'property', $id, ['title' => $title], $prevData);
	}

	/**
	 * Record a delete event.
	 *
	 * @param int $id The item ID.
	 * @param array $prevData The previous data.
	 */
	static function deleteRgnField($id, $prevData) {
		self::record(self::DELETERGNFIELD, 'property', $id, ['title' => $prevData['fieldname']], $prevData);
	}

	/**
	 * Record a create feature event.
	 *
	 * @param int $id The item ID.
	 * @param string $title The title of the new item.
	 */
	static function createRegion($id, $title) {
		self::record(self::CREATEREGION, 'property', $id, ['title' => $title]);
	}

	/**
	 * Record an update to the given item.
	 *
	 * @param int $id The item ID.
	 * @param string $title The title of the post.
	 * @param array $prevData The previous data.
	 */
	static function updateRegion($id, $title, $prevData) {
		unset($prevData['lftrgtset']);
		self::record(self::UPDATEREGION, 'property', $id, ['title' => $title], $prevData);
	}

	/**
	 * Record a delete event.
	 *
	 * @param int $id The item ID.
	 * @param array $prevData The previous data.
	 */
	static function deleteRegion($id, $prevData) {
		unset($prevData['lftrgtset']);
		self::record(self::DELETEREGION, 'property', $id, ['title' => $prevData['title']], $prevData);
	}

	/**
	 * Record feature move event.
	 *
	 * @param int $id The item ID.
	 * @param string $position The position relative to the target.
	 * @param string $origPath The original path.
	 * @param string $newPath The new path.
	 */
	static function moveRegion($id, $position, $origPath, $newPath) {
		self::record(self::MOVEREGION, 'property', $id, [
			'position' => $position,
			'origPath' => $origPath,
			'newPath' => $newPath
		]);
	}

	/**
	 * Record a create property type event.
	 *
	 * @param int $id The item ID.
	 * @param string $title The title of the new item.
	 */
	static function createType($id, $title) {
		self::record(self::CREATETYPE, 'property', $id, ['title' => $title]);
	}

	/**
	 * Record an update to the given item.
	 *
	 * @param int $id The item ID.
	 * @param string $title The title of the post.
	 * @param array $prevData The previous data.
	 */
	static function updateType($id, $title, $prevData) {
		unset($prevData['lftrgtset']);
		self::record(self::UPDATETYPE, 'property', $id, ['title' => $title], $prevData);
	}

	/**
	 * Record a delete event.
	 *
	 * @param int $id The item ID.
	 * @param array $prevData The previous data.
	 */
	static function deleteType($id, $prevData) {
		unset($prevData['lftrgtset']);
		self::record(self::DELETETYPE, 'property', $id, ['title' => $prevData['title']], $prevData);
	}

	/**
	 * Record a move property type event.
	 *
	 * @param int $id The item ID.
	 * @param string $title The title of the new item.
	 */
	static function moveType($id, $title) {
		self::record(self::MOVETYPE, 'property', $id, ['title' => $title]);
	}

	/**
	 * Record a create property event.
	 *
	 * @param int $id The item ID.
	 * @param string $title The title of the new item.
	 */
	static function createProperty($id, $title) {
		self::record(self::CREATEPROPERY, 'property', $id, ['title' => $title]);
	}

	/**
	 * Record an update to the given item.
	 *
	 * @param int $id The item ID.
	 * @param string $title The title of the post.
	 * @param array $prevData The previous data.
	 */
	static function updateProperty($id, $title, $prevData) {
		self::record(self::UPDATEPROPERTY, 'property', $id, ['title' => $title], $prevData);
	}

	/**
	 * Record a delete event.
	 *
	 * @param int $id The item ID.
	 * @param array $prevData The previous data.
	 */
	static function deleteProperty($id, $prevData) {
		self::record(self::DELETEPROPERTY, 'property', $id, ['title' => $prevData['title']], $prevData);
	}

	/**
	 * Record a create property gallery event.
	 *
	 * @param int $id The item ID.
	 * @param string $property The title of the property.
	 * @param string $title The title of the new item.
	 */
	static function createGallery($id, $property, $title) {
		self::record(self::CREATEGALLERY, 'property', $id, [
			'property' => $property,
			'title' => $title
		]);
	}

	/**
	 * Record an update property gallery event.
	 *
	 * @param int $id The item ID.
	 * @param string $property The title of the property.
	 * @param string $title The title of the item.
	 * @param array $prevData The previous data.
	 */
	static function updateGallery($id, $property, $title, $prevData) {
		self::record(self::UPDATEGALLERY, 'property', $id, [
			'property' => $property,
			'title' => $title
		], $prevData);
	}

	/**
	 * Record a delete property gallery event.
	 *
	 * @param int $id The item ID.
	 * @param string $property The title of the property.
	 * @param array $prevData The previous data.
	 */
	static function deleteGallery($id, $property, $prevData) {
		self::record(self::DELETEGALLERY, 'property', $id, [
			'property' => $property,
			'title' => $prevData['title']
		], $prevData);
	}
}
