public function actionCalculate($id, $code)
 {
     // Загрузка таблицы для блока
     $table = Table::model()->findByPK((int) $id);
     if ($table === null) {
         throw new CHttpException('404');
     }
     // Устанавливаем источники данных
     $person = null;
     $event = null;
     $personForm = new PersonForm();
     $eventForm = new EventForm();
     $this->performAjaxValidation(array($personForm, $eventForm), $code);
     if ($table->source_destiny_table == Table::SOURCE_FROM_USER && ($personFormData = Yii::app()->getRequest()->getPost('PersonForm')) !== null) {
         $personForm->setAttributes($personFormData);
         if ($personForm->validate()) {
             $person = new Person();
             $person->setAttributes(array('name' => $personForm->name, 'gender' => $personForm->gender, 'date' => $personForm->date, 'time' => $personForm->getTime(), 'city_id' => $personForm->city_id));
         }
     }
     if ($table->source_event_table == Table::SOURCE_FROM_USER && ($eventFormData = Yii::app()->getRequest()->getPost('EventForm')) !== null) {
         $eventForm->setAttributes($eventFormData);
         if ($eventForm->date != '' || $eventForm->city_id != '' || $eventForm->hour != '' || $eventForm->minute != '') {
             if ($eventForm->validate()) {
                 $event = new Event();
                 $event->setAttributes(array('date' => $eventForm->date, 'time' => $eventForm->getTime(), 'city_id' => $eventForm->city_id));
             }
         }
     }
     if (Yii::app()->request->isAjaxRequest) {
         if ($personForm->hasErrors() || $eventForm->hasErrors()) {
             $personForm->addErrors($eventForm->getErrors());
             Yii::app()->ajax->failure($personForm->getErrors());
         } else {
             $arr = explode('-', $code);
             $blockId = key_exists(0, $arr) ? (int) $arr[0] : '';
             $this->widget('application.modules.bazi.widgets.TableWidget', array('model_id' => $table->id, 'block_id' => $blockId, 'person' => $person, 'event' => $event));
         }
     }
     return false;
 }