<?php

/**
 * Class file for decoding theme audit logs.
 *
 * 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
 */

/**
 * cfThemeAuditHelper Class
 *
 * Class to provide decoding for theme audit trails.
 *
 * @package clearFusionCMS
 */
class cfThemeAuditHelper extends cfAuditHelper {

	/**
	 * Convert the raw data to a human readable message.
	 *
	 * @param array $data The audit data.
	 * @return string The message string.
	 */
	function getMessage($data) {
		$params = empty($data['params']) ? [] : json_decode($data['params'], true);

		switch($data['action']) {
			case cfThemeAudit::INSTALLED:
				$msg = sprintf(__('Installed theme <strong>%1s</strong> into <strong>%2s</strong>.', 'cfBackend'), $params['name'], $params['file']);
				break;
			case cfThemeAudit::REMOVED:
				$msg = sprintf(__('Removed theme <strong>%1s</strong> from <strong>%2s</strong>.', 'cfBackend'), $params['name'], $params['file']);
				break;
			case cfThemeAudit::ENABLED:
				$msg = sprintf(__('Enabled the theme <strong>%s</strong>.', 'cfBackend'), $params['name']);
				break;
			case cfThemeAudit::DISABLED:
				$msg = sprintf(__('Disabled the theme <strong>%s</strong>.', 'cfBackend'), $params['name']);
				break;
			case cfThemeAudit::CHILDTHEME:
				$msg = sprintf(__('Changed the child theme to <strong>%s</strong>.', 'cfBackend'), $params['name']);
				break;
			case cfThemeAudit::CSSFRAMEWORK:
				$msg = sprintf(__('Changed the theme CSS framework to <strong>%s</strong>.', 'cfBackend'), $params['name']);
				break;
			default:
				$msg = parent::getMessage($data);
				break;
		}

		return $msg;
	}

	/**
	 * @inheritdoc
	 */
	function hasAdditionalData($data) {
		return in_array($data['action'], [cfThemeAudit::ENABLED, cfThemeAudit::DISABLED, cfThemeAudit::CHILDTHEME, cfThemeAudit::CSSFRAMEWORK ]);
	}
}
