function isActive($db) { if ($this->private) { return ExceptionTrigger::raise(new GenericException('このイベントに参加することは出来ません')); } if ($this->periodDate < time()) { return ExceptionTrigger::raise(new GenericException('参加登録期限が過ぎています')); } if ($db->count(new Participant(), new C(Q::eq(Participant::columnEvent(), $this->id))) >= $this->maxParticipant) { return ExceptionTrigger::raise(new GenericException('参加登録可能人数を超えています')); } return true; }
function __init__($args) { parent::__init__($args); if (!$this->isSession('__concert_key')) { $this->setSession('__concert_key', md5(time() + mt_rand(0, 9999999))); } if ($this->isPost()) { if (!$this->isVariable('__concert_key') || $this->getVariable('__concert_key') != $this->getSession('__concert_key')) { ExceptionTrigger::raise(new GenericException('__concert_key')); Header::redirect(Rhaco::url()); } } }
function publish($src, &$paraser) { if (ExceptionTrigger::isException() && stripos($src, 'form ') !== false && SimpleTag::setof($tag, $src)) { foreach ($tag->getIn('input') as $input) { if (ExceptionTrigger::invalid($input->param('name'))) { // どうやら発行されているようだ $exceptions = ExceptionTrigger::get($input->param('name')); $addHtml = ''; foreach ($exceptions as $e) { $addHtml .= sprintf('<%s class="%s">%s</%s>', $this->tagName, $this->class, $e->getMessage(), $this->tagName); } $src = str_replace($input->getPlain(), $input->getPlain() . $addHtml, $src); } } } return $src; }
<?php require dirname(__FILE__) . '/__init__.php'; Rhaco::import('generic.Flow'); $flow = new Flow(); $db = new DbUtil(Event::connection()); if ($flow->isPost() && $flow->isVariable('answer') && strtolower($flow->getVariable('answer')) == strtolower(Rhaco::constant('ANSWER'))) { $p = $flow->toObject(new Participant()); if ($db->insert($p)) { $flow->setVariable('participant', $p); $flow->write('thanks.html'); Rhaco::end(); } } else { ExceptionTrigger::raise(new GenericException('登録に失敗しました')); } $flow->setVariable('event', $db->get(new Event(), new C(Q::depend(), Q::eq(Event::columnId(), Rhaco::constant('CURRENT_EVENT', 1))))); $flow->setVariable('hatena', Rhaco::obj('HatenaSyntax', array('headlevel' => 4, 'id' => 'event_description'))); $flow->write('index.html');