Practical symfony 4日目

#### Practical symfony 4日目(http://www.symfony-project.org/jobeet/1_4/Doctrine/ja/04)
#### デフォルトのレイアウトを編集
> notepad .\apps\frontend\templates\layout.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
	<!-- apps/frontend/templates/layout.php -->
	<head>
		<!-- <?php include_http_metas() ?> -->
		<!-- <?php include_metas() ?> -->
		<!-- <?php include_title() ?> -->
		<title>Jobeet - Your best job board</title>
		<link rel="shortcut icon" href="/favicon.ico" />
		<?php include_javascripts() ?>
		<?php include_stylesheets() ?>
	</head>
	<body>
		<div id="container">
			<div id="header">
				<div class="content">
					<h1>
						<a href="<?php echo url_for('job/index') ?>">
							<img src="/images/logo.jpg" alt="Jobeet Job Board" />
						</a>
					</h1>
					<div id="sub_header">
						<div class="post">
							<h2>Ask for people</h2>
							<div>
								<a href="<?php echo url_for('job/index') ?>">Post a Job</a>
							</div>
						</div>
						
						<div class="search">
							<h2>Ask for a job</h2>
							<form action="" method="get">
								<input type="text" name="keywords" id="search_keywords" />
								<input type="submit" value="search" />
								<div class="help">Enter some keywords (city, country, position, ...)</div>
							</form>
						</div>
					</div>
				</div>
			</div>
			
			<div id="content">
				<?php if ($sf_user->hasFlash('notice')): ?>
					<div class="flash_notice">
						<?php echo $sf_user->getFlash('notice') ?>
					</div>
				<?php endif ?>
				<?php if ($sf_user->hasFlash('error')): ?>
					<div class="flash_error">
						<?php echo $sf_user->getFlash('error') ?>
					</div>
				<?php endif ?>
				<div class="content">
					<?php echo $sf_content ?>
				</div>
			</div>
			
			<div id="footer">
				<div class="content">
					<span class="symfony">
						<img src="/images/jobeet-mini.png" />powered by <a href="http://www.symfony-project.org/"><img src="/images/symfony.gif" alt="symfony framework" /></a>
					</span>
					<ul>
						<li>
							<a href="">About Jobeet</a>
						</li>
						<li class="feed">
							<a href="">Full feed</a>
						</li>
						<li>
							<a href="">Jobeet API</a>
						</li>
						<li class="last">
							<a href="">Affiliates</a>
						</li>
					</ul>
				</div>
			</div>
		</div>
	</body>
</html>

#### アセットをダウンロード
wget --directory-prefix=.\web\images http://www.symfony-project.org/get/jobeet/images.zip
wget --directory-prefix=.\web\css    http://www.symfony-project.org/get/jobeet/css.zip
wget --directory-prefix=.\web        http://www.symfony-project.org/get/jobeet/favicon.ico

#### コマンドライン用の適当なアーカイバーが入ってなかったので
#### GUI で image.zip と css.zip を展開、main.css は空のファイルがあったので上書き
#### ブラウザで表示を確認。

#### view の設定を確認する
> notepad .\apps\frontend\config\view.yml

#### job モジュールの view を設定する
> mkdir .\apps\frontend\modules\job\config
> notepad .\apps\frontend\modules\job\config\view.yml
# jobeet ではこのファイルへの記述の代わりに use_stylesheet() ヘルパーを使うらしいので動作確認時に一時的に有効化する
# indexSuccess:
#   stylesheets: [jobs.css]
#   stylesheets: [jobs.css, print: { media: print }]
# 
# showSuccess:
#   stylesheets: [job.css]
#   stylesheets: [job.css, print: { media: print }]

#### use_stylesheet() を使うように書き換え
> notepad .\apps\frontend\modules\job\templates\indexSuccess.php
> notepad .\apps\frontend\modules\job\templates\showSuccess.php

#### Controller の中身を確認
> notepad .\apps\frontend\modules\job\actions\actions.class.php

