<?php
final class OfferCodeDao extends Dao {
  private static $ALL = <<<'SQL'
select prefecture_id,
       city_id,
       ward_id,
       offer_no
  from offer_code
 order by prefecture_id,
       city_id,
       ward_id
SQL;
  private static $PK = <<<'SQL'
select prefecture_id,
       city_id,
       ward_id,
       offer_no
  from offer_code
 where prefecture_id = '%s'
   and city_id = '%s'
   and ward_id ='%s'
SQL;
  private static $UPDATE = <<<'SQL'
update offer_code
   set offer_no = LAST_INSERT_ID(offer_no + 1)
 where prefecture_id = '%s'
   and city_id = '%s'
   and ward_id ='%s'
SQL;
  private static $LAST_INSERT_ID = <<<'SQL'
select LAST_INSERT_ID()
SQL;
  public function getAll() {
    return $this->execute(self::$ALL);
  }
  public function getByPk($pk) {
  }
  public function getNextVal($prefectureId, $cityId, $wardId) {
    $this->execute(self::$UPDATE, array($prefectureId, $cityId, $wardId));
    return $prefectureId . $cityId . $wardId . str_pad(mysql_result($this->execute(self::$LAST_INSERT_ID), 0), 5, '0', STR_PAD_LEFT);
  }
}
// EOF.
