Exemplo n.º 1
0
 function actionLike()
 {
     $user_id = $_REQUEST['uid'];
     $style_id = $_REQUEST['sid'];
     //记录存储到like表
     $likeModel = new LikeModel();
     $ret = LikeModel::model()->find('user_id=:userid and style_id=:styleid', array(':userid' => $user_id, ':styleid' => $style_id));
     if (!isset($ret)) {
         $likeModel->user_id = $user_id;
         $likeModel->style_id = $style_id;
         $likeModel->like_time = time();
         if (!$likeModel->save()) {
             echo "like record saved fail!";
         }
     } else {
         echo json_encode(array('result' => 0, 'comment' => "you have liked it!"));
         return;
     }
     //修改style表,like_num 加1
     $styleModel = new StyleModel();
     $connection = Yii::app()->db;
     $sql = "select like_num from tbl_style where _id = :style_id";
     $command = $connection->createCommand($sql);
     $tmp = $command->query(array(':style_id' => $style_id))->readAll();
     $styleModel->updateByPk($style_id, array('like_num' => $tmp[0]["like_num"] + 1));
     echo json_encode(array('result' => 1, 'res' => array('style_id' => $likeModel->style_id, 'like_num' => $tmp[0]["like_num"] + 1)));
 }
Exemplo n.º 2
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 the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = StyleModel::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Exemplo n.º 3
0
 public function index()
 {
     if (in_array(Auth::getCapability(), array(CAPABILITY_ADMINISTRATOR))) {
         Model::autoloadModel('style');
         $model = new StyleModel($this->db);
         $this->para = new stdClass();
         if (isset($_POST['type'])) {
             $this->para->type = $_POST['type'];
         }
         if (isset($_POST['orderby'])) {
             $this->para->orderby = $_POST['orderby'];
         }
         if (isset($_POST['order'])) {
             $this->para->order = $_POST['order'];
         }
         if (isset($_POST['page'])) {
             $this->para->page = $_POST['page'];
         }
         if (isset($_POST['s'])) {
             $this->para->s = $_POST['s'];
         }
         if (isset($_POST['paged'])) {
             $this->para->paged = $_POST['paged'];
         }
         if (isset($_POST['styles'])) {
             $this->para->styles = $_POST['styles'];
         }
         if (isset($_POST['action'])) {
             $this->para->action = $_POST['action'];
         }
         if (isset($_POST['action2'])) {
             $this->para->action2 = $_POST['action2'];
         }
         if (isset($_POST['description_show'])) {
             $this->para->description_show = $_POST['description_show'];
         }
         if (isset($_POST['slug_show'])) {
             $this->para->slug_show = $_POST['slug_show'];
         }
         if (isset($_POST['tours_show'])) {
             $this->para->tours_show = $_POST['tours_show'];
         }
         if (isset($_POST['styles_per_page'])) {
             $this->para->styles_per_page = $_POST['styles_per_page'];
         }
         if (isset($_POST['adv_setting'])) {
             $this->para->adv_setting = $_POST['adv_setting'];
         }
         if (isset($this->para->adv_setting) && $this->para->adv_setting == "adv_setting") {
             $model->changeAdvSetting($this->para);
         }
         if (isset($this->para->type) && in_array($this->para->type, array("action", "action2")) && isset($this->para->styles)) {
             $model->executeAction($this->para);
         }
         $model->search($this->view, $this->para);
         if (count((array) $this->para) > 0) {
             $this->view->ajax = TRUE;
             $this->view->renderAdmin(RENDER_VIEW_STYLE_INDEX, TRUE);
         } else {
             $this->view->renderAdmin(RENDER_VIEW_STYLE_INDEX);
         }
     } else {
         $this->login();
     }
 }
Exemplo n.º 4
0
 public function actionUpload()
 {
     if (!isset(Yii::app()->user->id)) {
         $this->redirect(array('style/index'));
     }
     $isSuc = false;
     $userId = isset($_REQUEST['id']) ? trim(strip_tags($_REQUEST['id'])) : null;
     //本地
     //$root = YiiBase::getPathOfAlias('webroot').Yii::app()->getBaseUrl();
     //服务器代码
     $root = YiiBase::getPathOfAlias('webroot');
     $folder = $root . '/images/images/styles/' . $userId . '/';
     $desFilePath;
     $tmpFilePath;
     $relPath = Yii::app()->getBaseUrl() . '/images/images/styles/' . $userId . '/';
     $this->mkDirIfNotExist($folder);
     if ($_FILES["file"]["type"] == "image/gif" || $_FILES["file"]["type"] == "image/jpeg" || $_FILES["file"]["type"] == "image/png" || $_FILES["file"]["type"] == "image/jpg" || $_FILES["file"]["type"] == "image/pjpeg") {
         if ($_FILES["file"]["error"] > 0) {
             $isSuc = false;
         } else {
             $tmpFilePath = $_FILES["file"]["tmp_name"];
             /*
             				$array = explode("/", $tmpFilePath); 
             				var_dump($array[ count($array) -1]);
             			    $tmpPath  = $tmpPath.$array[ count($array) -1];
             */
             $name = $this->getUploadImageFileName($_FILES["file"]["name"]);
             $desFilePath = $folder . $name;
             $desThumbPath = $folder . 'thumb/' . $name;
             $relPath = $relPath . $name;
             if (file_exists($desFilePath)) {
                 unlink($desFilePath);
                 //echo $_FILES["file"]["name"] . " already exists. ";
             } else {
                 move_uploaded_file($tmpFilePath, $desFilePath);
                 //生成缩略图
                 $im = null;
                 $imtp = null;
                 if ($_FILES["file"]["type"] == "image/gif") {
                     $im = imagecreatefromgif($desFilePath);
                     $imtp = 'gif';
                 } else {
                     if ($_FILES["file"]["type"] == "image/jpg" || $_FILES["file"]["type"] == "image/jpeg") {
                         $im = imagecreatefromjpeg($desFilePath);
                         $imtp = 'jpg';
                     } else {
                         if ($_FILES["file"]["type"] == "image/png") {
                             $im = imagecreatefrompng($desFilePath);
                             $imtp = 'png';
                         }
                     }
                 }
                 $this->mkDirIfNotExist($folder . 'thumb/');
                 CThumb::resizeImage($im, 100, 100, $desThumbPath, $imtp);
                 //------------生成缩略图
                 $isSuc = true;
             }
         }
     } else {
         $isSuc = false;
     }
     if ($isSuc) {
         $styleModel = new StyleModel();
         $styleModel->image = $relPath;
         $styleModel->user_id = $userId;
         $styleModel->create_time = time();
         $styleModel->like_num = 0;
         $styleModel->recommand_val = 0;
         if (!$styleModel->save()) {
             echo "style saved fail!";
             return false;
         }
         $host = 'http://' . Yii::app()->request->getServerName();
         //本地调试
         $styleModel->image = $host . $styleModel->image;
         //服务器
         //$styleModel->image = $host.Yii::app()->getBaseUrl().$styleModel->image;
         $this->redirect(array('Upload2/index'));
     } else {
         echo "upload failed";
     }
 }
Exemplo n.º 5
0
<?php

$descr = $_GET['Descr'];
$style_id = $_GET['StyleId'];
$styleModel = new StyleModel();
$styleModel->updateByPk($style_id, array('descr' => $descr, 'updatetime' => time()));
exit;