<?php

/**
 * Class file for decoding module 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
 */

/**
 * cfModuleAuditHelper Class
 *
 * Class to provide decoding for module audit trails.
 *
 * @package clearFusionCMS
 */
class cfModuleAuditHelper 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 cfModuleAudit::INSTALLED:
				$msg = sprintf(__('Installed version <strong>%1s</strong> of module <strong>%2s</strong>.', 'cfBackend'), $params['ver'], $params['name']);
				break;
			case cfModuleAudit::REMOVED:
				$msg = sprintf(__('Removed version <strong>%1s</strong> of module <strong>%2s</strong>.', 'cfBackend'), $params['ver'], $params['name']);
				break;
			case cfModuleAudit::UPLOADEDCORE:
				$msg = sprintf(__('Uploaded CMS core files.', 'cfBackend'));
				break;
			case cfModuleAudit::UPLOADEDMODULE:
				$msg = sprintf(__('Uploaded files for module <strong>%s</strong>.', 'cfBackend'), $params['name']);
				break;
			default:
				$msg = parent::getMessage($data);
				break;
		}

		return $msg;
	}

	/**
	 * @inheritdoc
	 */
	function hasAdditionalData($data) {
		return false;
	}
}
