/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Collection::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     if (isset($this->time) && $this->time != '') {
         $date_explode = explode(" to ", $this->time);
         $date1 = trim($date_explode[0]);
         $date2 = trim($date_explode[1]);
         $date2 = date("Y-m-d", strtotime("+1 day", strtotime($date2)));
         $query->andFilterWhere(['between', 'collection.time', $date1, $date2]);
     }
     $query->joinwith('customer');
     $query->joinwith('account');
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'customer.name', $this->customer_id]);
     $query->andFilterWhere(['like', 'account.name', $this->account_id]);
     $query->andFilterWhere(['like', 'money', $this->money]);
     return $dataProvider;
 }
Esempio n. 2
0
 public static function calculateSum()
 {
     /** @var Collection $lastSuccessCollection */
     $lastSuccessCollection = Collection::find()->where(['is_fulfilled' => true])->orderBy(['date' => SORT_DESC])->limit(1)->one();
     if (is_null($lastSuccessCollection)) {
         return Log::calculateSum();
     }
     return Log::calculateSum($lastSuccessCollection->date);
 }
Esempio n. 3
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     // $url = 'http://map.naver.com/search2/local.nhn?query='. urlencode('서울특별시+중구+애견호텔');
     //     $job = (new CollectionLocal($url));
     //     dispatch($job);
     // return;
     $this->comment("Collector job staring...");
     $collect_local_main = '';
     $collect_local_sub = '';
     $collect_ord = 1;
     $collect_url = array();
     $collection = Collection::orderby('id', 'desc')->first();
     if (empty($collection->id)) {
         $local = Local::where('ord', 1)->first();
         $collect_local_main = $local->main;
         $collect_local_sub = $local->sub;
     } else {
         $local = Local::where('ord', '>', $collection->ord)->first();
         if (empty($local->id)) {
             $local = Local::where('ord', 1)->first();
         }
         $collect_local_main = $local->main;
         $collect_local_sub = $local->sub;
         $collect_ord = $local->ord;
     }
     //2분단위로 데이터 가져오기 실행
     $keywordSets = Keyword::orderby('ord', 'asc')->get();
     foreach ($keywordSets as $k => $value) {
         $url = 'http://map.naver.com/search2/local.nhn?query=' . urlencode($collect_local_main . '+' . $collect_local_sub . '+' . $value->keyword);
         $job = (new CollectionLocal($url))->delay($k * 120);
         dispatch($job);
     }
     $collection = new Collection();
     $collection->local_main = $collect_local_main;
     $collection->local_sub = $collect_local_sub;
     $collection->ord = $collect_ord;
     $collection->save();
     $this->comment("Collector : [" . $collect_local_main . "/" . $collect_local_sub . "]");
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Collection::find()->orderBy(['id' => SORT_DESC]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 200]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'is_fulfilled' => $this->is_fulfilled, 'sum' => $this->sum, 'date' => $this->date]);
     $query->andFilterWhere(['like', 'login', $this->login]);
     return $dataProvider;
 }
Esempio n. 5
0
 /**
  * Delete Collection and all its documents
  *
  * @param String $name
  * @param Request $request
  * @return Response
  */
 public function deleteCollection($name, Request $request)
 {
     if (!$this->appKeyAvailable($request)) {
         return $this->notAuthorized($request);
     }
     $collection = $this->readCollection($name);
     if (!$this->setSessionUser($request)) {
         $this->setResultError("Not logged in", 401);
     } elseif (!$this->isAdmin()) {
         $this->setResultError("Unauthorized action", 403);
     } elseif (!$collection) {
         $this->setResultError("Collection name does not exist", 404);
     } else {
         Collection::destroy($collection->id);
         $this->setResultOk();
     }
     return $this->setResponse();
 }
Esempio n. 6
0
 /**
  * Bulk delete the specified resources in storage.
  *
  * @param string $action to perform
  * @param string|array $ids
  * @return integer count of actions performed
  */
 public function bulkAction($action, $ids)
 {
     // Get a collection of resources
     $collection = Collection::parseMixed($ids, [',', '+', ' ']);
     // Get any extra arguments passed
     $arguments = array_slice(func_get_args(), 2);
     // Run in a transaction for all or nothing behavior
     DB::transaction(function () use($collection, $action, $arguments) {
         // Iterate over the resources performing the action on each
         $collection->each(function ($id) use($action, $arguments) {
             // Repository@<action>($id)
             array_unshift($arguments, $id);
             call_user_func_array([$this, studly_case($action)], $arguments);
         });
     });
     // Fire bulk after event listeners
     $this->eventFire('bulk.' . snake_case($action), $collection->all());
     return $collection->count();
 }
