Example #1
0
 private function addNewAdvice()
 {
     $advice = new Advice();
     $advice->name = Input::get('name');
     $advice->id_user = Auth::user()->id;
     $advice->save();
     return Redirect::route('advice.view', ['id' => $advice->id, 'idQuestion' => 'root']);
 }
Example #2
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Advice();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Advice'])) {
         $model->attributes = $_POST['Advice'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->aid));
         }
     }
     $this->render('create', array('model' => $model));
 }
 /**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param      PropelPDO $con
  * @return     int The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws     PropelException
  * @see        save()
  */
 protected function doSave(PropelPDO $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their coresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aAdvice !== null) {
             if ($this->aAdvice->isModified() || $this->aAdvice->isNew()) {
                 $affectedRows += $this->aAdvice->save($con);
             }
             $this->setAdvice($this->aAdvice);
         }
         if ($this->asfGuardUser !== null) {
             if ($this->asfGuardUser->isModified() || $this->asfGuardUser->isNew()) {
                 $affectedRows += $this->asfGuardUser->save($con);
             }
             $this->setsfGuardUser($this->asfGuardUser);
         }
         if ($this->isNew()) {
             $this->modifiedColumns[] = CommentsPeer::ID;
         }
         // If this object has been modified, then save it to the database.
         if ($this->isModified()) {
             if ($this->isNew()) {
                 $pk = CommentsPeer::doInsert($this, $con);
                 $affectedRows += 1;
                 // we are assuming that there is only 1 row per doInsert() which
                 // should always be true here (even though technically
                 // BasePeer::doInsert() can insert multiple rows).
                 $this->setId($pk);
                 //[IMV] update autoincrement primary key
                 $this->setNew(false);
             } else {
                 $affectedRows += CommentsPeer::doUpdate($this, $con);
             }
             $this->resetModified();
             // [HL] After being saved an object is no longer 'modified'
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
 public function processAdviceValidation()
 {
     $return = true;
     $advices_to_validate = Advice::getIdsAdviceToValidate();
     $advices_to_unvalidate = Advice::getIdsAdviceToUnvalidate();
     foreach ($advices_to_validate as $id) {
         $advice = new Advice((int) $id);
         $advice->validated = 1;
         $return &= $advice->save();
     }
     foreach ($advices_to_unvalidate as $id) {
         $advice = new Advice((int) $id);
         $advice->validated = 0;
         $return &= $advice->save();
     }
     return $return;
 }
Example #5
0
 /** 
  * 前端表单 
  * 验证码有点小问题需要修改
  */
 public function actionForm()
 {
     $adviceModel = new Advice();
     $userModel = new User();
     $criteria = new CDbCriteria();
     $criteria->select = '*';
     $category_info = Category::model()->findAll($criteria);
     $category = array();
     foreach ($category_info as $row) {
         $category[$row->cid] = $row->cname;
     }
     if ($_FILES['Advice']) {
         // 保存文件,但是这样不好,需要现验证advice 之后在保存
         $set = array('image/jpeg', 'image/png', 'image/gif');
         $filename = $_FILES['Advice']['name']['picture'];
         $type = $_FILES['Advice']['type']['picture'];
         $tmp_name = $_FILES['Advice']['tmp_name']['picture'];
         $error = $_FILES['Advice']['error']['picture'];
         $size = $_FILES['Advice']['size']['picture'];
         if ($error == 0) {
             $date = date('Y-m-d', time());
             $date = str_replace('-', "", $date);
             $dir = 'uploads/' . mt_rand(1, 1000) . $date;
             //if(! is_dir($dir)) { mkdir( $dir , 0777, true);}
             $file = $dir . $_FILES['Advice']['name']['picture'];
             $success = move_uploaded_file($_FILES['Advice']['tmp_name']['picture'], $file);
             if (!$success) {
                 $adviceModel->addError('picture', '图片上传失败');
             }
             $adviceModel->picture = $file;
             /*将图片新路径押进model*/
         } else {
             $default_picture = Yii::app()->baseUrl . '/upload/1.jpeg';
             $adviceModel->picture = $default_picture;
         }
     }
     if (isset($_POST['Advice']) && isset($_POST['User'])) {
         /****************************************************/
         $_POST['User']['user_id'] = 12;
         /*由于user_id 暂时没有让用户输入,所以保留*/
         /****************************************************/
         $adviceModel->status = 0;
         /* 0 means have not read 1 opposite */
         $adviceModel->create_time = date("Y-m-d H:i:s", time());
         $adviceModel->user_id = $_POST['User']['user_id'];
         $adviceModel->content = $_POST['Advice']['content'];
         $adviceModel->cid = $_POST['Advice']['cid'];
         $userModel->user_id = $_POST['User']['user_id'];
         $userModel->username = $_POST['User']['username'];
         $userModel->mobile_phone = $_POST['User']['mobile_phone'];
         $userModel->email = $_POST['User']['email'];
         if (!isset(User::model()->findByPk($userModel->user_id)->user_id)) {
             if ($userModel->save() && $adviceModel->save()) {
                 // 新增一条反馈的同时相应类别加1
                 $cateModel = Category::model()->findByPk($adviceModel->cid);
                 echo $cateModel->num;
                 die;
                 $cateModel->num++;
                 $cateModel->save() or die('出现错误');
                 $this->redirect(array('index/success'));
             }
         } else {
             if ($adviceModel->save()) {
                 // 新增一条反馈的同时相应类别加1
                 $cateModel = Category::model()->findByPk($adviceModel->cid);
                 $cateModel->num++;
                 $cateModel->save() or die('出现错误');
                 $this->redirect(array('index/success'));
             }
         }
     }
     $this->renderPartial('form', array('adviceModel' => $adviceModel, 'userModel' => $userModel, 'category' => $category));
 }