/**
  * 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()
 {
     if (isset($_GET['form'])) {
         $form_id = $_GET['form'];
         $model = Form::model()->findByPk($form_id);
         $table_name = $model->TABLE_NAME;
         $this->loadModel($form_id)->delete();
         if (Yii::app()->db->schema->getTable($table_name)) {
             Yii::app()->db->createCommand()->dropTable($table_name);
             FormField::model()->deleteAllByAttributes(array('FORM_ID' => $form_id));
         }
     } else {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     // 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('all'));
     }
 }
Ejemplo n.º 2
0
 public static function getFields()
 {
     $form_id = Yii::app()->params['form-id'];
     self::$_model = FormField::model()->findAllByAttributes(array('FORM_ID' => $form_id), array('order' => 'POSITION ASC'));
     return self::$_model;
 }
 public function actionView()
 {
     if (isset($_GET['form'])) {
         $table_id = $_GET['form'];
         if (isset($_GET['entry'])) {
             $entry_id = $_GET['entry'];
             $fields = FormField::model()->findAllByAttributes(array('FORM_ID' => $table_id), array('order' => 'POSITION ASC'));
         } else {
             $entry_id = NULL;
         }
     } else {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     $this->render('view', array('model' => $this->loadModel($table_id, $entry_id), 'table_id' => $table_id, 'entry_id' => $entry_id, 'fields' => $fields, 'form' => Form::model()->findByPk($table_id)));
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return FormField the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = FormField::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }