Exemplo n.º 1
0
 /**
  * Creates a new Search model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Search();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['index', 'viewer_id' => $model->viewer_id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Exemplo n.º 2
0
 public function actionClub()
 {
     $model = new Search();
     $clubs = 1;
     if ($model->load(\Yii::$app->request->get()) && isset($model['name'])) {
         $clubs = Search::searchClubs($model['name'], $model['author'], 20, \Yii::$app->request->post('contentId'));
         if (\Yii::$app->request->isAjax) {
             echo json_encode(['content' => $clubs]);
             die;
         }
     }
     return $this->render('club', ['model' => $model, 'clubs' => $clubs]);
 }
Exemplo n.º 3
0
 /**
  * Search handler
  * @return array
  * @throws ForbiddenHttpException
  */
 public function actionSearch()
 {
     $headers = Yii::$app->response->getHeaders();
     $headers->set('X-Robots-Tag', 'none');
     $headers->set('X-Frame-Options', 'SAMEORIGIN');
     $headers->set('X-Content-Type-Options', 'nosniff');
     if (!Yii::$app->request->isAjax) {
         throw new ForbiddenHttpException();
     }
     $model = new Search();
     $model->load(Yii::$app->request->get());
     $cacheKey = 'ProductSearchIds: ' . $model->q;
     $ids = Yii::$app->cache->get($cacheKey);
     if ($ids === false) {
         $ids = ArrayHelper::merge($model->searchProductsByDescription(), $model->searchProductsByProperty());
         Yii::$app->cache->set($cacheKey, $ids, 86400, new TagDependency(['tags' => ActiveRecordHelper::getCommonTag(Product::className())]));
     }
     /** @var \app\modules\shop\ShopModule $module */
     $module = Yii::$app->modules['shop'];
     $pages = new Pagination(['defaultPageSize' => $module->searchResultsLimit, 'forcePageParam' => false, 'totalCount' => count($ids)]);
     $cacheKey .= ' : ' . $pages->offset;
     $products = Yii::$app->cache->get($cacheKey);
     if ($products === false) {
         $products = Product::find()->where(['in', '`id`', array_slice($ids, $pages->offset, $pages->limit)])->addOrderBy('sort_order')->with('images')->all();
         Yii::$app->cache->set($cacheKey, $products, 86400, new TagDependency(['tags' => ActiveRecordHelper::getCommonTag(Product::className())]));
     }
     Yii::$app->response->format = Response::FORMAT_JSON;
     return ['view' => $this->renderAjax('search', ['model' => $model, 'pages' => $pages, 'products' => $products]), 'totalCount' => count($ids)];
 }
Exemplo n.º 4
0
 /**
  * @return array
  * @throws ForbiddenHttpException
  */
 public function actionSearch()
 {
     /**
      * @param $module \app\modules\page\PageModule
      */
     if (!Yii::$app->request->isAjax) {
         throw new ForbiddenHttpException();
     }
     $model = new Search();
     $model->load(Yii::$app->request->get());
     $cacheKey = 'PageSearchIds: ' . $model->q;
     $ids = Yii::$app->cache->get($cacheKey);
     if ($ids === false) {
         $ids = $model->searchPagesByDescription();
         Yii::$app->cache->set($cacheKey, $ids, 86400, new TagDependency(['tags' => ActiveRecordHelper::getCommonTag(Page::className())]));
     }
     $pages = new Pagination(['defaultPageSize' => $this->module->searchResultsLimit, 'forcePageParam' => false, 'pageSizeLimit' => [$this->module->minPagesPerList, $this->module->maxPagesPerList], 'totalCount' => count($ids)]);
     $cacheKey .= ' : ' . $pages->offset;
     $pagelist = Yii::$app->cache->get($cacheKey);
     if ($pagelist === false) {
         $pagelist = Page::find()->where(['in', '`id`', array_slice($ids, $pages->offset, $pages->limit)])->addOrderBy('sort_order')->with('images')->all();
         Yii::$app->cache->set($cacheKey, $pagelist, 86400, new TagDependency(['tags' => ActiveRecordHelper::getCommonTag(Page::className())]));
     }
     Yii::$app->response->format = Response::FORMAT_JSON;
     return ['view' => $this->renderPartial('search', ['model' => $model, 'pagelist' => $pagelist, 'pages' => $pages]), 'totalCount' => count($ids)];
 }
