<?php
require_once DAO . 'OccupationDao.php';
require_once DAO . 'CategoryDao.php';
require_once DAO . 'ConditionDao.php';
require_once DAO . 'CompensationDao.php';
require_once DAO . 'TopicDao.php';
require_once DTO . 'TopDto.php';
final class Top extends Action {
  private $dto;
  public function __construct() {
    $this->dto = new TopDto();
  }
  protected function getDto() {
    return $this->dto;
  }
  public function index() {
    $dao = new OccupationDao();
    $result = $dao->getAll();
    while ($row = mysql_fetch_assoc($result)) {
      $this->dto->occupation[] = array('name' => $row['occupation_name'], 'value' => $row['occupation_id']);
      $this->dto->category[$row['occupation_id']] = array();
    }
    $dao = new CategoryDao();
    $result = $dao->getAll();
    while ($row = mysql_fetch_assoc($result)) {
      $this->dto->category[$row['occupation_id']][] = array('name' => $row['category_name'], 'value' => $row['category_id']);
    }
    $dao = new ConditionDao();
    $result = $dao->getAll();
    while ($row = mysql_fetch_assoc($result)) {
      $this->dto->condition[] = array('name' => $row['condition_name'], 'value' => $row['condition_id']);
    }
    $dao = new CompensationDao();
    $result = $dao->getAll();
    while ($row = mysql_fetch_assoc($result)) {
      $this->dto->compensation[] = array('name' => $row['compensation_name'], 'value' => $row['compensation_id']);
    }
    $dao = new TopicDao();
    $this->dto->topic = mysql_fetch_assoc($dao->getByPk(1))['topic'];
    if (empty($this->dto->topic)) {
      $this->dto->topic = 'お知らせはありません。';
    }
    return new forward();
  }
}
// EOF.
