<?php

require_once XOOPS_TRUST_PATH . '/libs/xoonips/class/core/Complement.class.php';
require_once XOOPS_TRUST_PATH . '/libs/xoonips/class/core/Kana2Roma.class.php';
require_once XOOPS_TRUST_PATH . '/libs/xoonips/class/core/Utils.class.php';
require_once 'ItemComplementManager.class.php';

class Xoonips_ComplementKana extends Xoonips_Complement {

	public function complete($field, $id, &$data) {
		$ids = explode(Xoonips_Enum::ITEM_ID_SEPARATOR, $id);
		$complementId = $this->getId();
		$itemtypeId = $field->getItemTypeId();

		$manager = new Xoonips_ItemComplementManager($this->dirname);
		$complementItems = $manager->getItemComplement($complementId, $itemtypeId, $ids[2]);

		if (!$complementItems) return;
		foreach ($complementItems as $comp) {
			$detailId = $comp['item_field_detail_id'];
		}

		$kana = $data[$id];
		$key = $field->getFieldGroupId() . Xoonips_Enum::ITEM_ID_SEPARATOR . $ids[1] . Xoonips_Enum::ITEM_ID_SEPARATOR . $detailId;
		$kana2roma = new Xoonips_Kana2Roma();
		$data[$key] = $kana2roma->kana2Roma($kana);
	}
}
?>
