コード例 #1
0
ファイル: Post.php プロジェクト: bolom009/testwork_api
 public function saveImage()
 {
     $imagePost = new Image();
     $nameImg = Yii::$app->security->generateRandomString(9);
     $this->img->saveAs($this->getPath() . $nameImg . "." . $this->img->extension);
     $imagePost->url = $nameImg . "." . $this->img->extension;
     $imagePost->type = Image::POST_STATUS;
     $imagePost->object_id = $this->id;
     $imagePost->save();
 }
コード例 #2
0
 /**
  * 疾病图集
  * @author gaoqing
  * @date 2016-03-25
  * @return string 视图
  */
 public function actionDisimages()
 {
     $view = "disease_images";
     $dname = $this->helpGparam('dname', "");
     $dname = trim($dname, '/');
     $domudle = $this->helpGparam('dmodule', 'tuji');
     $domudle = trim($domudle, '/');
     $pageStr = trim(trim($domudle, 'tuji'), '_');
     $page = 1;
     if (!empty($pageStr)) {
         $page = intval($pageStr);
     }
     $disease = $this->diseaseService->getDiseasesByPinyin($dname, false, false, false, false);
     //图集信息
     $icondition = ['flag' => 1, 'relid' => $disease['id']];
     $images = Image::search($icondition);
     $imagesList = $images['list'];
     //获取相关疾病图集
     $relDiseaseImages = ArticleService::getRelDiseaseImages($disease['id'], 6);
     $return_img_list = [];
     foreach ($imagesList as $k => $v) {
         $v['url'] = \librarys\helpers\utils\Url::getuploadfileUrl(1, $v['name']);
         $return_img_list[] = $v;
     }
     $params = ['disease' => $disease, 'imagesList' => $return_img_list, 'relDiseaseImages' => $relDiseaseImages];
     return $this->renderPartial($view, $params);
 }
コード例 #3
0
 /**
  * Finds the Image model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Image the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Image::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
コード例 #4
0
ファイル: Product.php プロジェクト: Krinnerion/shop
 public static function getSmallProductImage($model)
 {
     $image = Image::find()->where(['product_id' => $model->id])->one();
     if ($image) {
         /* @var $image \common\models\Image */
         return Html::img($image->getUrl(), ['alt' => 'image', 'style' => 'width: 75px;']);
     }
 }
コード例 #5
0
 public function actionAddBlog()
 {
     $model = new Blog();
     $image = new Image();
     $data = Yii::$app->request->post();
     $model->load($data, '');
     $image->img = UploadedFile::getInstancesByName("image");
     if ($image->validate() && $model->save()) {
         if (!empty($model->categorys)) {
             $model->setCategories();
         }
         if (!empty($image->img)) {
             $image->uploads($model, Image::BLOG_STATUS);
         }
         return $model;
     }
     return array_merge($model->getErrors(), $image->getErrors());
 }
コード例 #6
0
 public function actionAddCategory()
 {
     $user = Yii::$app->user->identity;
     if ($user->role == User::ROLE_ADMIN) {
         $model = new Category();
         $image = new Image();
         $model->load(Yii::$app->request->post(), '');
         $image->img = UploadedFile::getInstancesByName("image");
         if ($image->validate() && $model->save()) {
             if (!empty($image->img)) {
                 $image->uploads($model, Image::CATEGORY_STATUS);
             }
             return $model;
         }
         return array_merge($model->getErrors(), $image->getErrors());
     }
     return "Access denied";
 }
コード例 #7
0
 public function actionDelete()
 {
     if (\Yii::$app->request->post('id') === null) {
         return false;
     }
     $id = \Yii::$app->request->post('id');
     $model = Image::findOne($id);
     return $model->delete();
 }
コード例 #8
0
ファイル: ImageSearch.php プロジェクト: ibrarturi/yii2-shop
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Image::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'product_id' => $this->product_id]);
     return $dataProvider;
 }
コード例 #9
0
ファイル: CustomerController.php プロジェクト: akiu/first-yii
 public function actionViewbyslug($slug)
 {
     $this->layout = "main";
     $model = Product::find()->where(['product_slug' => $slug])->one();
     if (!$model) {
         throw new NotFoundHttpException('The requested page does not exist.');
     } else {
         $image = Image::find()->where(['product_id' => $model->product_id])->all();
         return $this->render('viewbyslug', ['model' => $model, 'image' => $image]);
     }
 }
