how to set Event registration form

hello everyone. how are you.

I want to set the event registration form in such that, I have to models one is Event and other is Eventregistration{which is used to apply for the specific event}. Now with each event their is available seats options e.g. their are 50 seats available in this particular event. now when a user goto the detail page of an event then then their is a button of "attend event" which leads the user to a form through which he can submit the form for that perticular event and this form data is saved in the Eventregistration table and also this form contains the "seats" field which will save the number of seats to which a user is applying. Now I want that their should be a connection between the available seats (in Event model) and "seats"(of Eventregistraion model) in such a way that if there are 50 seats available and user apply for the 8 seats then next time for the other user the available seats should be displayed 42 instead of 50.

I think I have explained my problem very clearly. but if still require explaination then I’ll explain that.

and if anyone have the idea then please share with me.

I am working on my final year project and stuck here in this point.

Thanks in advance.

Can show me your related codes so i and yii other members can help you!!

do something like this. make the relation for event and seats as 1:many relation. and before registering the seats. count the total number of seats booked so that you can show the available seats as well as restrict the seats.

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(); ?>




Hi,

try with the STAT relation to get the number of reserved seats:




class Events extends CActiveRecord {


    // ....


    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(

            // ....

            'numberofreservedseats' => array(self::STAT, 'Eventregistraion', 'event_id', 'select' => 'SUM(reserve_seats)')

        );

    }


    public function getRemainSeats() {

        return $this->available_seats - $this->numberofreservedseats;

    }


    // ....

}



controller (with eager loading):




// ....

$model = Events::model()->with('numberofreservedseats')->...

// ....



view:




<?php echo $model->remainSeats; ?>



Yes he is right. follow this.

this is more of a design problem, there many things you have to consider before you tackle this, how big is the application how many seats are available for a given event …