コード例 #1
0
 public function actionRemoveContact($id)
 {
     $model = $this->loadModel($id);
     $pieces = explode(" ", $model->associatedContacts);
     $pieces = Sales::editContactsInverse($pieces);
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Sales'])) {
         $temp = $model->attributes;
         $model->attributes = $_POST['Sales'];
         $arr = $_POST['Sales']['associatedContacts'];
         foreach ($arr as $id => $contact) {
             $rel = CActiveRecord::model('Relationships')->findByAttributes(array('firstType' => 'Contacts', 'firstId' => $contact, 'secondType' => 'Sales', 'secondId' => $model->id));
             if (isset($rel)) {
                 $rel->delete();
             }
             unset($pieces[$contact]);
         }
         $temp2 = Sales::parseContactsTwo($pieces);
         $model->associatedContacts = $temp2;
         $changes = $this->calculateChanges($temp, $model->attributes);
         $model = $this->updateChangelog($model, $changes);
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('addContact', array('model' => $model, 'contacts' => $pieces, 'action' => 'Remove'));
 }