Пример #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;
 }
Пример #2
0
        <div class="col-md-7">
            <h4>Генерация карт</h4>
            <div class="form-card row-fluid well well-sm">
                <?php 
echo Html::beginForm(['create'], 'post', ['class' => 'form-inline']);
?>
                <label for="quantity">Кол-во карт:</label>
                <input type="text" name="quantity" class="form-control" maxlength="4" size="4"/>
                <label for="type">Тип карт:</label>
                <?php 
echo Html::dropDownList('type', '', \app\modules\discount\models\Card::getTypeList(), ['class' => 'form-control']);
?>
                <input type="submit" value="Сгенерировать" class="btn btn-success"/>
                <?php 
echo Html::a('Распечатать и скачать', ['/discount/admin/card/print'], ['class' => 'btn btn-primary']);
?>
                <?php 
echo Html::endForm();
?>
            </div>
        </div>
    </div>



    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'id', 'number', 'cvcode', 'dateCreate:date', ['attribute' => 'status', 'value' => 'statusText', 'filter' => \app\modules\discount\models\Card::getStatusList()], ['attribute' => 'type', 'value' => 'typeValue', 'filter' => \app\modules\discount\models\Card::getTypeList()], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{view}']]]);
?>

</div>
 public function actionActivate($cvcode)
 {
     /**
      * @var $model \app\modules\discount\models\Card
      */
     $model = Card::findByCvcode($cvcode);
     if (!$model) {
         throw new HttpException('404', 'Карта с таким кодом не найдена!');
     }
     $user = new User();
     $user->scenario = 'client.create';
     $user->role = 'client';
     $profile = new Profile();
     $profile->scenario = 'client.create';
     $partner = new \app\modules\cms\models\Partner();
     $partner->scenario = 'card.activate';
     $partner->load($_POST);
     $partnerValidate = $partner->email ? $partner->validate() : true;
     //        var_dump($partnerValidate);
     if ($user->load($_POST) && $profile->load($_POST) && $partnerValidate) {
         $model->status = Card::STATUS_ACTIVE;
         $user->dateCreate = date(DATE_FORMAT_DB);
         if ($user->save()) {
             $model->userId = $user->id;
             $profile->file = UploadedFile::getInstance($profile, 'file');
             $profile->userId = $user->id;
             if ($profile->file) {
                 $filename = $user->id . '.' . $profile->file->extension;
                 $filepath = \Yii::getAlias(Profile::PHOTO_DIR_ALIAS) . '/' . $filename;
                 $profile->file->saveAs($filepath, false);
                 $profile->photo = $filename;
             }
             $profile->save();
             $model->dateActivate = date('Y-m-d H:i:s');
             $model->save(false, ['status', 'userId', 'dateActivate']);
             if ($partnerValidate) {
                 $partner->create($user);
             }
             $loginModel = new \app\models\LoginForm();
             $loginModel->username = $user->username;
             $loginModel->password = $user->password2;
             $loginModel->login();
             $this->redirect(['card', 'cvcode' => $cvcode]);
         }
     }
     return $this->render('activate', ['model' => $model, 'user' => $user, 'profile' => $profile, 'partner' => $partner]);
 }
Пример #4
0
<?php

use yii\helpers\Url;
use app\modules\discount\models\Card;
?>
<div class="navbar-default sidebar" role="navigation">
    <div class="sidebar-nav navbar-collapse">
        <ul class="nav" id="side-menu">
            <?php 
if ($cardLink = Card::getLinkByUser()) {
    ?>
            <li>
                <a href="<?php 
    echo $cardLink;
    ?>
">Профиль</a>
            </li>
            <?php 
}
?>
            
            <?php 
if (Yii::$app->user->can('client')) {
    ?>
            <li>
                <a href="<?php 
    echo Url::to(['/discount/user/client-history']);
    ?>
">История</a>
            </li>
            <?php 
Пример #5
0
 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));
 }