jcj Posted February 17, 2013 Share Posted February 17, 2013 Hi all, I'm new to Yii and learning based on Larry's work-in-progress book and the online resources. I'm doing some work for a non-profit as my first Yii project and trying to create an event reservation app for them using Yii. Here's a "working" demo of the form I am working with: http://dev.inglouriousdesigners.com/aers/index.php/Reservation/create?eventRecord=6 Just to give some background data, the relationships look like this. I left out some fields for the sake of brevity. tbl_event (Event model) event_id (pk) title descr ..... tbl_reservation reservation_id (pk) event_record_id (fk --> eventRecord->event_record_id) cust_name cust_address1 visitor_count (sum of ticket count) txn_amount (dollar amount of ticketcount*(rate) for each rate selection) <snipped additional fields -- see form> tbl_reservation_detail reservation_detail_id (pk) reservation_id (fk --> tbl_reservation->reservation_id) rate_id (fk --> tbl_rate-->rate_id) quantity (count of tickets of type rate_id) tbl_event_record (EventRecord model) event_record_Id (pk) event_id (fk --> event->event_id) start_datetime end_datetime max_occupancy (Max # of visitors for this time slot.) reserved_occupancy (Currently reserved spots for this eventRecord.) ... tbl_rate rate_id (pk) event_id (fk --> event->event_id) rate_class_id (fk --> rateClass->rate_class_id) amount ... tbl_rate_class rate_class_id (pk) descr (Description of rate class ex: "Adult", "Child" "Senior Citizen") ... What I'm working on is the Reservation/Create action as shown on this demo page: http://dev.inglouriousdesigners.com/aers/index.php/Reservation/create?eventRecord=6 I can save customer information to the Reservation model (except txn amount and visitor count). That was easy.. What I want to implement is this: On the form in the "Ticket Information" section, change this to a cGridView (or similar) to show Rate Class (rateClass->descr) Cost (rate->amount) Desired Tickets Adult 10.00 (dropdown list) Child 9.00 (dropdown list) Member 5.00 (dropdown list) Senior citizen 5.00 (dropdown list) Then, below that, show: Total Tickets: ___ Amount: _____ <Reserve Button> The form should, via ajax/jquery or whatever the Yii appropriate method is, not permit > "Tickets Available" (eventrecord->max_occupancy - eventrecord->reserved_occupancy) to be selected in any combination on the dropdowns. Calculate the total amount at the bottom. Then validate everything and save Reservation and ReservationDetail models. Also, update EventRecord model with the new reserved_occupancy value (this is easy.. I can do that.) I'm lost on the on-form calculations and the correct way to do the validation. I'll gladly *pay* someone for their time to help if you have a good solution. In a time crunch as the non-profit has tours coming up soon that they will need this app for. Thanks in advance! Jeff Link to comment Share on other sites More sharing options...
Antonio Conte Posted February 18, 2013 Share Posted February 18, 2013 I'm only allowed to pick 5 tickets, and the rest seems to get calculated correctly. Did you get this to work now? Link to comment Share on other sites More sharing options...
jcj Posted February 19, 2013 Author Share Posted February 19, 2013 I'm only allowed to pick 5 tickets, and the rest seems to get calculated correctly. Did you get this to work now? It..sort of works. The code in the view is hackish and ugly. It isn't very Yii-like. It's just using plain old Javascript to do the calculations and update the total div and refresh the dropdown options. This is fine for the order form (Except I just noticed you can proceed to Reserve with 0 tickets selected), but when I need to go back to "edit' that form (ie: the user wants to go back and change ticket selections after viewing the confirmation page), I can't get the ticket selections to load back into the bottom part of the form. Which, is obviously because they're not really tied to the model. I'd also prefer to show the ticket options in a cGridView or similar just since I think it would look better. It all almost works..just not well enough and not in a manner that I'd call "clean" Link to comment Share on other sites More sharing options...
Antonio Conte Posted February 19, 2013 Share Posted February 19, 2013 Without any real experience with YII, I could recommend you a combination of the CRangeValidator and the CNumberValidator. Build this into your Validate() method of the model. The CNumberValidator allows you to specify a max and a min, and the range can be defined using a list of viable options. Run that method from your controller to validate. That's the proper way to do it. Regarding the actual validation, I guess you have better knowledge than me on valid/invalid cases. Link to comment Share on other sites More sharing options...
Recommended Posts