menuitems = array();
foreach( $xmlSchemaData->child_nodes() as $node )
{
if ( $node->node_type() == XML_ELEMENT_NODE and $node->tagname() == 'menuitem' )
{
if ( empty( $this->defaultId ) )
{
$this->defaultId = file2code( $node->get_attribute('id') );
}
$this->menuitems[ file2code( $node->get_attribute('id') ) ] = file2code( $node->get_content() );
}
}
}
/* ----------------------------------------------------------------
* 当項目のXMLノードを新規作成する。
* $xmlDocParentEntry : エントリのDOMオブジェクト。
* return : 新規XMLノード。
*/
function createNew( $xmlDocParentEntry )
{
$newNode = parent::createNew( $xmlDocParentEntry );
$newNode->set_content( fileconv( $this->defaultId ) );
return $newNode;
}
/* ----------------------------------------------------------------
* 入力内容でエントリ項目を更新する。
* $xpathEntry : エントリのXPathオブジェクト。
* $currentEntry : 現在のエントリ位置を表すXPath文字列。
*/
function update( $xpathEntry, $currentEntry )
{
// エントリXMLを取得。
$xmlEntryDataList = $xpathEntry->xpath_eval( $currentEntry . '/' . $this->dataName );
$xmlEntryData = $xmlEntryDataList->nodeset[0];
// "name"属性に対応するPOSTが存在すれば、エントリに反映する。
if ( isset( $_POST[ $this->dataName ] ) )
{
$datavalue = $_POST[ $this->dataName ];
// 範囲チェック(選択肢中に存在するIDか)
if ( ! in_array( $datavalue, array_keys($this->menuitems) ) )
{
$this->errorMessage = sprintf( "%s に存在しない選択肢が指定されました。", $this->dataCaption );
return false;
}
// まず、テキストノードを削除する(削除しないと、set_contentではテキストノードが増えるだけ)。
$xmlEntryData = $xmlEntryDataList->nodeset[0];
EntryUtil::deleteTextNode( $xmlEntryData );
// テキストノードに新しい値をsetする。
$xmlEntryData->set_content( fileconv( $datavalue ) );
//print( $dataname . " = " . htmlconv( $datavalue ) . "
\n" );
}
return true;
}
/* ----------------------------------------------------------------
* フォーム項目を描画するHTMLを返す。
* $xpathEntry : エントリのXPathオブジェクト。
* $currentEntry : 現在のエントリ位置を表すXPath文字列。
*/
function renderFormItem( $xpathEntry, $currentEntry )
{
$xmlEntryDataArray = $xpathEntry->xpath_eval( $currentEntry . '/' . $this->dataName );
$value = $xmlEntryDataArray->nodeset[0]->get_content();
$strFormHTML = '' . "\n";
return $strFormHTML;
}
/* ----------------------------------------------------------------
* フォーム項目を描画するHTMLを返す。
* $xpathEntry : エントリのXPathオブジェクト。
* $currentEntry : 現在のエントリ位置を表すXPath文字列。
*/
function renderFormItemXML( $xpathEntry, $currentEntry, &$xmlOutputEntryData )
{
$xmlEntryDataArray = $xpathEntry->xpath_eval( $currentEntry . '/' . $this->dataName );
$value = $xmlEntryDataArray->nodeset[0]->get_content();
// リクエストに値があれば、その値を再表示する(エラー時に前回入力値が保証されるようにする)
if ( isset( $_POST[ $this->dataName ] ) )
{
$value = $_POST[ $this->dataName ];
}
$xmlDocOutput = $xmlOutputEntryData->owner_document();
foreach ( $this->menuitems as $itemKey => $itemCaption )
{
$xmlOutputOption = $xmlDocOutput->create_element('option');
if ( $itemKey == $value )
{
$xmlOutputOption->set_attribute('selected', 'selected');
}
$xmlOutputOption->set_attribute('value', fileconv( $itemKey ) );
$xmlOutputOption->set_content( fileconv( $itemCaption ) );
$xmlOutputEntryData->append_child( $xmlOutputOption );
}
}
}
?>