<?php
/*
 * Copyright (c) 2013, webvariants GbR, http://www.webvariants.de
 *
 * This file is released under the terms of the MIT license. You can find the
 * complete text in the attached LICENSE file or online at:
 *
 * http://www.opensource.org/licenses/mit-license.php
 */

abstract class _WV2_Extensions_Base {
	protected static function canView() {
		return _WV2_Metainfo::isAllowed('view');
	}

	protected static function canEdit() {
		return _WV2_Metainfo::isAllowed('edit');
	}

	protected static function showErrors($errors, $type) {
		$flashMessage = sly_Core::getFlashMessage();
		$flashMessage->appendWarning(self::getErrorText($errors, $type));
	}

	protected static function getErrorText($errors, $type) {
		$messages = array(t('metainfo_input_errors'));

		foreach ($errors as $metainfo => $message) {
			$metainfo   = WV2_Metainfo::getMetainfo($metainfo, $type);
			$messages[] = sly_translate($metainfo->getTitle(), true).': '.sly_translate($message, true);
		}

		return implode('<br />', $messages);
	}
}
