Ejemplo n.º 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']);
 }
Ejemplo n.º 2
0
 public function insert(Advice $advice)
 {
     $advice->setAdviceId(null);
     $advice->setCreatedAt(new DateTime());
     $sql = 'insert into ' . $this->tableName . '(adviceId, content,createdBy,createdAt) ' . 'values( :adviceId, :content, :createdBy, :createdAt)';
     return $this->execute($sql, $advice);
     //$statement = $this->getDb()->prepare($sql);
     // $data =  AdviceMapper::getParams($advice);
     //echo $data[':content'];
     //$statement->execute($data);
     // echo date_format($advice->getCreatedAt(), 'Y-m-d H:i:s');
 }
Ejemplo n.º 3
0
 public function run($args)
 {
     $user_info = Admin::model()->findAll();
     $count = Advice::model()->count('status=0');
     foreach ($user_info as $row) {
         if ($row->send_email == 0 || empty($row->email)) {
             continue;
         }
         $message = "您今天新增" . $count . "条后勤办反馈建议\n\t        \t\t'http://localhost/logistics/index.php?r=admin/index/index' 点击链接登录后台进行查看";
         $mailer = Yii::createComponent('application.extensions.mailer.EMailer');
         $mailer->Host = 'smtp.qq.com';
         $mailer->IsSMTP();
         $mailer->SMTPAuth = true;
         $mailer->From = '*****@*****.**';
         $mailer->AddReplyTo("{$row->email}");
         $mailer->AddAddress("{$row->email}");
         $mailer->FromName = '你大爷';
         $mailer->Username = '******';
         //这里输入发件地址的用户名
         $mailer->Password = '******';
         //这里输入发件地址的密码
         $mailer->SMTPDebug = true;
         //设置SMTPDebug为true,就可以打开Debug功能,根据提示去修改配置
         $mailer->CharSet = 'UTF-8';
         $mailer->Subject = Yii::t('demo', 'Yii rulez!');
         $mailer->Body = $message;
         $x = $mailer->Send();
         $x = $mailer->Send();
     }
 }
Ejemplo n.º 4
0
 public static function map(Advice $advice, array $properties)
 {
     if (array_key_exists('adviceId', $properties)) {
         $advice->setAdviceId($properties['adviceId']);
     }
     if (array_key_exists('content', $properties)) {
         $advice->setContent($properties['content']);
     }
     if (array_key_exists('createdBy', $properties)) {
         $advice->setCreatedBy($properties['createdBy']);
     }
     if (array_key_exists('createdAt', $properties)) {
         $createdAt = DateTransform::createDateTime($properties['createdAt']);
         if ($createdAt) {
             $advice->setCreatedAt($createdAt);
         }
     }
 }
Ejemplo n.º 5
0
 /**
  *  发布一则反馈
  */
 public function actionUpdateStatus($aid = 0)
 {
     if ($aid != 0) {
         $model = Advice::model()->findByPk($aid);
         if (isset($model->aid)) {
             $model->attributes = array('status' => 1);
         }
         if ($model->save()) {
             $this->redirect(array('index'));
         }
     }
     $this->redirect(array('index'));
 }
 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;
 }
Ejemplo n.º 7
0
 /**
  * Declares an association between this object and a Advice object.
  *
  * @param      Advice $v
  * @return     Images The current object (for fluent API support)
  * @throws     PropelException
  */
 public function setAdvice(Advice $v = null)
 {
     if ($v === null) {
         $this->setAdviceId(NULL);
     } else {
         $this->setAdviceId($v->getId());
     }
     $this->aAdvice = $v;
     // Add binding for other direction of this n:n relationship.
     // If this object has already been added to the Advice object, it will not be re-added.
     if ($v !== null) {
         $v->addImages($this);
     }
     return $this;
 }
Ejemplo n.º 8
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));
 }
Ejemplo n.º 9
0
 public function processImportAdvices($advices, $advices_lang, $id_lang)
 {
     $formated_advices_lang = array();
     foreach ($advices_lang as $lang) {
         $formated_advices_lang[$lang->id_ps_advice] = array('html' => array($id_lang => $lang->html));
     }
     $current_advices = array();
     $result = Db::getInstance()->ExecuteS('SELECT id_advice, id_ps_advice FROM ' . _DB_PREFIX_ . 'advice');
     foreach ($result as $row) {
         $current_advices[(int) $row['id_ps_advice']] = (int) $row['id_advice'];
     }
     $cond_ids = $this->getFormatedConditionsIds();
     foreach ($advices as $advice) {
         try {
             //if advice already exist we update language data
             if (isset($current_advices[$advice->id_ps_advice])) {
                 $adv = new Advice($current_advices[$advice->id_ps_advice]);
                 $adv->html[$id_lang] = $formated_advices_lang[$advice->id_ps_advice]['html'][$id_lang];
                 $adv->update();
                 $this->processAdviceAsso($adv->id, $advice->display_conditions, $advice->hide_conditions, $advice->tabs, $cond_ids);
                 unset($current_advices[$advice->id_ps_advice]);
             } else {
                 $advice_data = array_merge((array) $advice, $formated_advices_lang[$advice->id_ps_advice]);
                 $adv = new Advice();
                 $adv->hydrate($advice_data, (int) $id_lang);
                 $adv->id_tab = (int) Tab::getIdFromClassName($advice->tab);
                 $adv->add();
                 $this->processAdviceAsso($adv->id, $advice->display_conditions, $advice->hide_conditions, $advice->tabs, $cond_ids);
             }
             unset($adv);
         } catch (Exception $e) {
             continue;
         }
     }
 }
