Esempio n. 1
0
 public function init()
 {
     parent::init();
     if ($this->page == 'index') {
         if ($this->cat == 'all' or $this->cat == null) {
             $query = Logotypes::find()->limit(15);
         } else {
             $query_cat = new Query();
             $query_cat->select('id')->from('category')->where(['name' => $this->cat]);
             $cat_id = $query_cat->all()[0]['id'];
             $query = Logotypes::find()->limit(15)->where(['category' => $cat_id]);
         }
         $logos = $query->all();
         shuffle($logos);
     } else {
         if ($this->cat == 'all' or $this->cat == null) {
             $query = Logotypes::find();
         } else {
             $query_cat = new Query();
             $query_cat->select('id')->from('category')->where(['name' => $this->cat]);
             $cat_id = $query_cat->all()[0]['id'];
             $query = Logotypes::find()->where(['category' => $cat_id]);
         }
         $countQuery = clone $query;
         $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => 15]);
         $logos = $query->offset($pages->offset)->limit($pages->limit)->all();
         $this->pages = $pages;
     }
     $this->logos = $logos;
 }
Esempio n. 2
0
 public function actionUpload()
 {
     var_dump($_POST['cat']);
     if (isset($_POST['cat'])) {
         $cat = $_POST['cat'];
     } else {
         $cat = 'none';
     }
     $cat = self::createCategory($cat);
     $fileName = 'file';
     if (isset($_FILES[$fileName])) {
         $files = \yii\web\UploadedFile::getInstancesByName($fileName);
         //            $_FILES[$i] = $file;
         //Print file data
         //print_r($file);
         //            var_dump($_FILES[$i]);
         //            $i++;
         //var_dump($_FILES);
         $prepath = '../web/';
         $uploadPath = '/src/upload';
         foreach ($files as $file) {
             $name = md5_file($file->tempName);
             $path = $uploadPath;
             if (!file_exists($prepath . $path)) {
                 mkdir($prepath . $path, 0755, true);
             }
             for ($i = 0; $i <= 2; $i++) {
                 $path .= '/' . $name[$i];
                 if (!file_exists($prepath . $path)) {
                     mkdir($prepath . $path, 0755, true);
                 }
             }
             if (!file_exists($prepath . $path . '/' . $file->name)) {
                 if ($file->saveAs($prepath . $path . '/' . $file->name)) {
                     $kaboom = explode(".", $file->name);
                     $fileExt = end($kaboom);
                     $target_file = $prepath . $path . '/' . $file->name;
                     $resized_file = $prepath . $path . '/230_' . $file->name;
                     $wmax = 230;
                     $hmax = 230;
                     self::AkImgResize($target_file, $resized_file, $wmax, $hmax, $fileExt);
                     //Now save file data to database
                     $logo = new Logotypes();
                     $logo->name = $file->name;
                     $logo->category = $cat;
                     $logo->path = $path . '/' . $file->name;
                     $logo->path_230 = $path . '/230_' . $file->name;
                     if ($logo->save()) {
                         echo \yii\helpers\Json::encode($logo);
                     } else {
                         echo 'failed';
                         echo \yii\helpers\Json::encode($logo);
                         //echo $logo->errors();
                     }
                     //echo \yii\helpers\Json::encode($file);
                 }
             }
         }
     }
 }
Esempio n. 3
0
 public function getLogos()
 {
     return $this->hasMany(Logotypes::className(), ['category' => 'id']);
 }