Exemplo n.º 5
0
 public function actionSearch()
 {
     $model = new Search();
     $model->load(Yii::$app->request->get());
     return $this->render('search', ['model' => $model]);
 }
Exemplo n.º 6
0
 public function actionResult()
 {
     $model = new Search();
     if ($model->load(Yii::$app->request->get()) && $model->validate()) {
         $query = $model->extendSearch();
         if (!$query) {
             Yii::$app->session->setFlash('error', 'Ошибка при валидации');
             Yii::error('Ошибка при валидации');
             return $this->goHome();
         }
         $pagination = new Pagination(['defaultPageSize' => 3, 'totalCount' => $query->count()]);
         $tours = $query->offset($pagination->offset)->limit($pagination->limit)->all();
         return $this->render('result', ['tours' => $tours, 'pagination' => $pagination, 'model' => $model]);
     }
     $this->redirect('extendsearch', 302);
 }
Exemplo n.º 7
0
 public function actionResult()
 {
     if (Yii::$app->user->isGuest) {
         return $this->goHome();
     }
     $model = new Search();
     if ($model->load(Yii::$app->request->get())) {
         $query = $model->orderSearch();
         if (!$query) {
             Yii::$app->session->setFlash('error', 'Ошибка при валидации');
             Yii::error('Ошибка при валидации');
             return $this->goHome();
         }
         $pagination = new Pagination(['defaultPageSize' => 3, 'totalCount' => $query->count()]);
         $orders = $query->offset($pagination->offset)->limit($pagination->limit)->all();
         return $this->render('result', ['orders' => $orders, 'pagination' => $pagination]);
     }
     return $this->render('search', ['model' => $model]);
 }
