• R/O
  • SSH
  • HTTPS

kaede: Commit


Commit MetaInfo

Revision151 (tree)
Time2007-03-02 20:11:39
Authorhawkring

Log Message

サンプルその2・5画面ウィザード追加

Change Summary

Incremental Difference

--- Kaede/branches/try-state-pattern/examples/webapp/actions/Ex2/wizard.dicon.php (nonexistent)
+++ Kaede/branches/try-state-pattern/examples/webapp/actions/Ex2/wizard.dicon.php (revision 151)
@@ -0,0 +1,9 @@
1+<?php
2+
3+return array('components' => array(
4+ 'db' => array(
5+ 'constructor' => 'Ex2_RecipeDB'
6+ )
7+ ));
8+
9+?>
--- Kaede/branches/try-state-pattern/examples/webapp/actions/Ex2/Confirm.php (nonexistent)
+++ Kaede/branches/try-state-pattern/examples/webapp/actions/Ex2/Confirm.php (revision 151)
@@ -0,0 +1,37 @@
1+<?php
2+
3+class Ex2_Confirm extends Kaede_Core_Action_Stateful
4+{
5+ var $db;
6+ var $db_BINDING;
7+
8+ var $genre;
9+ var $foodstuff;
10+ var $recipe;
11+
12+ function start(&$req)
13+ {
14+ $this->genre = $this->db->getGenre($this->get('genre_id'));
15+ $this->foodstuff = $this->db->getFoodstuff($this->get('foodstuff_id'));
16+ $this->recipe = $this->db->getRecipe($this->get('recipe_id'));
17+ $this->render();
18+ }
19+
20+ function exec_post(&$req)
21+ {
22+ $this->db->save($this->get('genre_id'),
23+ $this->get('foodstuff_id'),
24+ $this->get('recipe_id'));
25+ $this->context->redirect($this->context->getNextAction());
26+ }
27+
28+ function exec_back(&$req)
29+ {
30+ $this->context->redirect($this->context->getPreviousAction());
31+ }
32+
33+ //サンプル表示用
34+ var $file = __FILE__;
35+}
36+
37+?>
--- Kaede/branches/try-state-pattern/examples/webapp/actions/Ex2/Page1.php (nonexistent)
+++ Kaede/branches/try-state-pattern/examples/webapp/actions/Ex2/Page1.php (revision 151)
@@ -0,0 +1,33 @@
1+<?php
2+
3+class Ex2_Page1 extends Kaede_Core_Action_Stateful
4+{
5+ var $FLOW_ENTRY = 'wizard';
6+ var $FLOW_ACTIONS = array('ex2_page2', 'ex2_page3', 'ex2_confirm', 'ex2_done');
7+
8+ function start(&$req)
9+ {
10+ $this->render();
11+ }
12+
13+ function exec_post(&$req)
14+ {
15+ if($this->validate($req)) {
16+ $this->context->redirect($this->context->getNextAction());
17+ return true;
18+ }
19+ }
20+
21+ function validate(&$req)
22+ {
23+ if(!$req->get('name')) {
24+ $this->addError('お名前が入力されていません');
25+ }
26+ return !$this->hasErrors();
27+ }
28+
29+ //サンプル表示用
30+ var $file = __FILE__;
31+}
32+
33+?>
--- Kaede/branches/try-state-pattern/examples/webapp/actions/Ex2/Page2.php (nonexistent)
+++ Kaede/branches/try-state-pattern/examples/webapp/actions/Ex2/Page2.php (revision 151)
@@ -0,0 +1,54 @@
1+<?php
2+
3+class Ex2_Page2 extends Kaede_Core_Action_Stateful
4+{
5+ var $db;
6+ var $db_BINDING;
7+
8+ var $genres = array();
9+ var $foodstuffs = array();
10+
11+ function start(&$req)
12+ {
13+ $this->genres = $this->db->findGenres();
14+ $this->foodstuffs = $this->db->findFoodstuffs();
15+ $this->render();
16+ }
17+
18+ function exec_post(&$req)
19+ {
20+ if($this->validate($req)) {
21+ $this->context->redirect($this->context->getNextAction());
22+ return true;
23+ }
24+ }
25+
26+ function validate(&$req)
27+ {
28+ if(!$req->get('genre_id')) {
29+ $this->addError('ジャンルが選択されていません');
30+ }
31+ elseif(!$this->db->getGenre($this->get('genre_id'))) {
32+ $this->addError('ジャンルは選択肢の中から選んでください');
33+ }
34+
35+ if(!$req->get('foodstuff_id')) {
36+ $this->addError('食材が選択されていません');
37+ }
38+ elseif(!$this->db->getFoodstuff($this->get('foodstuff_id'))) {
39+ $this->addError('食材は選択肢の中から選んでください');
40+ }
41+
42+ return !$this->hasErrors();
43+ }
44+
45+ function exec_back(&$req)
46+ {
47+ $this->context->redirect($this->context->getPreviousAction());
48+ }
49+
50+ //サンプル表示用
51+ var $file = __FILE__;
52+}
53+
54+?>
--- Kaede/branches/try-state-pattern/examples/webapp/actions/Ex2/Page3.php (nonexistent)
+++ Kaede/branches/try-state-pattern/examples/webapp/actions/Ex2/Page3.php (revision 151)
@@ -0,0 +1,45 @@
1+<?php
2+
3+class Ex2_Page3 extends Kaede_Core_Action_Stateful
4+{
5+ var $db;
6+ var $db_BINDING;
7+
8+ var $recipes = array();
9+
10+ function start(&$req)
11+ {
12+ $this->recipes = $this->db->findRecipes($this->get('genre_id'),
13+ $this->get('foodstuff_id'));
14+ $this->render();
15+ }
16+
17+ function exec_post(&$req)
18+ {
19+ if($this->validate($req)) {
20+ $this->context->redirect($this->context->getNextAction());
21+ return true;
22+ }
23+ }
24+
25+ function validate(&$req)
26+ {
27+ if(!$req->get('recipe_id')) {
28+ $this->addError('料理が選択されていません');
29+ }
30+ elseif(!$this->db->getRecipe($this->get('recipe_id'))) {
31+ $this->addError('料理は選択肢の中から選んでください');
32+ }
33+ return !$this->hasErrors();
34+ }
35+
36+ function exec_back(&$req)
37+ {
38+ $this->context->redirect($this->context->getPreviousAction());
39+ }
40+
41+ //サンプル表示用
42+ var $file = __FILE__;
43+}
44+
45+?>
--- Kaede/branches/try-state-pattern/examples/webapp/actions/Ex2/Done.php (nonexistent)
+++ Kaede/branches/try-state-pattern/examples/webapp/actions/Ex2/Done.php (revision 151)
@@ -0,0 +1,15 @@
1+<?php
2+
3+class Ex2_Done extends Kaede_Core_Action_Stateful
4+{
5+ function start(&$req)
6+ {
7+ $this->render();
8+ $this->context->finish();
9+ }
10+
11+ //サンプル表示用
12+ var $file = __FILE__;
13+}
14+
15+?>
--- Kaede/branches/try-state-pattern/examples/webapp/components/Ex2/RecipeDB.php (nonexistent)
+++ Kaede/branches/try-state-pattern/examples/webapp/components/Ex2/RecipeDB.php (revision 151)
@@ -0,0 +1,93 @@
1+<?php
2+
3+class Ex2_RecipeDB
4+{
5+ var $_genres = array(
6+ 1 => 'イタリアン',
7+ 2 => 'フレンチ',
8+ 3 => '和食'
9+ );
10+
11+ var $_foodstuffs = array(
12+ 20 => '肉',
13+ 21 => '魚',
14+ 22 => '野菜'
15+ );
16+
17+ var $_recipes = array();
18+
19+ function Ex2_RecipeDB()
20+ {
21+ $recipeStr = <<<EOF
22+1,20,牛薄切り肉のピッツァイオーラ
23+1,20,鶏胸肉のチーズはさみ焼き
24+1,21,たちうおのムニエル
25+1,21,ナポリの溺れだこ
26+1,22,茄子の薄切りグリル ドライトマト風味
27+1,22,カリフラワーのフリット
28+2,20,リヨン風ビーフステーキ
29+2,20,ビーフストロガノフ
30+2,21,鯛の蒸し焼きズッキーニ添え
31+2,21,舌平目のムニエル
32+2,22,トマトの詰め物プロヴァンス風
33+2,22,生ハム入りじゃがいものガレット
34+3,20,鶏ごぼう巻きの照り煮
35+3,20,牛肉のたたき
36+3,21,いわしの利休焼き
37+3,21,鯛のかぶと煮
38+3,21,さわらの南蛮漬け
39+3,22,ふろふき大根のゆず味噌がけ
40+3,22,焼きえびいものくるみ味噌田楽
41+EOF;
42+ $id = 101;
43+ foreach(explode("\n",$recipeStr) as $row) {
44+ list($genre_id, $foodstuff_id, $name) = explode(",", $row);
45+ $this->_recipes[$id] = compact('id', 'genre_id', 'foodstuff_id', 'name');
46+ $id++;
47+ }
48+ }
49+
50+ function findFoodstuffs()
51+ {
52+ return $this->_foodstuffs;
53+ }
54+
55+ function findGenres()
56+ {
57+ return $this->_genres;
58+ }
59+
60+ function getFoodstuff($id)
61+ {
62+ return isset($this->_foodstuffs[$id]) ? $this->_foodstuffs[$id] : null;
63+ }
64+
65+ function getGenre($id)
66+ {
67+ return isset($this->_genres[$id]) ? $this->_genres[$id] : null;
68+ }
69+
70+ function findRecipes($genre_id, $foodstuff_id)
71+ {
72+ $ret = array();
73+ foreach($this->_recipes as $row) {
74+ if($genre_id == $row['genre_id'] &&
75+ $foodstuff_id == $row['foodstuff_id']) {
76+ $ret[] = $row;
77+ }
78+ }
79+ return $ret;
80+ }
81+
82+ function getRecipe($id)
83+ {
84+ return isset($this->_recipes[$id]) ? $this->_recipes[$id] : null;
85+ }
86+
87+ function save()
88+ {
89+ //nothing to do
90+ }
91+}
92+
93+?>
--- Kaede/branches/try-state-pattern/examples/webapp/templates/index.html (revision 150)
+++ Kaede/branches/try-state-pattern/examples/webapp/templates/index.html (revision 151)
@@ -8,7 +8,8 @@
88 <body>
99 <p>テストページです。</p>
1010 <ul>
11- <li><a href="<?php $h($action->request->getServer('SCRIPT_NAME')) ?>/ex1/input">入力→確認→完了</a></li>
11+ <li><a href="<?php $h($helper->getURL('ex1_input', false)) ?>">入力→確認→完了</a></li>
12+ <li><a href="<?php $h($helper->getURL('ex2_page1', false)) ?>">5画面ウィザード</a></li>
1213 </ul>
1314 </body>
1415 </html>
\ No newline at end of file
--- Kaede/branches/try-state-pattern/examples/webapp/templates/ex2/confirm.html (nonexistent)
+++ Kaede/branches/try-state-pattern/examples/webapp/templates/ex2/confirm.html (revision 151)
@@ -0,0 +1,40 @@
1+<!DOCTYPE HTML PUBLIC "-//W4C//DTD HTML 4.01//EN" "http://www.w4.org/TR/html4/strict.dtd">
2+<html>
3+ <head>
4+ <meta http-equiv="content-type" content="text/html; charset=UTF-8">
5+ <link rel="stylesheet" type="text/css" href="/style/kaede-ex1.css">
6+ <title>料理注文ウィザード [4]</title>
7+ </head>
8+ <body>
9+ <h1>料理注文ウィザード [4]</h1>
10+ <p>
11+ <?php $h($action->get("name")) ?>さん
12+ </p>
13+ <?php include(dirname(__FILE__).'/_error-panel.html') ?>
14+
15+ <form action="" method="post">
16+ <?php echo $contextKey ?>
17+ <table>
18+ <tr>
19+ <th>ジャンル</th><td><?php $h($action->genre) ?></td>
20+ </tr>
21+ <tr>
22+ <th>食材</th><td><?php $h($action->foodstuff) ?></td>
23+ </tr>
24+ <tr>
25+ <th>料理</th><td><?php $h($action->recipe['name']) ?></td>
26+ </tr>
27+ </table>
28+ <p>
29+ 注文は以上でよろしいでしょうか。<br />
30+ <small>(冷静に考えるとこの確認画面はおかしいな……あくまで例なので許しておくれ)</small>
31+ </p>
32+ <p>
33+ <input type="submit" name="__exec_back" value="戻る">
34+ <input type="submit" value="送信">
35+ </p>
36+ </form>
37+ <div class="code"><?php highlight_file($action->file) ?></div>
38+ <div class="code"><?php highlight_file(__FILE__) ?></div>
39+ </body>
40+</html>
\ No newline at end of file
--- Kaede/branches/try-state-pattern/examples/webapp/templates/ex2/page1.html (nonexistent)
+++ Kaede/branches/try-state-pattern/examples/webapp/templates/ex2/page1.html (revision 151)
@@ -0,0 +1,31 @@
1+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2+<html>
3+ <head>
4+ <meta http-equiv="content-type" content="text/html; charset=UTF-8">
5+ <link rel="stylesheet" type="text/css" href="/style/kaede-ex1.css">
6+ <title>料理注文ウィザード</title>
7+ </head>
8+ <body>
9+ <h1>料理注文ウィザード</h1>
10+ <p>
11+ 5画面のウィザードのテストです。
12+ </p>
13+ <p>
14+ まずはお名前を入力してください。
15+ </p>
16+ <?php include(dirname(__FILE__).'/_error-panel.html') ?>
17+
18+ <form action="" method="post">
19+ <?php echo $contextKey ?>
20+ <table>
21+ <tr>
22+ <th>お名前</th>
23+ <td><input type="text" name="name" value="<?php $h($action->get('name', '')) ?>"></td>
24+ </tr>
25+ </table>
26+ <p><input type="submit" value="次へ"></p>
27+ </form>
28+ <div class="code"><?php highlight_file($action->file) ?></div>
29+ <div class="code"><?php highlight_file(__FILE__) ?></div>
30+ </body>
31+</html>
\ No newline at end of file
--- Kaede/branches/try-state-pattern/examples/webapp/templates/ex2/page2.html (nonexistent)
+++ Kaede/branches/try-state-pattern/examples/webapp/templates/ex2/page2.html (revision 151)
@@ -0,0 +1,66 @@
1+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2+<html>
3+ <head>
4+ <meta http-equiv="content-type" content="text/html; charset=UTF-8">
5+ <link rel="stylesheet" type="text/css" href="/style/kaede-ex1.css">
6+ <title>料理注文ウィザード [2]</title>
7+ </head>
8+ <body>
9+ <h1>料理注文ウィザード [2]</h1>
10+ <p>
11+ ようこそ <?php $h($action->get("name")) ?>さん
12+ </p>
13+ <p>
14+ 料理のジャンルとメインの食材を選択してください。
15+ </p>
16+ <?php include(dirname(__FILE__).'/_error-panel.html') ?>
17+
18+ <form action="" method="post">
19+ <?php echo $contextKey ?>
20+ <table>
21+ <tr>
22+ <th>ジャンル</th>
23+ <td>
24+ <ul>
25+ <?php foreach($action->genres as $genre_id => $genre_name): ?>
26+ <li>
27+ <input
28+ type="radio"
29+ name="genre_id"
30+ value="<?php $h($genre_id) ?>"
31+ id="genre_id_<?php $h($genre_id) ?>"
32+ <?php echo($genre_id == $action->get('genre_id')) ? ' checked="checked" ' : '' ?>>
33+ <label for="genre_id_<?php $h($genre_id) ?>"><?php $h($genre_name) ?></label>
34+ </li>
35+ <?php endforeach; ?>
36+ </ul>
37+ </td>
38+ </tr>
39+ <tr>
40+ <th>食材</th>
41+ <td>
42+ <ul>
43+ <?php foreach($action->foodstuffs as $foodstuff_id => $foodstuff_name): ?>
44+ <li>
45+ <input
46+ type="radio"
47+ name="foodstuff_id"
48+ value="<?php $h($foodstuff_id) ?>"
49+ id="foodstuff_id_<?php $h($foodstuff_id) ?>"
50+ <?php echo($foodstuff_id == $action->get('foodstuff_id')) ? ' checked="checked" ' : '' ?>>
51+ <label for="foodstuff_id_<?php $h($foodstuff_id) ?>"><?php $h($foodstuff_name) ?></label>
52+ </li>
53+ <?php endforeach; ?>
54+ </ul>
55+ </td>
56+ </tr>
57+ </table>
58+ <p>
59+ <input type="submit" name="__exec_back" value="戻る">
60+ <input type="submit" value="次へ">
61+ </p>
62+ </form>
63+ <div class="code"><?php highlight_file($action->file) ?></div>
64+ <div class="code"><?php highlight_file(__FILE__) ?></div>
65+ </body>
66+</html>
\ No newline at end of file
--- Kaede/branches/try-state-pattern/examples/webapp/templates/ex2/page3.html (nonexistent)
+++ Kaede/branches/try-state-pattern/examples/webapp/templates/ex2/page3.html (revision 151)
@@ -0,0 +1,48 @@
1+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2+<html>
3+ <head>
4+ <meta http-equiv="content-type" content="text/html; charset=UTF-8">
5+ <link rel="stylesheet" type="text/css" href="/style/kaede-ex1.css">
6+ <title>料理注文ウィザード [3]</title>
7+ </head>
8+ <body>
9+ <h1>料理注文ウィザード [3]</h1>
10+ <p>
11+ ようこそ <?php $h($action->get("name")) ?>さん
12+ </p>
13+ <p>
14+ 料理を選択してください。
15+ </p>
16+ <?php include(dirname(__FILE__).'/_error-panel.html') ?>
17+
18+ <form action="" method="post">
19+ <?php echo $contextKey ?>
20+ <table>
21+ <tr>
22+ <th>料理</th>
23+ <td>
24+ <ul>
25+ <?php foreach($action->recipes as $recipe_id => $recipe): ?>
26+ <li>
27+ <input
28+ type="radio"
29+ name="recipe_id"
30+ value="<?php $h($recipe['id']) ?>"
31+ id="recipe_id_<?php $h($recipe['id']) ?>"
32+ <?php echo($recipe['id'] == $action->get('recipe_id')) ? ' checked="checked" ' : '' ?>>
33+ <label for="recipe_id_<?php $h($recipe['id']) ?>"><?php $h($recipe['name']) ?></label>
34+ </li>
35+ <?php endforeach; ?>
36+ </ul>
37+ </td>
38+ </tr>
39+ </table>
40+ <p>
41+ <input type="submit" name="__exec_back" value="戻る">
42+ <input type="submit" value="次へ">
43+ </p>
44+ </form>
45+ <div class="code"><?php highlight_file($action->file) ?></div>
46+ <div class="code"><?php highlight_file(__FILE__) ?></div>
47+ </body>
48+</html>
\ No newline at end of file
--- Kaede/branches/try-state-pattern/examples/webapp/templates/ex2/_error-panel.html (nonexistent)
+++ Kaede/branches/try-state-pattern/examples/webapp/templates/ex2/_error-panel.html (revision 151)
@@ -0,0 +1,7 @@
1+ <?php if($action->hasErrors()): ?>
2+ <ul class="error">
3+ <?php foreach($action->getErrors(true) as $msg): ?>
4+ <li><?php $h($msg) ?></li>
5+ <?php endforeach; ?>
6+ </ul>
7+ <?php endif; ?>
--- Kaede/branches/try-state-pattern/examples/webapp/templates/ex2/done.html (nonexistent)
+++ Kaede/branches/try-state-pattern/examples/webapp/templates/ex2/done.html (revision 151)
@@ -0,0 +1,19 @@
1+<!DOCTYPE HTML PUBLIC "-//W5C//DTD HTML 5.01//EN" "http://www.w5.org/TR/html5/strict.dtd">
2+<html>
3+ <head>
4+ <meta http-equiv="content-type" content="text/html; charset=UTF-8">
5+ <link rel="stylesheet" type="text/css" href="/style/kaede-ex1.css">
6+ <title>料理注文ウィザード [5]</title>
7+ </head>
8+ <body>
9+ <h1>料理注文ウィザード [5]</h1>
10+ <p>
11+ <?php $h($action->get("name")) ?>さん
12+ </p>
13+ <p>
14+ 正常に注文が行われました。<a href="">最初のページに戻る</a>
15+ </p>
16+ <div class="code"><?php highlight_file($action->file) ?></div>
17+ <div class="code"><?php highlight_file(__FILE__) ?></div>
18+ </body>
19+</html>
\ No newline at end of file
Show on old repository browser