Esempio n. 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Card::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]], 'pagination' => ['pageSize' => 100]]);
     $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, 'datePrint' => $this->datePrint, 'dateActivate' => $this->dateActivate, 'status' => $this->status, 'userId' => $this->userId, 'type' => $this->type]);
     $query->andFilterWhere(['like', 'cvcode', $this->cvcode]);
     return $dataProvider;
 }
 public function actionPrint()
 {
     set_time_limit(0);
     $cardList = Card::find()->newCard()->all();
     $qrCode = new QrCode();
     $zip = new \ZipArchive();
     $zipFile = Card::CARD_DIR . '/card-files-' . date('dmYHis') . '.zip';
     if ($zip->open($zipFile, \ZipArchive::CREATE)) {
         foreach ($cardList as $card) {
             $filename = Card::CARD_DIR . '/' . $card->cvcode . '.png';
             $qrCode->png($card->fullurl, $filename);
             $card->toPrint();
             $baseName = basename($filename);
             $zip->addFile($filename, $baseName);
         }
         $zip->close();
     }
     Yii::$app->response->sendFile($zipFile, basename($zipFile));
 }