Exemplo n.º 8
0
    public function actionHome($id = null)
    {
        //======= download PDF
        if ($id != NULL) {
            $sql = "SELECT * from tugas where id_tugas = {$id}";
            $model = Tugas::findBySql($sql)->one();
            //cari username yg buat tugas
            $sql1 = "SELECT username.username from username \n\t\t\t\tinner join tugas on (username.id_user = tugas.id_user) where id_tugas = {$id}";
            $model1 = Username::findBySql($sql1)->one();
            //cari nama jumlah user yg ikut ngrjain tugas
            $sql2 = "SELECT tugas.id_tugas, tugas.nama_tugas, tugas.tgl_mulai, tugas.tgl_akhir, count(bagi_tugas.id_tugas) as total_user, \n\t\t\t\tcount(bagi_tugas.tgl_selesai) as finished_working\n\t\t\t\tfrom tugas left outer join bagi_tugas on (tugas.id_tugas = bagi_tugas.id_tugas) where tugas.id_tugas = {$id}\n\t\t\t\tgroup by tugas.id_tugas order by tugas.id_tugas DESC";
            $model2 = Tugas::findBySql($sql2)->one();
            //buat progress project
            if ($model2->finished_working == 0) {
                $progress_project = 0;
            } else {
                $progress_project = $model2->finished_working / $model2->total_user * 100;
            }
            //dapetin nama username yg ikut ngrjain tugas
            $usernamenya = "";
            if ($model2->total_user != 0) {
                //dapetin id_user di tabel bagi_tugas
                $sql3 = "SELECT * from bagi_tugas where id_tugas = {$id} order by id_user ASC";
                $model3 = Bagitugas::findBySql($sql3)->all();
                $list_user = array();
                $i = 0;
                foreach ($model3 as $data) {
                    $list_user[$i] = $data->id_user;
                    $i++;
                }
                //dapetin username di tabel username
                if (count($list_user) != 0) {
                    $join = join(',', $list_user);
                    $sql4 = "SELECT * from username where id_user in ({$join}) order by id_user ASC";
                    $model4 = Username::findBySql($sql4)->all();
                } else {
                    $join = null;
                    $model4 = 0;
                    //belum ada username di bagi_tugas
                }
                foreach ($model4 as $index => $code) {
                    $usernamenya .= "<li>" . $code->username . "<br>          pembagian tugas : " . $model3[$index]->pembagian_tugas . "</li>";
                }
            }
            //user != 0
            //buat PDFnya
            $html = '<html><head>
				<style>
					h1 { margin-bottom:8px }
			
				</style>
			</head>
			<body>
				<h1>' . $model2->nama_tugas . '</h1>
				<b>dibuat oleh : </b>' . $model1->username . '<br>
				<b>tanggal project : </b>' . $model2->tgl_mulai . ' / ' . $model2->tgl_akhir . '<br>
				<b>progress project : </b>' . $progress_project . '%
				<br><br><hr>user yang mengerjakan : ' . $model2->total_user . '<br><br>' . $usernamenya . '
			</body></html>';
            $arr = array('file' => $html);
            $pdf_json = json_encode($arr);
            //cek akses untuk download PDF
            $id_user = Yii::$app->user->identity->id_user;
            $sql_pdf = "SELECT tipe_akses from username where id_user = {$id_user}";
            $model_pdf = Username::findBySql($sql_pdf)->one();
            if ($model_pdf->tipe_akses == "admin") {
                echo "<script>window.location.href = 'http://localhost/basic3/index.php?pdf={$pdf_json}';\n\t\t\t\talert('di download!');\n\t\t\t\t</script>";
            } else {
                echo "<script>alert('akses hanya untuk admin');</script>";
            }
            //return $this->redirect('index.php?r=site/home');
        }
        //============ UNTUK HALAMAN HOME
        //cari nama username yg buat tugas project
        $sql = 'SELECT username.username from username inner join tugas on (username.id_user = tugas.id_user)
				order by tugas.id_tugas DESC';
        $model = Username::findBySql($sql)->all();
        //cari nama tugas + jumlah user + finished working
        $sql1 = 'SELECT tugas.id_tugas, tugas.nama_tugas, tugas.tgl_mulai, tugas.tgl_akhir, count(bagi_tugas.id_tugas) as total_user, 
				count(bagi_tugas.tgl_selesai) as finished_working
				from tugas left outer join bagi_tugas on (tugas.id_tugas = bagi_tugas.id_tugas) 
				group by tugas.id_tugas order by tugas.id_tugas DESC';
        $model1 = Tugas::findBySql($sql1)->all();
        //search tugas
        $search = new Search();
        if ($search->load(Yii::$app->request->post())) {
            $keyword = $search['search'];
            $sql = "SELECT tugas.id_tugas, tugas.nama_tugas, tugas.tgl_mulai, tugas.tgl_akhir, \n\t\t\tcount(bagi_tugas.id_tugas) as total_user, count(bagi_tugas.tgl_selesai) as finished_working \n\t\t\tfrom tugas left outer join bagi_tugas on (tugas.id_tugas = bagi_tugas.id_tugas) \n\t\t\twhere tugas.nama_tugas like '%{$keyword}%' group by tugas.id_tugas order by tugas.id_tugas DESC";
            $model = Tugas::findBySql($sql)->all();
            return $this->render('search', ['model' => $model, 'keyword' => $keyword, 'search' => $search]);
        }
        $model2 = new Tugas();
        //ada input data Tugas baru
        if ($model2->load(Yii::$app->request->post())) {
            $model2['tgl_selesai'] = null;
            if ($model2->save()) {
                return $this->redirect('index.php?r=site/home');
            }
            //return $this->redirect(['view', 'id' => $model->id_user]);
        } else {
            //cari maksimal id_tugas+1
            $sql3 = "SELECT max(id_tugas)+1 as max_id from tugas";
            $model3 = Tugas::findBySql($sql3)->one();
            return $this->render('home', ['model' => $model, 'model1' => $model1, 'model2' => $model2, 'model3' => $model3, 'search' => $search]);
        }
    }