CatalogCacheMgr.php 1.89 KB
<?php

/**
 * @class CatalogCacheMgr
 */

class CatalogCacheMgr extends TimeTableCacheMgr
{
	const DEFAULT_PARAM_ID_PREFIX = 'cat_param_id_';

	function __construct() {
		$this->objectMgr  = new CatalogMgr();
	}

	protected function getCacheFileName() {
	  return "cacheCat";
	}

	protected function resetCache($options = array()) {
    $this->cache = new CatalogCacheObject();
		if (!empty($options['nparams'])) {
			for ($i = 0; $i < (int)$options['nparams']; $i++) {
				$this->cache->addParameter(CatalogCacheMgr::DEFAULT_PARAM_ID_PREFIX.(string)($i+1), 'column_'.(string)($i+1), 1, 0);
			}
		}
		else if (!empty($options['parameters'])) {
			$index = 0;
			foreach ($options['parameters'] as $parameter) {
				if (array_key_exists('id',$parameter) && !empty($parameter['id'])) {
					$id = $parameter['id'];
				}
				else if (array_key_exists('ID',$parameter) && !empty($parameter['ID'])) {
					$id = $parameter['ID'];
				}
				else {
					$id = 'cat_param_id_'.$index;
				}
				$this->cache->addParameter($id, $parameter['name'], intval($parameter['size']), intval($parameter['type']));
				++$index;
			}
		}
		return array('parameters' => $this->cache->getParametersInfo());
  }

	protected function loadAdditionalDescription($options) {
		$params_desc = $this->objectMgr->getCatalogParamDescription($options);
		if (!$params_desc['success']) {
			return array();
		}
		return array('parameters' => $params_desc['parameters']);
	}


	public function initFromUploadedFile($name, $format)
	{
		$result = parent::initFromUploadedFile($name, $format);
		if (!$result['success']) {
			return $result;
		}

		$info = $this->objectMgr->getUploadedObject($name, $format,TRUE);
		foreach ($info['parameters'] as $parameter) {
			$this->cache->addParameter($parameter['id'], $parameter['name'], intval($parameter['size']), intval($parameter['type']));
		}

		return $result+ array('parameters' => $info['parameters']);
	}

}
?>