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

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

	/**#@+
	 * Action codes.
	 */
	const CREATE = 1000;
	const UPDATE = 1010;
	const DELETE = 1020;
	const DRAFT = 1030;
	const DRAFTDEL = 1040;
	const MOVE = 1050;
	/**#@-*/

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

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

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

	/**
	 * Record deletion of a draft.
	 *
	 * @param int $id The item ID.
	 * @param array $prevData The previous data.
	 */
	static function deleteDraft($id, $prevData) {
		self::record(self::DRAFTDEL, 'content', $id, ['restype' => $prevData['restype'], 'title' => $prevData['title']], $prevData);
	}

	/**
	 * Record storing of a draft.
	 *
	 * @param int $id The item ID.
	 * @param array $prevData The previous data.
	 */
	static function draft($id, $prevData) {
		self::record(self::DRAFT, 'content', $id, ['restype' => $prevData['restype'], 'title' => $prevData['title']], $prevData);
	}

	/**
	 * Record document 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 move($id, $position, $origPath, $newPath) {
		self::record(self::MOVE, 'content', $id, [
			'position' => $position,
			'origPath' => $origPath,
			'newPath' => $newPath
		]);
	}
}
