public function index(Request $request)
 {
     $type = $request->get('type');
     $q = $request->get('q');
     $search = new Search();
     return ['type' => $type, 'items' => $search->search($q, $type)];
 }
Exemple #2
0
 public function search(Search $search)
 {
     $URL = $_SERVER['REQUEST_URI'];
     $url_lang = substr($URL, 1, 2);
     $this->data['search'] = $search->getActive($url_lang);
     return view('pages.search', $this->data);
 }
 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]);
 }
Exemple #4
0
 public function search(Search $search)
 {
     if (isset($_POST['sort'])) {
         $input = \Input::all();
         $sort = $input['sort'];
         $sortBy = $input['sortBy'];
         $this->data['search'] = $this->song->sortSong($sort, $sortBy);
     } else {
         $this->data['search'] = $this->song->getActiveSongs();
     }
     $this->data['most_popular'] = $this->song->most_popular();
     $this->data['last_add'] = $this->song->last_add();
     $this->data['search'] = $search->getActive();
     return view('pages.search', $this->data);
 }
 /**
  * @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)];
 }
Exemple #6
0
 /**
  * Algoritmo di riempimento di una lista. E' quello che decide quali utenti scegliere per la ricerca
  *
  * @throws Exception
  */
 public function fillList()
 {
     if (!$this->exists) {
         throw new Exception('Non utilizzabile', 500);
     }
     /**
      * @var Search $search
      */
     $search = Search::whereId($this->search_id)->first();
     $lastTimeout = Carbon::now()->subMinutes(5)->toDateTimeString();
     $lastUpdate = Carbon::now()->subMinutes(10)->toDateTimeString();
     $usersWhoRefused = $search->usersWhoRefused();
     $usersAlreadyFetched = $search->userAlreadyFetched();
     // <Per test>
     $lastUpdate = Carbon::now()->subYear(1)->toDateTimeString();
     // </Per test>
     $users = DB::table('users AS USER')->leftjoin('user_search_timeouts AS USER_TIMEOUT', 'USER_TIMEOUT.user_id', '=', 'USER.id')->selectRaw("USER.id, haversine(USER.geo_latitude, USER.geo_longitude, 10, 20) AS distance, MAX(USER_TIMEOUT.timed_out_at) AS last_timeout")->where('USER.geo_last_update', '>', $lastUpdate)->whereRaw('haversine(USER.geo_latitude, USER.geo_longitude, 10, 20) <= ' . (double) $search->max_distance)->whereNotIn('USER.id', $usersWhoRefused)->whereNotIn('USER.id', $usersAlreadyFetched)->where('USER.id', '<>', $search->user_id)->where('USER.status', '=', User::STATUS_AVAILABLE)->groupBy('USER.id')->havingRaw('last_timeout < ' . DB::getPdo()->quote($lastTimeout) . ' OR last_timeout IS NULL')->orderBy('distance')->limit(self::MAX_USERS_FOR_LIST)->get();
     if (!empty($users)) {
         $tuples = [];
         foreach ($users as $i => $user) {
             /**
              * @var stdClass $user
              */
             $tuples[] = ['search_list_id' => $this->id, 'user_id' => $user->id, 'order' => $i + 1];
         }
         DB::table('search_list_users')->insert($tuples);
     }
 }
