public function actionSave()
 {
     $arr = CRequest::getArray("CModel");
     if ($arr["work_type"] == "1") {
         $load = CIndPlanManager::getLoad($arr["load_id"]);
         $object = new CIndPlanPersonLoadTable($load);
         $object->setAttributes(CRequest::getArray($object::getClassName()));
         if ($object->validate()) {
             $object->save();
             if ($this->continueEdit()) {
                 $this->redirect("work.php?action=add&id=" . $object->getLoad()->getId() . "&type=1" . "&year=" . $object->getLoad()->year_id);
             } else {
                 $this->redirect("load.php?action=view&id=" . $object->getLoad()->person_id . "&year=" . $object->getLoad()->year_id);
             }
             return true;
         }
     } else {
         $object = new CIndPlanPersonWork();
         $object->setAttributes(CRequest::getArray($object::getClassName()));
         if ($object->validate()) {
             $object->save();
             if ($this->continueEdit()) {
                 $this->redirect("work.php?action=edit&id=" . $object->getId() . "&year=" . $object->load->year_id);
             } else {
                 $this->redirect("load.php?action=view&id=" . $object->load->person_id . "&year=" . $object->load->year_id);
             }
             return true;
         }
     }
     $this->setData("object", $object);
     $this->renderView("_individual_plan/work/edit.tpl");
 }
 public function save()
 {
     // удаляем старые данные
     foreach (CActiveRecordProvider::getWithCondition(TABLE_IND_PLAN_WORKS, "load_id=" . $this->getLoad()->getId() . " and work_type=1")->getItems() as $ar) {
         $ar->remove();
     }
     // добавляем новые
     foreach ($this->data as $isContract => $works) {
         foreach ($works as $type_id => $months) {
             foreach ($months as $month_id => $value) {
                 $obj = new CIndPlanPersonWork();
                 $obj->load_id = $this->getLoad()->getId();
                 $obj->work_type = "1";
                 $obj->load_month_id = $month_id;
                 $obj->load_type_id = $type_id;
                 $obj->load_is_contract = $isContract;
                 $obj->load_value = $value;
                 $obj->save();
             }
         }
     }
 }