#### トップページのテンプレートを編集
> notepad .\apps\frontend\modules\job\templates\indexSuccess.php
<!-- apps/frontend/modules/job/templates/indexSuccess.php -->
<?php use_stylesheet('jobs.css') ?>

<!--
<h1>Jobeet jobs List</h1>

<table>
	<thead>
		<tr>
			<th>Id</th>
			<th>Category</th>
			<th>Type</th>
			<th>Company</th>
			<th>Logo</th>
			<th>Url</th>
			<th>Position</th>
			<th>Location</th>
			<th>Description</th>
			<th>How to apply</th>
			<th>Token</th>
			<th>Is public</th>
			<th>Is activated</th>
			<th>Email</th>
			<th>Expires at</th>
			<th>Created at</th>
			<th>Updated at</th>
		</tr>
	</thead>
	<tbody>
		<?php foreach ($jobeet_jobs as $jobeet_job): ?>
			<tr>
				<td><a href="<?php echo url_for('job/show?id='.$jobeet_job->getId()) ?>"><?php echo $jobeet_job->getId() ?></a></td>
				<td><?php echo $jobeet_job->getCategoryId() ?></td>
				<td><?php echo $jobeet_job->getType() ?></td>
				<td><?php echo $jobeet_job->getCompany() ?></td>
				<td><?php echo $jobeet_job->getLogo() ?></td>
				<td><?php echo $jobeet_job->getUrl() ?></td>
				<td><?php echo $jobeet_job->getPosition() ?></td>
				<td><?php echo $jobeet_job->getLocation() ?></td>
				<td><?php echo $jobeet_job->getDescription() ?></td>
				<td><?php echo $jobeet_job->getHowToApply() ?></td>
				<td><?php echo $jobeet_job->getToken() ?></td>
				<td><?php echo $jobeet_job->getIsPublic() ?></td>
				<td><?php echo $jobeet_job->getIsActivated() ?></td>
				<td><?php echo $jobeet_job->getEmail() ?></td>
				<td><?php echo $jobeet_job->getExpiresAt() ?></td>
				<td><?php echo $jobeet_job->getCreatedAt() ?></td>
				<td><?php echo $jobeet_job->getUpdatedAt() ?></td>
			</tr>
		<?php endforeach; ?>
	</tbody>
</table>

<a href="<?php echo url_for('job/new') ?>">New</a>
-->
<div id="jobs">
	<table class="jobs">
		<?php foreach ($jobeet_jobs as $i => $job): ?>
			<tr class="<?php echo fmod($i, 2) ? 'even' : 'odd' ?>">
				<td class="location"><?php echo $job->getLocation() ?></td>
				<td class="position">
					<a href="<?php echo url_for('job/show?id='.$job->getId()) ?>">
						<?php echo $job->getPosition() ?>
					</a>
				</td>
				<td class="company"><?php echo $job->getCompany() ?></td>
			</tr>
		<?php endforeach ?>
	</table>
</div>

#### 求人ページのテンプレートを編集
####   (日付指定の書式を北米式から日本式にカスタマイズしてみる)
> notepad .\apps\frontend\modules\job\templates\showSuccess.php
<!-- apps/frontend/modules/job/templates/showSuccess.php -->
<?php use_stylesheet('job.css') ?>

