<?php
require_once DAO . 'OfferDao.php';
require_once DAO . 'OfferOutlineDao.php';
require_once DAO . 'OfferSalaryDao.php';
require_once DAO . 'OfferCompensationDao.php';
require_once DAO . 'OfferHoursDao.php';
require_once DAO . 'OfferConditionDao.php';
require_once DAO . 'OfferRemarkDao.php';
require_once DAO . 'OfferTimeDao.php';
require_once DTO . 'JobDetailDto.php';
final class JobDetail extends Action {
  private $dto;
  public function __construct() {
    $this->dto = new JobDetailDto();
  }
  protected function getDto() {
    return $this->dto;
  }
  public function index() {
    $this->dto->offerCode = $this->dto->option;
    $dao = new OfferDao();
    if (!($offer = mysql_fetch_assoc($dao->getByPk($this->dto->offerCode)))) {
      return new Redirect('not_found', DOMAIN);
    }
    $this->dto->shopName = $offer['shop_name'];
    $this->dto->title = $offer['title'];
    $this->dto->celebrate = $offer['celebrate'];
    $this->dto->photo_2 = $offer['photo_2'];
    $this->dto->message = $offer['message'];
    $this->dto->prefectureName = $offer['prefecture_name'];
    $this->dto->cityName = $offer['city_name'];
    $this->dto->wardName = $offer['ward_name'];
    $this->dto->address = $offer['address'];
    $this->dto->access = $offer['access'];
    $this->dto->lat = $offer['lat'];
    $this->dto->lng = $offer['lng'];
    $this->dto->delFlag = $offer['del_flag'];

    $dao = new OfferOutlineDao();
    $outlineList = $dao->getByOfferCode($this->dto->offerCode);
    while ($outline = mysql_fetch_assoc($outlineList)) {
      $this->dto->outlineList[$outline['occupation_name']][$outline['category_name']][] = $outline['content_name'];
    }
    $dao = new OfferSalaryDao();
    $salaryList = $dao->getByOfferCode($this->dto->offerCode);
    while ($salary = mysql_fetch_assoc($salaryList)) {
      $this->dto->salaryList[] = $salary['salary'];
    }
    $dao = new OfferCompensationDao();
    $compensationList = $dao->getByOfferCode($this->dto->offerCode);
    while ($compensation = mysql_fetch_assoc($compensationList)) {
      $this->dto->compensationList[] = $compensation['compensation_name'];
    }
    $dao = new OfferHoursDao();
    $timeList = $dao->getByOfferCode($this->dto->offerCode);
    while ($time = mysql_fetch_assoc($timeList)) {
      $this->dto->timeList[] = array('start_time' => $time['start_time'], 'start_min' => $time['start_min'], 'end_time' => $time['end_time'], 'end_min' => $time['end_min']);
    }
    $dao = new OfferConditionDao();
    $conditionList = $dao->getByOfferCode($this->dto->offerCode);
    while ($condition = mysql_fetch_assoc($conditionList)) {
      $this->dto->conditionList[] = $condition['condition_name'];
    }
    $dao = new OfferRemarkDao();
    $remarkList = $dao->getByOfferCode($this->dto->offerCode);
    while ($remark = mysql_fetch_assoc($remarkList)) {
      $this->dto->remarkList[] = $remark['remark'];
    }
    $dao = new OfferTimeDao();
    $boxList = $dao->getByOfferCode($this->dto->offerCode);
    while ($box = mysql_fetch_assoc($boxList)) {
      $this->dto->boxList[$box['search_time']] = 'dummy';
    }
    return new forward();
  }
}
// EOF.
