<?php
/**
* DBインスタンス作成タスク
*
* PHP version 5
*
* @author     stk2k <stk2k@sazysoft.com>
* @copyright  2008 stk2k, sazysoft
*/
class DBTableCreateTask extends DatabaseTask implements ITask
{
	public $success;

	/*
	 *    コンストラクタ
	 */
	public function __construct()
	{
		$this->success = FALSE;

		parent::__construct();
	}

	/**
	 * イベントを処理する
	 */
	public function processEvent( IEvent $event, TaskSnapshot $snapshot )
	{
		// テーブル作成
		$this->createTable( s('shouhin') );
		$this->createTable( s('manufacturer') );

		// 投入データ
		$manufacturer_list = array( 
				array( 'id' => 1, 'name' => 'Charcoal' ),
				array( 'id' => 2, 'name' => '茶子家具店' ),
			);
		$shouhin_list = array( 
				array( 'item_code' => 'ELH-001',   'item_name' => '高級羽毛布団',   'price' => '54000',  'manufacturer_id' => '1' ),
				array( 'item_code' => 'THJ-2341',  'item_name' => 'ソファーベッド', 'price' => '43000',  'manufacturer_id' => '2' ),
				array( 'item_code' => 'BFD-1172D', 'item_name' => 'パソコンデスク', 'price' => '22000',  'manufacturer_id' => '2' ),
			);

		// データ投入
		foreach( $shouhin_list as $data )
		{
			// DTO作成
			$dto = new DTO($data);

print "DTO:$dto<BR>";

			// DB保存
			$this->save( s('shouhin'), $dto, s('PHP_TO_DB') );
		}

		foreach( $manufacturer_list as $data )
		{
			// DTO作成
			$dto = new DTO($data);

			// DB保存
			$this->save( s('manufacturer'), $dto, s('PHP_TO_DB') );
		}

		$this->success = TRUE;

		return b(TRUE);
	}

}