コード例 #10
0
ファイル: Image.php プロジェクト: afernandes465/fafediesel
 public function upload()
 {
     if ($this->validate()) {
         foreach ($this->imageFiles as $file) {
             $this->file_name = $this->table_name . '_' . $this->table_id . '_' . trim($file->baseName) . '.' . $file->extension;
             $full_path = \Yii::$app->basePath . "/../" . $this->filePath;
             $full_path = strtr($full_path, '/\\', DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR);
             if ($file->saveAs($full_path)) {
                 $model = new Image();
                 $model->table_name = $this->table_name;
                 $model->table_id = $this->table_id;
                 $model->path = $this->path;
                 $model->file_name = $this->file_name;
                 $model->save(false);
             }
         }
         return true;
     } else {
         return false;
     }
 }
コード例 #11
0
ファイル: ImageSearch.php プロジェクト: Krinnerion/shop
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Image::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     //        if (!($this->load($params) && $this->validate())) {
     //            return $dataProvider;
     //        }
     if (empty($params) || !$this->validate()) {
         return $dataProvider;
     }
     $this->id = $params['id'];
     $query->andFilterWhere(['product_id' => $this->id]);
     return $dataProvider;
 }
コード例 #12
0
ファイル: ImageSearch.php プロジェクト: czechcamus/dasport
 /**
  * Creates data provider instance with search query applied
  * @param array $params
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Image::find();
     if (!isset($params['sort'])) {
         $query->orderBy(['file_time' => SORT_DESC]);
     }
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 24], 'sort' => ['defaultOrder' => ['file_time' => SORT_DESC]]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['like', 'title', $this->fileTitle]);
     return $dataProvider;
 }
コード例 #13
0
 /**
  * 根据疾病id, 获取当前疾病相关疾病的图集
  * @author gaoqing
  * @date 2016-05-05
  * @param int $diseaseid 疾病id
  * @param int $size 所需的个数
  * @return array 相关疾病的图集
  */
 public static function getRelDiseaseImages($diseaseid, $size)
 {
     $relDiseaseImages = [];
     //1、得到所有的相关疾病
     $disease = new Disease();
     $relDiseases = $disease->getDiseaseDisByDisid($diseaseid);
     //2、得到相关疾病的图集
     if (isset($relDiseases) && !empty($relDiseases)) {
         $notHasImages = [];
         $inner = [];
         $relDiseaseImagesIndex = 0;
         foreach ($relDiseases as $relDisease) {
             $images = [];
             $inner['disease'] = $relDisease;
             $inner['images'] = $images;
             //2.1、如果当前图集,已经够 $size 了,就停止查询
             if ($relDiseaseImagesIndex == 6) {
                 break;
             }
             //2.2、得到疾病图集
             $icondition = ['flag' => 1, 'relid' => $relDisease['id']];
             $imagesTemp = Image::search($icondition);
             if (isset($imagesTemp['list']) && !empty($imagesTemp['list'])) {
                 $images = $imagesTemp['list'];
                 $inner['images'] = $images;
                 $relDiseaseImages[] = $inner;
                 $relDiseaseImagesIndex++;
             } else {
                 $notHasImages[] = $inner;
             }
         }
         $relDiseaseImagesCount = count($relDiseaseImages);
         /*
          * 3.1、当前 $relDiseaseImages 中不到指定的个数 $size时:
          * 3.2、计算出,距离 $size 所需的个数 $needCount
          * 3.3、从 $notHasImages 中,提前 $needCount 个数据
          */
         if ($relDiseaseImagesCount < $size) {
             $needCount = $size - $relDiseaseImagesCount;
             $needArr = array_slice($notHasImages, 0, $needCount);
             $relDiseaseImages = array_merge($relDiseaseImages, $needArr);
         }
     }
     return $relDiseaseImages;
 }
コード例 #14
0
ファイル: ArticleForm.php プロジェクト: czechcamus/dasport
 /**
  * Save Article model
  * @param bool $insert
  */
 public function saveArticle($insert = true)
 {
     $article = $insert === true ? new Article() : Article::findOne($this->item_id);
     $imageId = null;
     if (!isset(Yii::$app->request->post('ArticleForm')['imageFilename'])) {
         $this->imageFilename = null;
     }
     if ($this->imageFilename) {
         $imageId = Image::find()->andWhere(['filename' => $this->getImageName()])->scalar();
     }
     $this->image_id = $imageId;
     $article->attributes = $this->toArray();
     if ($this->content_date) {
         $article->content_date = Yii::$app->formatter->asDate($this->content_date, 'y-MM-dd');
     }
     if ($this->content_end_date) {
         $article->content_end_date = Yii::$app->formatter->asDate($this->content_end_date, 'y-MM-dd');
     }
     if ($this->content_time) {
         $article->content_time = Yii::$app->formatter->asTime($this->content_time, 'HH:mm');
     }
     $article->active = is_array($this->boxes) && in_array(self::PROPERTY_ACTIVE, $this->boxes) ? 1 : 0;
     $article->public = is_array($this->boxes) && in_array(self::PROPERTY_PUBLIC, $this->boxes) ? 1 : 0;
     if ($this->item_id) {
         ArticleCategory::deleteAll(['article_id' => $this->item_id]);
     }
     $article->tagValues = $this->tagValues;
     $article->save(false);
     if (is_array($this->categoryBoxes)) {
         foreach ($this->categoryBoxes as $categoryBox) {
             $articleCategory = new ArticleCategory();
             $articleCategory->article_id = $article->id;
             $articleCategory->category_id = $categoryBox;
             $articleCategory->save();
         }
     }
 }
