<?php
/**
* ループ専用のテンプレート置換処理クラス
*
* HTMLテンプレート内のループの部分の置換を行うクラス
*/
class template_convert_loop extends template_convert {
/**
* テンプレート置換ロジック実行
*
*/
public function convert_template($view) {
$output_html = $view->get_output_html();
$output_buf = mb_strstr($output_html, '|||', true);
$after = mb_strstr($output_html, '|||');
$after_array = explode('|||', $after);
$name = $after_array[1];
$body = $after_array[2];
$rows = $view->get_loop_array_value($name);
if (true === isset($rows)) {
// ループ名が設定されている時のみデータもある
$row_size = count($rows);
// 表示する行数分繰り返す
for ($i = 0; $i < $row_size; $i++) {
// 初期化
$body_buf = $body;
// strstrは検索文字列が見つからない時はfalseを返すので、その間繰り返し
while (false !== ($data_before = mb_strstr($body_buf, ';;;', true))) {
$data_after = mb_substr(mb_strstr(mb_substr(mb_strstr($body_buf, ';;;'), 3), ';;;'), 3);
$data_array = explode(';;;', $body_buf);
// モデルのゲッターを実行しデータを取得
$data_value = utility::create_accessor_name($rows[$i], 'get', $data_array[1]);
$body_buf = $data_before . $data_value . $data_after;
}
$output_buf .= $body_buf;
}
}
$output_buf .= $after_array[4];
$view->set_output_html($output_buf);
}
}
?>
Author:kitoku
「奇特」を目指しているITエンジニアです。ホームページ:http://www.kitoku-magic.net/