コード例 #1
0
 /**
  * @param ShopProduct $product
  * @param CUploadedFile $image
  */
 public function __construct(ShopProduct $product, CUploadedFile $image)
 {
     $name = ShopUploadedImage::createName($product, $image);
     $fullPath = ShopUploadedImage::getSavePath() . '/' . $name;
     $image->saveAs($fullPath);
     @chmod($fullPath, 0666);
     // Check if product has main image
     $is_main = (int) ShopProductImage::model()->countByAttributes(array('product_id' => $product->id, 'is_main' => 1));
     $imageModel = new ShopProductImage();
     $imageModel->product_id = $product->id;
     $imageModel->name = $name;
     $imageModel->is_main = $is_main == 0 ? true : false;
     $imageModel->uploaded_by = Yii::app()->user->id;
     //$imageModel->date_uploaded = date('Y-m-d H:i:s');
     $imageModel->save(false, false);
     $this->resize($fullPath);
     $this->watermark($fullPath);
 }
コード例 #2
0
 /**
  * @param ShopProduct $model
  */
 public function handleUploadedImages(ShopProduct $model)
 {
     $images = CUploadedFile::getInstancesByName('ShopProductImages');
     if ($images && sizeof($images) > 0) {
         /** var $image CUploadedFile */
         foreach ($images as $image) {
             if (!ShopUploadedImage::hasErrors($image)) {
                 $model->addImage($image);
             } else {
                 $this->setFlashMessage(Yii::t('ShopModule.admin', 'ERR_LOAD_IMAGE', array('{NAME}' => $image->getName())));
             }
         }
     }
 }