コード例 #15
0
ファイル: Car.php プロジェクト: afernandes465/fafediesel
 public function getImagesList()
 {
     $img = Image::find()->andWhere(['table_id' => $this->id])->andWhere(['table_name' => \common\functions\TableName::name($this)])->all();
     return ArrayHelper::map($img, 'id', 'id');
 }
コード例 #16
0
ファイル: Movie.php プロジェクト: syungkeaw/m
 public function saveImage()
 {
     $this->unlinkAll('image', true);
     if (isset($this->_image) && is_array($this->_image)) {
         foreach ($this->_image as $path) {
             $image = new Image();
             $image->path = $path;
             $image->link('movie', $this);
         }
     }
 }
コード例 #17
0
ファイル: view.php プロジェクト: cyanofresh/yii2shop
/* @var $this yii\web\View */
/* @var $model common\models\Product */
$this->title = $model->name . ' - ' . $model->category->name;
$this->params['breadcrumbs'][] = ['label' => Yii::t('frontend/catalog', 'Catalog'), 'url' => ['catalog/index']];
if ($model->category->parent) {
    $this->title .= ' - ' . $model->category->parent->name;
    $this->params['breadcrumbs'][] = ['label' => $model->category->parent->name, 'url' => ['catalog/category', 'category' => $model->category->parent->slug]];
}
$this->params['breadcrumbs'][] = ['label' => $model->category->name, 'url' => ['catalog/category', 'category' => $model->category->slug]];
$this->params['breadcrumbs'][] = $model->name;
// Meta tags
$this->registerMetaTag(['name' => 'description', 'content' => $model->meta_description]);
$this->registerMetaTag(['name' => 'keywords', 'content' => $model->meta_keywords]);
// Gallery images
$galleryItems[] = ['src' => Yii::$app->urlManager->baseUrl . '/uploads/product/' . $model->id . '/main.jpg', 'options' => ['title' => $model->name]];
foreach (Image::findAll(['model_id' => $model->id]) as $image) {
    $galleryItems[] = ['src' => Yii::$app->urlManager->baseUrl . '/uploads/product/' . $model->id . '/' . $image->id . '.jpg', 'options' => ['title' => $model->name]];
}
?>

<div class="row">
    <div class="col-sm-6">
        <?php 
echo Gallery::widget(['items' => $galleryItems, 'id' => 'product-gallery-links']);
?>
    </div>

    <div class="col-sm-6">
        <h1 class="product-header">
            <?php 
echo $model->name;
コード例 #18
0
ファイル: ContentRecord.php プロジェクト: czechcamus/dasport
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getImage()
 {
     return $this->hasOne(Image::className(), ['id' => 'image_id']);
 }
コード例 #19
0
ファイル: Image.php プロジェクト: Kulkow/mainsite
 public function flip($direction)
 {
     $image = Image::factory($this->_server_path('original'));
     $image->flip($direction);
     $image->save($this->_server_path('original'));
     $this->timestamp = time();
     return $this->resize()->update();
 }
コード例 #20
0
 /**
  * Creates data provider instance
  * @return ActiveDataProvider
  */
 public function search()
 {
     $query = Image::find()->andWhere(['not in', 'id', $this->usedImagesIds]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['file_time' => SORT_DESC]], 'pagination' => ['pageSize' => 24]]);
     return $dataProvider;
 }
コード例 #21
0
ファイル: HotelController.php プロジェクト: vetal2409/example
 public function actionDeleteImage()
 {
     if (Yii::$app->request->post('image_id')) {
         $modelImage = Image::getById(Yii::$app->request->post('image_id'));
         $modelImage->delete();
     }
 }
