예제 #1
0
 /**
  * Deletes a particular model.
  * If deletion is successful, the browser will be redirected to the 'admin' page.
  * @param integer $id the ID of the model to be deleted
  */
 public function actionDelete($id)
 {
     if (Yii::app()->request->isPostRequest) {
         UserLogs::createLog('Delete ' . get_class($this->loadModel($id)) . ' ' . $id);
         // we only allow deletion via POST request
         $this->loadModel($id)->delete();
         // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
         if (!isset($_GET['ajax'])) {
             $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
         }
     } else {
         throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.');
     }
 }
 public function actionCreateContact($id)
 {
     $customerContact = new CustomerContact();
     $contact = new Contact();
     $customer = Customer::model()->findByPk($id);
     // Uncomment the following line if AJAX validation is needed
     $this->performAjaxValidation(array($customerContact));
     if (isset($_POST['Contact']) && isset($_POST['CustomerContact'])) {
         $trans = Yii::app()->db->beginTransaction();
         try {
             $contact->attributes = $_POST['Contact'];
             $customerContact->attributes = $_POST['CustomerContact'];
             if ($customerContact->save()) {
                 $contact->parent_model = 'CustomerContact';
                 $contact->parent_id = $customerContact->id;
                 if ($contact->save()) {
                     $trans->commit();
                     UserLogs::createLog('create new ' . get_class($contact) . ' ' . $contact->primaryKey);
                     Yii::app()->user->setFlash('success', 'Contact Customer sudah ditambah.');
                     $this->redirect(array('customer/update', 'id' => $id));
                 } else {
                     throw new CustomerControllerException($contact->getErrors());
                 }
             } else {
                 throw new CustomerControllerException($customerContact->getErrors());
             }
         } catch (CustomerControllerException $e) {
             $trans->rollback();
         } catch (CDbException $e) {
             $trans->rollback();
         }
     }
     $customerContact->customer_id = $id;
     $this->render('create_contact', array('contact' => $contact, 'customerContact' => $customerContact, 'id' => $id, 'customer_name' => $customer->name));
 }