here is the event model
<?php
class Events extends CActiveRecord {
public static function model($className = __CLASS__) {
return parent::model($className);
}
/**
* @return string the associated database table name
*/
public function tableName() {
return 'events';
}
/**
* @return array validation rules for model attributes.
*/
public function rules() {
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('title, content, category, status, screen_shot', 'required'),
array('category, status, user_id, total_seats, available_seats, reserve_seats', 'numerical', 'integerOnly' => true),
array('title, address', 'length', 'max' => 128),
array('screen_shot, screen_shot1, screen_shot2, screen_shot3, screen_shot4, screen_shot5', 'length', 'max' => 100),
array(is_approved', 'length', 'max' => 1),
array('start_time, end_time', 'safe'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, title, theme, content, category, screen_shot, status, country, is_featured, is_approved, vote_down, vote_up, views, user_id, modified_date, update_time, timestamp', 'safe', 'on' => 'search'),
);
}
/**
* @return array relational rules.
*/
public function relations() {
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'eventcategory' => array(self::BELONGS_TO, 'Categories', 'category'),
'members' => array(self::BELONGS_TO, 'Members', 'user_id'),
'eventreg' => array(self::HAS_MANY, 'Eventregistraion', 'event_id'),
);
}
public function getSeoUrl() {
return Yii::app()->createUrl('event/view', array(
'id' => $this->id,
'title' => $this->title,
));
}
protected function beforeSave() {
if (parent::beforeSave()) {
if ($this->isNewRecord) {
// $this->timestamp = date("Y-m-d H:i:S");
$this->update_time = date("Y-m-d H:i:S");
$this->user_id = Yii::app()->user->id;
//$this->image = 'no_yii_user.png';
}
else
$this->update_time = date("Y-m-d H:i:S");
return true;
}
else
return false;
}
}
and here is in event detail page, I am pasing the event id and available_seats to the event registration form.
<div class="col-xs-3">
<button class="btn btn-default pull-right">
<?php echo CHtml::link('<i class="fa fa-sign-in"></i> Register', array('/eventregistration/create', 'eid' => $model->id, 'ts' => $model->available_seats)); ?>
</button>
</div>
and here is the eventregistration model
class Eventregistration extends CActiveRecord
{
public static function model($className=__CLASS__)
{
return parent::model($className);
}
/**
* @return string the associated database table name
*/
public function tableName()
{
return 'event_registration';
}
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('name,email, city, event_id', 'required'),
array('event_id, created_by, updated_by, updated_by, reserve_seats', 'numerical', 'integerOnly'=>true),
array('name, email, city, reason', 'length', 'max'=>200),
);
}
/**
* @return array relational rules.
*/
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'eventregistration' => array(self::BELONGS_TO, 'Events', 'event_id'),
'registerer' => array(self::BELONGS_TO, 'Members', 'created_by'),
);
}
protected function beforeSave() {
if (parent::beforeSave()) {
if ($this->isNewRecord) {
$this->created_by = Yii::app()->user->id;
$this->updated_by = Yii::app()->user->id;
$this->updated_date = date("Y-m-d H:i:S");
return true;
} else {
$this->updated_date = date("Y-m-d H:i:S");
$this->updated_by = Yii::app()->user->id;
return true;
}
} else
return false;
}
}
and here is eventRegistration form
<?php
$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
'id' => 'eventregistration-form',
'enableAjaxValidation' => false,
));
?>
<p class="help-block">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Name<span class="required">*</span></label>
<div class="col-sm-10">
<?php echo $form->textField($model, 'name', array('class' => 'form-control', 'maxlength' => 200)); ?>
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Email<span class="required">*</span></label>
<div class="col-sm-10">
<?php echo $form->textField($model, 'email', array('class' => 'form-control', 'maxlength' => 200)); ?>
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">City<span class="required">*</span></label>
<div class="col-sm-10">
<?php echo $form->textField($model, 'city', array('class' => 'form-control', 'maxlength' => 200)); ?>
</div>
</div>
<p class="">Available Seats <?php echo $_GET['ts']; ?></p>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Seats</label>
<div class="col-sm-10">
<?php echo $form->textField($model, 'reserve_seats', array('class' => 'form-control', 'maxlength' => 3)); ?>
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Reason</label>
<div class="col-sm-10">
<?php echo $form->textArea($model, 'reason', array('col' => 6, 'row' => 4, 'class' => 'form-control', 'maxlength' => 200)); ?>
</div>
</div>
<?php echo $form->hiddenField($model, 'event_id', array('class' => 'form-control', 'value' => $_GET['eid'])); ?>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<?php
$this->widget('bootstrap.widgets.TbButton', array(
'buttonType' => 'submit',
'type' => 'primary',
'label' => $model->isNewRecord ? 'Submit' : 'Submit',
'htmlOptions' => array('class' => 'btn btn-green'),
));
?>
</div>
</div>
<?php $this->endWidget(); ?>