コード例 #22
0
 /**
  * 症状图集
  * lc 2016-4-1
  * @return string 视图
  */
 public function actionSymimages()
 {
     $view = "symptom_images";
     $dname = $this->helpGparam('dname', "");
     $dname = trim($dname, '/');
     $domudle = $this->helpGparam('dmodule', 'tuji');
     $domudle = trim($domudle, '/');
     $pageStr = trim(trim($domudle, 'tuji'), '_');
     $page = 1;
     if (!empty($pageStr)) {
         $page = intval($pageStr);
     }
     $condition = ["{{%symptom}}.pinyin_initial" => $dname];
     $disease = $this->symptom->getSymptomByCondition($condition, [], 1, 0);
     if (!isset($disease) || empty($disease)) {
         throw new NotFoundHttpException("当前访问的页面不存在!");
     }
     $disease = $disease[0];
     if (!empty($disease)) {
         $symptomContent = SymptomContent::find()->select('examine')->where(['id' => $disease['id']])->asArray(true)->one();
         if (isset($symptomContent) && !empty($symptomContent)) {
             $disease = array_merge($disease, $symptomContent);
         }
     }
     //图集信息
     $icondition = ['flag' => 2, 'relid' => $disease['id']];
     $size = 1;
     $paging = $this->helpPaging('pager')->setSize($size)->setPageSetSize(9)->setUrlFormat('/' . $dname . '/tuji_%d' . '/')->setCurrentClass('cupat');
     $offset = $paging->getOffset();
     $images = Image::search($icondition, $offset, $size, 'id DESC', true);
     $imagesList = $images['list'];
     $paging->setTotal($images['total']);
     //获取相关疾病文章
     $relArtsAndAsks = CacheHelper::getCache('frontend_symptom_detail_xgwz', ['title' => $disease['name'], 'id' => $disease['id'], 'diseaseid' => $disease['id'], 'pinyin' => $disease['pinyin']]);
     $relArticles = $relArtsAndAsks['relArticles'];
     //相关问答
     $asks = $relArtsAndAsks['relAsks'];
     //大家还在找部分
     $stillFind = $this->getStillFindDatas($disease['name']);
     //右侧:最新文章
     $lastestArticles = $this->getLatestArticles();
     $return_img_list = [];
     foreach ($imagesList as $k => $v) {
         $v['url'] = \librarys\helpers\utils\Url::getuploadfileUrl(2, $v['name']);
         $return_img_list[] = $v;
     }
     $params = ['disease' => $disease, 'imagesList' => $return_img_list, 'relArticles' => $relArticles, 'paging' => $paging, 'asks' => $asks, 'lastestArticles' => $lastestArticles, 'stillFind' => $stillFind];
     return $this->render($view, $params);
 }
コード例 #23
0
ファイル: DefaultController.php プロジェクト: BoBRoID/new.k-z
 public function actionUploaded()
 {
     if (!\Yii::$app->request->isAjax) {
         throw new BadRequestHttpException('Данный метод возможен только через ajax!');
     }
     \Yii::$app->response->format = 'json';
     $images = [];
     foreach (Image::find()->each() as $image) {
         $imageObj = new \stdClass();
         $imageObj->thumb = $image->link;
         $imageObj->image = $image->link;
         $imageObj->title = empty($image->description) ? '' : $image->description;
         $imageObj->id = "img{$image->id}";
         $images[] = $imageObj;
     }
     return $images;
 }
コード例 #24
0
ファイル: PageForm.php プロジェクト: czechcamus/dasport
 /**
  * Save Page model
  * @param bool $insert
  */
 public function savePage($insert = true)
 {
     $page = $insert === true ? new Page() : Page::findOne($this->item_id);
     $imageId = null;
     if (!isset(Yii::$app->request->post('PageForm')['imageFilename'])) {
         $this->imageFilename = null;
     }
     if ($this->imageFilename) {
         $imageId = Image::find()->andWhere(['filename' => $this->getImageName()])->scalar();
     }
     $this->image_id = $imageId;
     $page->attributes = $this->toArray();
     $page->active = is_array($this->boxes) && in_array(self::PROPERTY_ACTIVE, $this->boxes) ? 1 : 0;
     $page->public = is_array($this->boxes) && in_array(self::PROPERTY_PUBLIC, $this->boxes) ? 1 : 0;
     $page->tagValues = $this->tagValues;
     if ($page->save()) {
         $this->item_id = $page->id;
     }
 }
コード例 #25
0
ファイル: _imageView.php プロジェクト: vetal2409/example
<?php

use common\models\Image;
use yii\helpers\Html;
/**
 * @var $model common\models\Image
 */
?>
<div class="col-md-3 image-holder">
    <?php 
