Nested ObjectArray
orを再帰関数で解析するにはどうすればよいObjectArray Tree
ですか? また、各ノード/カーソルを取得するにはどうすればよいですか?
私はそれをパーサーして、1 つの組織化された構造を作成します。
私の ObjectArray ツリーは次のようになります。
object(stdClass)[248]
'id' => int 0
'type' => string 'root' (length=4)
'related_dropzone_id' => int 0
'related_dropzone_order' => int 0
'options' =>
object(stdClass)[250]
'children' =>
object(stdClass)[249]
'1376112098462' =>
(stdClass)[247]
'id' => string '1376112098462' (length=13)
'type' => string 'section' (length=7)
'related_dropzone_id' => int 0
'related_dropzone_order' => int 0
'dropzones' =>
object(stdClass)[246]
...
'options' =>
object(stdClass)[245]
...
'children' =>
object(stdClass)[244]
...
'1376112118210' =>
object(stdClass)[252]
'id' => string '1376112118210' (length=13)
'type' => string 'section' (length=7)
'related_dropzone_id' => int 0
'related_dropzone_order' => int 1
'dropzones' =>
object(stdClass)[255]
...
'options' =>
object(stdClass)[253]
...
'children' =>
object(stdClass)[254]
...
それには、私にとって有効な情報を含む子の紹介子があり、それを解析する必要があります。
これは私の関数コードです:
static public function get_content_html_render_LOM( $data_LOM , $handlebars_instance = '' , $template = '' ) {
static $template_result = ''; // Save the result html always - recursion
if ( $handlebars_instance == '' || ! ( $handlebars_instance instanceof Handlebars_Engine ) ) {
Handlebars_Autoloader::register();
$handlebars_instance = new Handlebars_Engine;
}
if ( isset ( $data_LOM->children ) )
foreach ( $data_LOM->children as $cursor ) {
$template_children = self::read_data_file( SpireBuilder::$widgets_dir . $cursor->type . '/templates/front-end.php' , array() );
if ( isset($cursor->related_dropzone_id) && $cursor->related_dropzone_id == 0 ){
$template = $template_children ; // esto tengo que cambiarlo pues cuando llega a un nuevo nodo
}
// Render template with data
if ( ! isset( $cursor->children ) )
$template_result = $handlebars_instance->render( $template , $cursor );
else {
//dropzones = srray vacio
// Por cada dropzone del lom hacer un foreach
// temporal children = children de childre
// ordenado children = ordenar temportal childre
// por cada children de este children
// si dropne.'i' == children[related dropxzone id]
// dropzone.'í' = templaate childre
// si no noop
$template_result = $handlebars_instance->render( $template , array( 'options' => $cursor->options , 'dropzones' => array( 'A' => $template_children ) ) );
//var_dump($template_result);
}
self::get_content_html_render_LOM( $cursor , $handlebars_instance , $template_result );
}
return $template_result;
}