Beispiel #1
0
 public function actionAdd()
 {
     $request = Yii::app()->request;
     try {
         $post_content = StringHelper::filterString($request->getPost('post_content'));
         $user_id = StringHelper::filterString($request->getPost('user_id'));
         $location = StringHelper::filterString($request->getPost('location'));
         $cats = $request->getPost('cats');
         if (count($_FILES['images']['tmp_name']) > 1) {
             $url_arr = UploadHelper::getUrlUploadMultiImages($_FILES['images'], $user_id);
         } else {
             $url_arr = UploadHelper::getUrlUploadSingleImage($_FILES['images'], $user_id);
         }
         // $album = StringHelper::filterString($request->getPost('album'));
         $album = NULL;
         $res = Posts::model()->addPost($user_id, $post_content, $location, $url_arr, $album, $cats);
         if ($res != FALSE) {
             ResponseHelper::JsonReturnSuccess($res, "Success");
         } else {
             ResponseHelper::JsonReturnError("", "Server Error");
         }
     } catch (Exception $ex) {
         var_dump($ex->getMessage());
     }
 }
Beispiel #2
0
 public function actionEditProcess()
 {
     try {
         $post = StringHelper::filterArrayString($_POST);
         $path = null;
         if (isset($_FILES['file'])) {
             $path = UploadHelper::getUrlUploadSingleImage($_FILES['file'], 'file');
         }
         $result = Document::model()->edit($_POST, $path);
         if ($result == 1) {
             Yii::app()->user->setFlash('success', 'Cập nhật dữ liệu thành công !');
             $this->redirect(Yii::app()->createUrl('document/edit', array('id' => $post['id'])));
         } else {
             if ($result == 2) {
                 Yii::app()->user->setFlash('error', 'Cập nhật dữ liệu thất bại !');
                 $this->redirect(Yii::app()->createUrl('document/edit', array('id' => $post['id'])));
             } else {
                 Yii::app()->user->setFlash('error', 'Không tồn tại tài liệu !');
                 $this->redirect(Yii::app()->createUrl('document/edit', array('id' => $post['id'])));
             }
         }
     } catch (Exception $ex) {
         var_dump($ex->getMessage());
     }
 }
 public function add($attr, $image)
 {
     $model = new Post();
     $model->setAttributes($attr);
     $model->date = time();
     $model->post_comment_count = 0;
     $model->post_like_count = 0;
     $image_url = null;
     if (isset($image)) {
         $image_url = UploadHelper::getUrlUploadSingleImage($image, $attr['user_id']);
     }
     $location = new Location();
     $location->longitude = $attr['lng'];
     $location->latitude = $attr['lat'];
     $location->name = $attr['name'];
     $location->save(FALSE);
     $model->image = $image_url;
     $model->location_id = $location->location_id;
     if ($model->save(FALSE)) {
         $subject_arr = json_decode($attr['subject'], true);
         foreach ($subject_arr as $item) {
             $subject_post = new PostSubject();
             $subject_post->post_id = $model->post_id;
             $subject_post->subject_id = $item;
             $subject_post->save(FALSE);
         }
         return TRUE;
     }
     return FALSE;
 }
 public function actionUploadImage()
 {
     $user_id = Yii::app()->request->getPost('user_id');
     if (empty($user_id)) {
         $user_id = 1;
     }
     $url = UploadHelper::getUrlUploadSingleImage($_FILES['image'], $user_id);
     ResponseHelper::JsonReturnSuccess($url, 'Success');
 }
Beispiel #5
0
 public function actionAddEvent()
 {
     try {
         $attr = StringHelper::filterArrayString($_POST);
         $image = UploadHelper::getUrlUploadSingleImage($_FILES['image'], $_POST['created_by']);
         if (Events::model()->addEvent($attr, $image)) {
             ResponseHelper::JsonReturnSuccess('', 'Success');
         } else {
             ResponseHelper::JsonReturnError('', 'Server Error');
         }
     } catch (Exception $ex) {
         var_dump($ex->getMessage());
     }
 }
Beispiel #6
0
 public function actionRegisterStaff()
 {
     $image_preview = null;
     $post = StringHelper::filterArrayString($_POST);
     if ($_FILES['image']['error'] != 4) {
         $image_preview = UploadHelper::getUrlUploadSingleImage($_FILES['image'], 'service_image');
         $post['avatar'] = $image_preview;
     }
     if (Provider::model()->registerStaff($post)) {
         ResponseHelper::JsonReturnSuccess('', 'Success');
     } else {
         ResponseHelper::JsonReturnError('', 'Error');
     }
 }
 public function actionAddCeleb()
 {
     $this->pageTitile = 'Thêm người nổi tiếng';
     $request = Yii::app()->request;
     try {
         $celeb_image = UploadHelper::getUrlUploadSingleImage($_FILES['celeb_image'], 'celebs_image');
         $celeb_cover = UploadHelper::getUrlUploadSingleImage($_FILES['celeb_cover'], 'celebs_cover');
         $res = Celebrities::model()->addCeleb($_POST, $celeb_image, $celeb_cover);
         if ($res != FALSE) {
             Yii::app()->user->setFlash('success', 'Thêm người nổi tiếng thành công');
         } else {
             Yii::app()->user->setFlash('error', 'Có lỗi xảy ra');
         }
         $this->redirect(Yii::app()->createUrl('celebrity/add'));
     } catch (Exception $ex) {
         var_dump($ex->getMessage());
     }
 }
 public function updateProfile($attr, $obj_files)
 {
     $check = User::model()->findByPk($attr['user_id']);
     if ($check) {
         $check->setAttributes($attr);
         if (isset($obj_files)) {
             $avatar = UploadHelper::getUrlUploadSingleImage($obj_files, $attr['user_id']);
             $check->avatar = $avatar;
         }
         if ($check->save(FALSE)) {
             return 'success';
         } else {
             return 'server error';
         }
     } else {
         return 'User not exist';
     }
 }
Beispiel #9
0
 public function actionUpdateInfo()
 {
     $request = Yii::app()->request;
     if ($request->isPostRequest && isset($_POST)) {
         try {
             $post = StringHelper::filterArrayString($_POST);
             //$user_id = StringHelper::filterArrayString($request->getPost('user_id'));
             $user_id = Yii::app()->session['user_id'];
             $user_photo = null;
             $user_cover = null;
             if ($_FILES["user_photo"]["error"] != 4) {
                 $user_photo = UploadHelper::getUrlUploadSingleImage($_FILES['user_photo'], $user_id);
             }
             if ($_FILES["user_cover"]["error"] != 4) {
                 $user_cover = UploadHelper::getUrlUploadSingleImage($_FILES['user_cover'], $user_id);
             }
             if (User::model()->updateUserInfo($user_id, $post, $user_photo, $user_cover)) {
                 // ResponseHelper::JsonReturnSuccess("", "Success");
                 Yii::app()->user->setFlash('success', 'Lưu thông tin thành công');
                 $this->redirect(Yii::app()->createUrl('user/editProfile'));
             } else {
                 //ResponseHelper::JsonReturnError("", "Server Error");
                 Yii::app()->user->setFlash('error', 'Lưu thông tin thất bại');
                 $this->redirect(Yii::app()->createUrl('user/editProfile'));
             }
         } catch (exception $e) {
             var_dump($e->getMessage());
         }
         Yii::app()->end();
     }
 }