echo Html::hiddenInput('hotel_id', $model->hotel_id, ['id' => 'hotel-id']);
?>
    <?php 
echo Html::hiddenInput('image_id', $model->id, ['id' => 'image-id']);
?>

    <?php 
echo Image::showImage($model->id, $model->name);
?>
    <?php 
echo Html::button('Make preview image', ['class' => 'text left btn btn-primary', 'id' => 'make-preview']);
?>
    <?php 
echo Html::button('Delete', ['class' => 'text right btn btn-primary', 'id' => 'delete-image']);
?>
</div>
コード例 #26
0
 /**
  * Updates an existing Product model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post())) {
         $model->image = UploadedFile::getInstance($model, 'image');
         $model->images = UploadedFile::getInstances($model, 'images');
         if ($model->validate() && $model->save()) {
             $dir = Yii::getAlias('@frontend/web/uploads/product/' . $model->id);
             if ($model->image) {
                 $model->image->saveAs($dir . '/main.jpg');
             }
             if ($model->images) {
                 $imageModels = Image::findAll(['model_id' => $model->id]);
                 if ($imageModels) {
                     foreach ($imageModels as $image) {
                         $file = $dir . '/' . $image->id . '.jpg';
                         if (file_exists($file)) {
                             unlink($file);
                         }
                         $image->delete();
                     }
                 }
                 foreach ($model->images as $image) {
                     $imageModel = new Image();
                     $imageModel->model_id = $model->id;
                     $imageModel->save();
                     $image->saveAs($dir . '/' . $imageModel->id . '.jpg');
                 }
             }
         }
         return $this->redirect(['view', 'id' => $model->id]);
     }
     return $this->render('update', ['model' => $model]);
 }
コード例 #27
0
ファイル: view.php プロジェクト: cyanofresh/yii2shop
<?php

use common\models\Image;
use yii\helpers\Html;
use yii\widgets\DetailView;
/* @var $this yii\web\View */
/* @var $model common\models\Product */
$this->title = $model->name;
$this->params['breadcrumbs'][] = ['label' => Yii::t('backend/product', 'Products'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
$image_models = Image::findAll(['model_id' => $model->id]);
$images = null;
foreach ($image_models as $image) {
    $images .= Html::img(Yii::$app->urlManagerFrontEnd->baseUrl . '/uploads/product/' . $model->id . '/' . $image->id . '.jpg', ['width' => '200px', 'class' => 'img-thumbnail']);
}
?>
<div class="product-view">

    <h1 class="page-header">
        <?php 
echo Html::encode($this->title);
?>
        <div class="btn-group pull-right">
            <?php 
echo Html::a('<span class="glyphicon glyphicon-eye-open"></span>', Yii::$app->urlManagerFrontEnd->createUrl(['catalog/view', 'slug' => $model->slug, 'category' => $model->category->slug]), ['class' => 'btn btn-success', 'target' => '_blank', 'data-toggle' => 'tooltip', 'title' => Yii::t('backend/product', 'View on site')]);
?>
            <?php 
echo Html::a('<span class="glyphicon glyphicon-pencil"></span>', ['update', 'id' => $model->id], ['class' => 'btn btn-primary', 'data-toggle' => 'tooltip', 'title' => Yii::t('backend/product', 'Update')]);
?>
            <?php 
echo Html::a('<span class="glyphicon glyphicon-trash"></span>', ['delete', 'id' => $model->id], ['class' => 'btn btn-danger', 'title' => Yii::t('backend/product', 'Delete'), 'data' => ['toggle' => 'tooltip', 'confirm' => Yii::t('yii', 'Are you sure you want to delete this item?'), 'method' => 'post']]);
コード例 #28
0
 public function getAdi($condition)
 {
     return Image::find()->where($condition)->asArray()->one();
 }
コード例 #29
0
ファイル: Post.php プロジェクト: veretilosergei1985/learni
 public function getImages()
 {
     return $this->hasMany(Image::className(), ['film_id' => 'id']);
 }
コード例 #30
0
ファイル: Image.php プロジェクト: VampireMe/admin-9939-com
 /**
  * 根据疾病id, 查询相关图集信息
  * @author gaoqing
  * 2016年1月19日
  * @param int $diseaseid 疾病id
  * @return array 图集信息
  */
 public function getImagesByDiseaseid($diseaseid)
 {
     $image = [];
     $image = Image::find()->asArray()->select(["id", "name", "weight", "flag"])->where("flag = :flag AND relid = :relid", [":flag" => 1, ":relid" => $diseaseid])->all();
     return $image;
 }