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

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

	/**#@+
	 * Action codes.
	 */
	const INSTALLED = 2100;
	const REMOVED = 2110;
	const ENABLED = 2120;
	const DISABLED = 2130;
	const CHILDTHEME = 2140;
	const CSSFRAMEWORK = 2150;
	/**#@-*/

	/**
	 * Record a theme install event.
	 *
	 * @param string $name The name of the theme.
	 * @param string $file The theme files.
	 */
	static function installed($name, $file) {
		self::record(self::INSTALLED, 'cfTheme', 0, [
			'name' => $name,
			'file' => $file
		]);
	}

	/**
	 * Record a theme install event.
	 *
	 * @param string $name The name of the theme.
	 * @param string $file The theme files.
	 */
	static function removed($name, $file) {
		self::record(self::REMOVED, 'cfTheme', 0, [
			'name' => $name,
			'file' => $file
		]);
	}

	/**
	 * Record a theme enable event.
	 *
	 * @param string $name The name of the theme.
	 * @param array $prev The previous theme data.
	 */
	static function enabled($name, $prev) {
		self::record(self::ENABLED, 'cfTheme', 0, [
			'name' => $name
		], $prev);
	}

	/**
	 * Record a theme disable event.
	 *
	 * @param string $name The name of the theme.
	 * @param array $prev The previous theme data.
	 */
	static function disabled($name, $prev) {
		self::record(self::DISABLED, 'cfTheme', 0, [
			'name' => $name
		], $prev);
	}

	/**
	 * Record a child theme change event.
	 *
	 * @param string $name The name of the theme.
	 * @param string $prev The previous theme data.
	 */
	static function childThemeChanged($name, $prev) {
		self::record(self::CHILDTHEME, 'cfTheme', 0, [
			'name' => empty($name) ? __('[Default]', 'cfBackend') : $name
		], [
			'childTheme' => empty($prev) ? __('[Default]', 'cfBackend') : $prev
		]);
	}

	/**
	 * Record a theme css framework change event.
	 *
	 * @param string $name The name of the theme.
	 * @param string $prev The previous theme data.
	 */
	static function cssChanged($name, $prev) {
		self::record(self::CSSFRAMEWORK, 'cfTheme', 0, [
			'name' => empty($name) ? __('fusionCSS / Other', 'cfBackend') : $name
		], [
			'cssFramework' => empty($prev) ? __('fusionCSS / Other', 'cfBackend') : $prev
		]);
	}
}