Esempio n. 7
0
 /**
  * Display a confirmation modal for the specified resource bulk action.
  *
  * @param string $action
  * @param string|array $ids (optional)
  * @return Illuminate\View\View
  */
 public function confirmBulk($action, $ids = null)
 {
     $data = [];
     $inTrash = false;
     // Get the objects from the repository
     $ids = is_null($ids) ? Input::get('ids') : $ids;
     if (!is_null($ids)) {
         $ids = Collection::parseMixed($ids, [',', '+', ' '])->all();
         // Get the resource out of the trash
         if (in_array($action, $this->trashableActions) && method_exists($this->getRepository(), 'retrieve')) {
             $inTrash = true;
         }
         // Get the resources as a collection
         $collection = $this->getRepository()->findIn('id', $ids);
         // Pass collection under the plural package named variable to the view
         $data = [str_plural($this->package) => $collection, 'ids' => $ids];
     }
     // Render confirmation modal
     $view = str_replace('bulk_', 'bulk.', $action) . '_confirm';
     return $this->modal($view, $data);
 }
Esempio n. 8
0
 public static function all($where_clause = [])
 {
     // Create an SQL "WHERE" clause
     $sql_where = Sql::where($where_clause);
     // SQL
     $sql = "\n            SELECT * FROM " . static::$table . $sql_where;
     // Get Results
     $results = DB::select($sql, $where_clause);
     // Make Collection
     $collection = new Collection();
     foreach ($results as $row) {
         // Create new Model
         $model = new static();
         $model->setData($row->{static::$key}, (array) $row);
         // Add Model to Collection
         $collection->add($model);
     }
     return $collection;
 }
 /**
  * Finds the Collection model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Collection the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Collection::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Esempio n. 10
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCollections()
 {
     return $this->hasMany(Collection::className(), ['customer_id' => 'id']);
 }
 public function actionCollected()
 {
     if (Yii::$app->request->get('rejected')) {
         return $this->render('collected_failed');
     }
     $collection = new Collection();
     $collection->login = Yii::$app->getSession()->get('collection.login');
     $collection->is_fulfilled = true;
     $collection->sum = Collection::calculateSum();
     $collection->save();
     return $this->render('collected');
 }
Esempio n. 12
0
 /**
  * Add a scope filter.
  *
  * @param string $name of scope closure
  * @param mixed $args to pass to closure
  * @return void
  */
 public function addScope($name, $args)
 {
     // Make sure that scopes match the filters
     $scopes = isset($this->filters['scopes']) ? $this->filters['scopes'] : [];
     $this->scopes = array_merge($this->scopes ?: [], $scopes);
     // Convert mixed to array
     $args = Collection::parseMixed($args, [','])->all();
     $args = array_values($args);
     $arrs = array_filter($args, function ($arg) {
         if (!is_numeric($arg) && !is_bool($arg) && empty($arg)) {
             return false;
         }
         return true;
     });
     // Only add the scope if the args are not empty
     if (!empty($args) && $args == $arrs) {
         $this->scopes[$name] = $arrs;
         $this->filters['scopes'] = $this->scopes;
     }
 }
Esempio n. 13
0
?>
<div class="file-create">

    <h1><?php 
echo Html::encode($this->title);
?>
</h1>

    <div class="file-form">

        <?php 
$form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]);
?>

        <?php 
echo $form->field($model, 'collection_id')->dropDownList(\app\models\Collection::getList());
?>

        <?php 
echo $form->field($model, 'files[]')->fileInput(['multiple' => true]);
?>

        <div class="form-group">
            <?php 
echo Html::submitButton('Загрузить', ['class' => 'btn btn-success']);
?>
        </div>

        <?php 
ActiveForm::end();
?>
Esempio n. 14
0
 /**
  * Retrieve Collection By Name
  *
  * @param String $name
  * @return Collection
  */
 protected function readCollection($name)
 {
     return Collection::whereName($name)->first();
 }
Esempio n. 15
0
 /**
  * Collection Factory
  */
 protected static function makeCollection($results)
 {
     // Make Collection
     $collection = new Collection();
     foreach ($results as $row) {
         // Create new Model
         $model = new static();
         $model->setData($row->{static::$key}, (array) $row);
         // Add Model to Collection
         $collection->add($model);
     }
     return $collection;
 }
Esempio n. 16
0
 public function collection(Request $request, $id)
 {
     if (!$this->login_user) {
         $result = ['status' => 201, 'msg' => '请先登录'];
     } else {
         $query = Collection::where('user_id', $this->login_user->id)->where('collection_type', 'article')->where('collection_id', $id);
         if ($query->first()) {
             $query->delete();
             Article::find($id)->decrement('collections', 1);
             $result = ['status' => 200, 'type' => 'cancel', 'msg' => '已取消收藏'];
         } else {
             Collection::create(['user_id' => $this->login_user->id, 'collection_type' => 'article', 'collection_id' => $id]);
             Article::find($id)->increment('collections', 1);
             $result = ['status' => 200, 'type' => 'success', 'msg' => '收藏成功'];
         }
     }
     return response()->json($result);
 }
Esempio n. 17
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCollection()
 {
     return $this->hasOne(Collection::className(), ['collection_id' => 'collection_id']);
 }