예제 #1
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 Doc the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Reward::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
예제 #2
0
파일: _form.php 프로젝트: Gameonn/JS_API

<!-- http://www.fyneworks.com/jquery/multiple-file-upload/ 
http://www.bsourcecode.com/2013/03/yii-cmultifileupload/
-->
<!-- <input type="file" class="multi" name="images" accept="gif|jpg"/> -->
<?php 
//echo $form->hiddenField($model, 'image');
?>


<!-- show all images in the existing table -->
<?php 
if ($model->isNewRecord != '1' || !empty($model->filepath)) {
    if ($model->id != '') {
        echo $allImages = Reward::model()->showAllImagesWithDelIcon($model->id);
    }
}
$this->widget('CMultiFileUpload', array('name' => 'images', 'max' => 6, 'accept' => 'jpeg|jpg|gif', 'duplicate' => 'Duplicate file!', 'denied' => 'Invalid file type'));
echo $form->error($model, 'image');
?>
 <div style="color:red;">
 <?php 
echo Yii::app()->user->getFlash('imageErrMsg');
?>
 </div>   




예제 #3
0
 public function actionCreate()
 {
     $this->pageTitle = 'Jobstar - Create Reward';
     error_reporting(E_ALL & ~E_NOTICE);
     $model = new Reward();
     $rewardImagesModel = new RewardImages();
     $Tags = new Tags();
     if (isset($_POST['Reward']) && !empty($_POST['Reward'])) {
         //check product name duplicacy
         $chkTitle = $_POST['Reward']['title'];
         $chkPrice = $_POST['Reward']['price'];
         $chkCategory = $_POST['Reward']['category_id'];
         $chkRewardExist = Reward::model()->find('title = :title', array(':title' => $chkTitle));
         if (!empty($chkRewardExist)) {
             Yii::app()->user->setFlash('errDupTitle', 'Reward name exist in database, please enter another.');
             $this->redirect(array('create', 'titleSet' => $chkTitle, 'priceSet' => $chkPrice, 'categorySet' => $chkCategory));
         }
         //end checking
         //check image is uploaded or not
         $chkImageUploaded = CUploadedFile::getInstancesByName('images');
         if (isset($chkImageUploaded) && count($chkImageUploaded) > 0) {
             //do nothing.... this is done only for validation
         } else {
             //please select image
             Yii::app()->user->setFlash('imageErrMsg', 'Please upload image.');
             $model->attributes = $_POST['Reward'];
             //$this->redirect(array('create'));
             $this->redirect(array('create', 'titleSet' => $chkTitle, 'priceSet' => $chkPrice, 'categorySet' => $chkCategory));
         }
         // end validation
         $model->attributes = $_POST['Reward'];
         $model->category_id = $_POST['Reward']['category_id'];
         $model->status = '1';
         $model->description = $_POST['Reward']['description'];
         //echo "<pre>";
         //print_r($model->attributes);
         if ($model->save()) {
             //echo "----";
             $useridFolder = $model->id;
             if (isset($_POST['tag']) && $_POST['tag'] != '') {
                 $getTags = $_POST['tag'];
                 $mystring = $getTags;
                 $findme = ',';
                 $pos = strpos($mystring, $findme);
                 if ($pos === false) {
                     //echo "The string '$findme' was not found in the string '$mystring'";
                     //if that tag name already exist, skip that tag
                     $chkTagExist = Tags::model()->find('name = :name', array(':name' => $getTags));
                     if (empty($chkTagExist)) {
                         // echo "Tag not exist";
                         $insertMultiDoc = Yii::app()->db->createCommand()->insert('tags', array('reward_id' => $model->id, 'name' => $getTags));
                     } else {
                         //echo "dont save the record";
                     }
                 } else {
                     //echo "The string '$findme' was found in the string '$mystring'";
                     //echo " and exists at position $pos";
                     //explode with comma
                     $getTagArray = explode(',', $getTags);
                     //insert into tags table with reward model id.
                     foreach ($getTagArray as $tagVal) {
                         //if that tag name already exist, skip that tag
                         $chkTagExist = Tags::model()->find('name = :name', array(':name' => $tagVal));
                         if (empty($chkTagExist)) {
                             // echo "Tag not exist";
                             $insertMultiDoc = Yii::app()->db->createCommand()->insert('tags', array('reward_id' => $model->id, 'name' => $tagVal));
                         } else {
                             //echo "dont save the record";
                         }
                     }
                 }
             }
             //end tags
             $images = CUploadedFile::getInstancesByName('images');
             //echo "<pre>";
             //print_r($images);
             // proceed if the images have been set
             if (isset($images) && count($images) > 0) {
                 //upload multiple images, first create folder with reward id and store all related images in that folder.
                 // create folder
                 if ($_SERVER['DOCUMENT_ROOT'] == '/var/www/html') {
                     $setDir = $_SERVER['DOCUMENT_ROOT'] . "/images/reward/" . $useridFolder;
                 } else {
                     $setDir = $_SERVER['DOCUMENT_ROOT'] . "/jobstar/images/reward/" . $useridFolder;
                 }
                 if (is_dir($setDir) == false) {
                     mkdir("{$setDir}", 0777, true);
                     chmod("{$setDir}", 0777);
                 } else {
                     chmod("{$setDir}", 0777);
                 }
                 // go through each uploaded image
                 $i = 0;
                 foreach ($images as $thefile) {
                     if ($i == '0') {
                         //first image will be default
                         $setDefaultStatus = '1';
                     } else {
                         $setDefaultStatus = '0';
                     }
                     //echo $pic->name.'<br />'  error, size;
                     //$finalName = $setDir."/".$pic->name;
                     //echo "<br>";
                     $imagetime = time();
                     $image = $thefile;
                     //$type      = $pic->type;
                     $type = $thefile->extensionName;
                     $destination = $_SERVER['DOCUMENT_ROOT'] . "/jobstar/images/reward/" . $useridFolder;
                     $finalName = $setDir . "/" . $imagetime . "_" . $i;
                     $thumbnailImage = $setDir . "/" . $imagetime . "_" . $i;
                     if ($image->saveAs($finalName . '.' . $type)) {
                         $dbFileName = $imagetime . "_" . $i . '.' . $type;
                         $chkThumb = $this->createimage(270, 200, $thumbnailImage, 'm', $type);
                         if ($chkThumb == 0) {
                             // add it to the main model now
                             $insertMultiDoc = Yii::app()->db->createCommand()->insert('rewardimages', array('reward_id' => $model->id, 'image' => $dbFileName, 'defaultImage' => $setDefaultStatus));
                             $chkThumb = $this->createimage(270, 200, $thumbnailImage, 'm', $type);
                         } else {
                             $this->redirect(array('create'));
                         }
                     } else {
                         // handle the errors here, if you want
                     }
                     $i++;
                 }
                 //end foreach
             } else {
                 //please select image
                 Yii::app()->user->setFlash('imageErrMsg', 'Please upload image.');
             }
         }
         //die('end');
         $this->redirect(array('admin', 'id' => $model->id));
     }
     //end post method
     $this->render('create', array('model' => $model));
 }