Ejemplo n.º 1
0
 public function actionAddContact($id)
 {
     $users = User::getNames();
     $contacts = Contacts::getAllNames();
     $model = $this->loadModel($id);
     $contacts = Quote::editContactArray($contacts, $model);
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Quote'])) {
         $temp = $model->associatedContacts;
         $tempArr = $model->attributes;
         $model->attributes = $_POST['Quote'];
         $arr = $model->associatedContacts;
         foreach ($arr as $contactId) {
             $rel = new Relationships();
             $rel->firstType = 'quotes';
             $rel->firstId = $model->id;
             $rel->secondType = 'contacts';
             $rel->secondId = $contactId;
             $rel->save();
         }
         $model->associatedContacts = Quote::parseContacts($arr);
         $temp .= " " . $model->associatedContacts;
         $model->associatedContacts = $temp;
         $changes = $this->calculateChanges($tempArr, $model->attributes);
         $model = $this->updateChangelog($model, $changes);
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('addContact', array('model' => $model, 'users' => $users, 'contacts' => $contacts, 'action' => 'Add'));
 }