<?php

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

/**
 * cfFileAuditHelper Class
 *
 * Class to provide decoding for file audit trails.
 *
 * @package clearFusionCMS
 */
class cfFileAuditHelper 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 cfFileAudit::UPLOADED:
				$msg = sprintf(__('Uploaded file <strong>%s</strong>.', 'cfBackend'), $params['file']);
				break;
			case cfFileAudit::NEWFOLDER:
				$msg = sprintf(__('Created a new folder <strong>%s</strong>.', 'cfBackend'), $params['folder']);
				break;
			case cfFileAudit::RENAMEFOLDER:
				$msg = sprintf(__('Renamed folder <strong>%1s</strong> to <strong>%2s</strong>.', 'cfBackend'), $params['folder'], $params['newFolder']);
				break;
			case cfFileAudit::DELFOLDER:
				$msg = sprintf(__('Deleted folder <strong>%s</strong>.', 'cfBackend'), $params['folder']);
				break;
			case cfFileAudit::MOVEFOLDER:
				$msg = sprintf(__('Moved folder <strong>%1s</strong> to <strong>%2s</strong>.', 'cfBackend'), $params['folder'], $params['newFolder']);
				break;
			case cfFileAudit::RENAMEFILE:
				$msg = sprintf(__('Renamed file <strong>%1s</strong> to <strong>%2s</strong>.', 'cfBackend'), $params['file'], $params['newFile']);
				break;
			case cfFileAudit::RESIZEIMG:
				$msg = sprintf(__('Resized image <strong>%1s</strong> to <strong>%2s</strong>. New size <strong>%3d</strong> x <strong>%4d</strong> pixels.', 'cfBackend'), $params['file'], $params['newFile'], $params['w'], $params['h']);
				break;
			case cfFileAudit::DELFILE:
				$msg = sprintf(__('Deleted file <strong>%s</strong>.', 'cfBackend'), $params['file']);
				break;
			case cfFileAudit::MOVEFILE:
				$msg = sprintf(__('Moved file <strong>%1s</strong> to <strong>%2s</strong>.', 'cfBackend'), $params['file'], $params['newFile']);
				break;
			default:
				$msg = parent::getMessage($data);
				break;
		}

		return $msg;
	}

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