<?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 WV42_Renderer_Base {
	protected $dataCache = null;

	protected function buildCache(pac_Role $role, pac_Destination $destination) {
		if ($this->dataCache !== null) return;

		$this->dataCache = array();

		// prepare query
		$stmt = pac_Core::prepare('SELECT `token`,`value` FROM '.pac_Core::dbTable(pac_Core::ROLES_DESTINATIONS_TABLE).' WHERE `destination` = :destination AND `role_id` = :role_id');
		$stmt->execute(array('destination' => $destination->getId(), 'role_id' => $role->getId()));

		// and fetch data
		foreach ($stmt->fetchAll() as $row) {
			$this->dataCache[$row['value']][] = $row['token'];
		}
	}
}