<!-- 注意!! PHP は HTML コメントの中もスキャンしてくるー!! 余計なコードは残さないほうがいいかも
<table>
	<tbody>
		<tr>
			<th>Id:</th>
			<td><?php echo $job->getId() ?></td>
		</tr>
		<tr>
			<th>Category:</th>
			<td><?php echo $job->getCategoryId() ?></td>
		</tr>
		<tr>
			<th>Type:</th>
			<td><?php echo $job->getType() ?></td>
		</tr>
		<tr>
			<th>Company:</th>
			<td><?php echo $job->getCompany() ?></td>
		</tr>
		<tr>
			<th>Logo:</th>
			<td><?php echo $job->getLogo() ?></td>
		</tr>
		<tr>
			<th>Url:</th>
			<td><?php echo $job->getUrl() ?></td>
		</tr>
		<tr>
			<th>Position:</th>
			<td><?php echo $job->getPosition() ?></td>
		</tr>
		<tr>
			<th>Location:</th>
			<td><?php echo $job->getLocation() ?></td>
		</tr>
		<tr>
			<th>Description:</th>
			<td><?php echo $job->getDescription() ?></td>
		</tr>
		<tr>
			<th>How to apply:</th>
			<td><?php echo $job->getHowToApply() ?></td>
		</tr>
		<tr>
			<th>Token:</th>
			<td><?php echo $job->getToken() ?></td>
		</tr>
		<tr>
			<th>Is public:</th>
			<td><?php echo $job->getIsPublic() ?></td>
		</tr>
		<tr>
			<th>Is activated:</th>
			<td><?php echo $job->getIsActivated() ?></td>
		</tr>
		<tr>
			<th>Email:</th>
			<td><?php echo $job->getEmail() ?></td>
		</tr>
		<tr>
			<th>Expires at:</th>
			<td><?php echo $job->getExpiresAt() ?></td>
		</tr>
		<tr>
			<th>Created at:</th>
			<td><?php echo $job->getCreatedAt() ?></td>
		</tr>
		<tr>
			<th>Updated at:</th>
			<td><?php echo $job->getUpdatedAt() ?></td>
		</tr>
	</tbody>
</table>

<hr />

<a href="<?php echo url_for('job/edit?id='.$job->getId()) ?>">Edit</a>
&nbsp;
<a href="<?php echo url_for('job/index') ?>">List</a>

-->
<?php use_helper('Text') ?>

<div id="job">
	<h1><?php echo $job->getCompany() ?></h1>
	<h2><?php echo $job->getLocation() ?></h2>
	<h3>
		<?php echo $job->getPosition() ?>
		<small> - <?php echo $job->getType() ?></small>
	</h3>
	
	<?php if ($job->getLogo()): ?>
		<div class="logo">
			<a href="<?php echo $job->getUrl() ?>">
				<img src="/uploads/jobs/<?php echo $job->getLogo() ?>" alt="<?php echo $job->getCompany() ?> logo" />
			</a>
		</div>
	<?php endif ?>
	
	<div class="description">
		<?php echo simple_format_text($job->getDescription()) ?>
	</div>
	
	<h4>How to apply?</h4>
	
	<p class="how_to_apply"><?php echo $job->getHowToApply() ?></p>
	
	<div class="meta">
		<small>posted on <?php echo $job->getDateTimeObject('created_at')->format('Y/m/d') ?></small>
	</div>
	
	<div style="padding: 20px 0">
		<a href="<?php echo url_for('job/edit?id='.$job->getId()) ?>">Edit</a>
	</div>
</div>

#### 求人ページのテンプレートで使う変数を $jobeet_job から $job に変更する、
> notepad .\apps\frontend\modules\job\actions\actions.class.php
	public function executeShow(sfWebRequest $request)
	{
		$this->job = Doctrine_Core::getTable('JobeetJob')->find(array($request->getParameter('id')));
		$this->forward404Unless($this->job);
	}

#### タイトルを動的に変更するため title という名前のスロットを作る
> notepad .\apps\frontend\templates\layout.php
		<title>
			<?php if (!include_slot('title')): ?>
				Jobeet - Your best job board
			<?php endif ?>
		</title>

> notepad .\apps\frontend\modules\job\templates\showSuccess.php
<!-- slot の追加、4日目(http://www.symfony-project.org/jobeet/1_4/Doctrine/ja/04) の記述
     第二引数のない slot() の呼び出しは end_slot() の呼び出しまで標準出力を読むっていう事だろうか?
     後で要確認。
-->
<?php slot('title') ?>
	<?php echo sprintf('%s is looking for a %s', $job->getCompany(), $job->getPosition()) ?>
<?php end_slot() ?>

#### 4日目終了。"Post a job" の URL が間違っているっぽいけど url_for() の解説で直るんだろうか?