Ejemplo n.º 10
0
 public function ajaxProcessCloseAdvice()
 {
     $id_advice = Advice::getIdByIdPs((int) Tools::getValue('id_advice'));
     Db::getInstance()->execute('UPDATE `ps_advice` SET `hide` =  \'1\' WHERE  `id_advice` = ' . (int) $id_advice . ';');
     die;
 }
Ejemplo n.º 11
0
 /**
  * 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 Advice the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Advice::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Ejemplo n.º 12
0
 /**
  * 选时间段画出统计图
  */
 private function analyse($time = -1, $all = 1)
 {
     $criteria = new CDbCriteria();
     $criteria->select = 'cid';
     if ($all == 0) {
         $criteria->addCondition('`status`=0');
     }
     if ($time > 0) {
         $start_time = date("Y-m-d H:i:s", strtotime("-{$time} week"));
         $end_time = date("Y-m-d H:i:s", time());
         $criteria->addCondition("create_time>'" . $start_time . "'");
         $criteria->addCondition("create_time<'" . $end_time . "'");
     } else {
         if ($time == 0) {
             $end_time = date("Y-m-d H:i:s", strtotime("{$time} week"));
             $start_time = date("Y-m-d 00:00:00", time());
             $criteria->addCondition("create_time>'" . $start_time . "'");
             $criteria->addCondition("create_time<'" . $end_time . "'");
         }
     }
     $model = Advice::model()->findAll($criteria);
     if (count($model) == 0) {
         return array();
     }
     $data = array();
     $cate_name = array();
     $cates = Category::model()->findAll();
     foreach ($cates as $row) {
         $cate_name[$row->cid] = $row->cname;
         $data[$cate_name[$row->cid]] = 0;
     }
     foreach ($model as $row) {
         $data[$cate_name[$row->cid]]++;
     }
     return $data;
 }
Ejemplo n.º 13
0
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param      Advice $value A Advice object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(Advice $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }
Ejemplo n.º 14
0
 /**
  *  查看近一个星期的反馈情况
  */
 private function analyse($id)
 {
     $criteria = new CDbCriteria();
     $criteria->select = array('create_time');
     $criteria->addCondition('cid=' . $id);
     $start_time = date("Y-m-d H:i:s", strtotime("-1 week"));
     $end_time = date("Y-m-d H:i:s", time());
     $criteria->addCondition("create_time>'" . $start_time . "'");
     $criteria->addCondition("create_time<'" . $end_time . "'");
     //$criteria -> order =  'create_time desc';
     $model = Advice::model()->findAll($criteria);
     if (count($model) == 0) {
         return array();
     }
     $data = array();
     for ($i = 0; $i < 7; $i++) {
         $data[date("Y-m-d ", strtotime("-{$i} day"))] = 0;
     }
     foreach ($model as $row) {
         $date = substr($row->create_time, 0, 10);
         $data[$date]++;
     }
     return $data;
 }
Ejemplo n.º 15
0
 public function processImportAdvices($advices, $advices_lang, $id_lang)
 {
     $formated_advices_lang = array();
     foreach ($advices_lang as $lang) {
         $formated_advices_lang[$lang->id_ps_advice] = array('html' => array($id_lang => $lang->html));
     }
     $current_advices = array();
     $result = Db::getInstance()->ExecuteS('SELECT id_advice FROM ' . _DB_PREFIX_ . 'advice');
     foreach ($result as $row) {
         $current_advices[] = (int) $row['id_advice'];
     }
     $cond_ids = $this->getFormatedConditionsIds();
     foreach ($advices as $advice) {
         try {
             //if advice already exist we update language data
             if (in_array($advice->id_ps_advice, $current_advices)) {
                 $adv = new Advice($advice->id_ps_advice);
                 $bdg->html[$id_lang] = $formated_advices_lang[$advice->id_ps_advice]['html'][$id_lang];
                 $adv->update();
                 unset($current_advices[$advice->id_ps_advice]);
             } else {
                 $advice_data = array_merge((array) $advice, $formated_advices_lang[$advice->id_ps_advice]);
                 $adv = new Advice();
                 $adv->hydrate($advice_data, (int) $id_lang);
                 $adv->id_tab = (int) Tab::getIdFromClassName($advice->tab);
                 $adv->add();
                 foreach ($advice->display_conditions as $cond) {
                     Db::getInstance()->insert('condition_advice', array('id_condition' => $cond_ids[$cond], 'id_advice' => $adv->id, 'display' => 1));
                 }
                 foreach ($advice->hide_conditions as $cond) {
                     Db::getInstance()->insert('condition_advice', array('id_condition' => $cond_ids[$cond], 'id_advice' => $adv->id, 'display' => 0));
                 }
             }
             unset($adv);
         } catch (Exception $e) {
             continue;
         }
     }
     // Delete advices that are not in the file anymore
     foreach ($current_advices as $id_advice) {
         // Check that the advice is used in this language
         $html = Db::getInstance()->getValue('SELECT html FROM ' . _DB_PREFIX_ . 'advice_lang WHERE id_advice = ' . (int) $id_advice . ' AND id_lang = ' . (int) $id_lang);
         if (!$html) {
             continue;
         }
         $adv = new Advice($id_advice);
         $adv->delete();
     }
 }