Exemple #7
0
 /**
  * Funzione richiamata da B nel caso in cui sta aspettando che arrivi la conferma che l'abbraccio è stato creato ma
  * non riceve nulla entro un tot di secondi. Utilizza quindi questa funzione per richiedere se l'abbraccio è stato
  * creato e se può entrare
  *
  * @param Request $request
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function checkForHug(Request $request)
 {
     try {
         $this->validate($request, ['search_id' => 'required|numeric|exists:searches,id']);
     } catch (ValidationException $e) {
         $errors = $e->getErrors();
         return parent::response([], $errors);
     }
     $user = $this->getAuthenticatedUser();
     /**
      * @var Hug    $hug
      * @var Search $search
      */
     $hug = Hug::whereSearchId($request->get('search_id'))->whereNull('closed_at')->first();
     $search = Search::whereId($request->get('search_id'))->first();
     if (empty($hug)) {
         // Riprova o lascia perdere!
         return parent::response(["hug" => null, "retryIn" => 15]);
     } else {
         // L'abbraccio esiste.
         if ($hug->user_sought_id != $user->id) {
             // Non è lui quello che è stato trovato
             abort(403);
         }
         if (!empty($hug->user_sought_last_checkin)) {
             // Ha già fatto l'accesso
             abort(400);
             // Forse dovremmo evitare errore in questo caso e semplicemente dirgli "guarda che già sei dentro"?
         }
         // Ok può entrare
         $this->join($hug, $user);
     }
     return parent::response(["hug" => $hug]);
 }
 /**
  * @param $term
  * @return string JSON
  */
 public function actionAutoCompleteSearch($term)
 {
     Yii::$app->response->format = Response::FORMAT_JSON;
     $search = new Search();
     $search->q = $term;
     $search->on(Search::QUERY_SEARCH_PRODUCTS_BY_DESCRIPTION, function (SearchEvent $event) {
         $event->setFunctionSearch(function ($activeQuery) {
             $activeQuery->limit(Yii::$app->getModule('core')->autoCompleteResultsCount);
             return Product::find()->select(['id', 'name', 'main_category_id', 'slug', 'sku'])->where(['id' => $activeQuery->all()])->all();
         });
     });
     $products = $search->searchProductsByDescription();
     $result = [];
     foreach ($products as $product) {
         /** @var Product $product */
         $result[] = ['id' => $product->id, 'name' => $product->name, 'url' => Url::toRoute(['@product', 'model' => $product, 'category_group_id' => $product->getMainCategory()->category_group_id], true)];
     }
     return $result;
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Search::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $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(['id' => $this->id, 'viewer_id' => $_GET['viewer_id'], 'visible' => $this->visible, 'datasource_id' => $this->datasource_id, 'chage_data' => $this->chage_data, 'setOrder' => $this->setOrder]);
     $query->andFilterWhere(['like', 'search_name', $this->search_name])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'sql_search', $this->sql_search]);
     return $dataProvider;
 }
 public function searchResults(Request $request)
 {
     $results = Search::search($request->r);
     return view('search.results', compact('results'))->with(['r' => $request->r]);
 }
 /**
  * Finds the Search model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Search the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Search::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getSearch()
 {
     return $this->hasOne(Search::className(), ['id' => 'search_id']);
 }
 public function actionSearch()
 {
     $model = new Search();
     $model->load(Yii::$app->request->get());
     return $this->render('search', ['model' => $model]);
 }
 public function make_research()
 {
     $search = new Search();
     $result = $search->find($this->_parameters);
     return $result;
 }
Exemple #15
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);
 }
Exemple #16
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]);
 }
 /**
  * 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)];
 }
Exemple #18
0
 /**
  * Controlla se l'utente può avviare la ricerca.
  *
  * Un utente non può avviare una ricerca quando:
  *  - Ha già una ricerca in corso.
  *  - Ha già un abbraccio in corso
  *  - Non ha lasciato il feedback per un'altro abbraccio concluso.
  *
  * @param User $user
  *
  * @throws UserCannotLaunchSearchException
  */
 private function checkIfUserCanLaunchSearch(User $user)
 {
     $search = Search::whereUserId($user->id)->whereNull('finished_at')->first();
     if ($search instanceof Search) {
         throw new UserCannotLaunchSearchException("Un'altra ricerca è in corso - Search id: {$search->id}");
     }
     $hug = Hug::whereNull('closed_at')->where(function ($query) use($user) {
         /**
          * @var Builder $query
          */
         $query->where('user_seeker_id', '=', $user->id)->orWhere('user_sought_id', '=', $user->id);
     })->first();
     if ($hug instanceof Hug) {
         throw new UserCannotLaunchSearchException("E' coinvolto in un'altro abbraccio - Hug id: {$hug->id}");
     }
     $hugWithOutFeedBack = DB::table('hugs AS HUG')->leftJoin('user_hug_feedbacks AS FEEDBACK_AS_SEEKER', function ($join) {
         /**
          * @var JoinClause $join
          */
         $join->on('HUG.user_seeker_id', '=', 'FEEDBACK_AS_SEEKER.user_id')->on('HUG.id', '=', 'FEEDBACK_AS_SEEKER.hug_id');
     })->leftJoin('user_hug_feedbacks AS FEEDBACK_AS_SOUGHT', function ($join) {
         /**
          * @var JoinClause $join
          */
         $join->on('HUG.user_sought_id', '=', 'FEEDBACK_AS_SOUGHT.user_id')->on('HUG.id', '=', 'FEEDBACK_AS_SOUGHT.hug_id');
     })->whereNotNull('HUG.closed_at')->whereNull('FEEDBACK_AS_SEEKER.id')->whereNull('FEEDBACK_AS_SOUGHT.id')->where(function ($query) use($user) {
         /**
          * @var Builder $query
          */
         $query->where('HUG.user_seeker_id', '=', $user->id)->orWhere('HUG.user_sought_id', '=', $user->id);
     })->first(['HUG.*']);
     if (!empty($hugWithOutFeedBack)) {
         throw new UserCannotLaunchSearchException("Non ha lasciato il feedback per un abbraccio concluso - Hug id: {$hugWithOutFeedBack->id}");
     }
 }
Exemple #19
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]);
        }
    }