示例#1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params, $aDop = [])
 {
     $query = Person::find();
     $query->with(Yii::$app->user->can(User::USER_GROUP_MODERATOR) ? ['section', 'section.conference'] : []);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $sFormname = $this->formName();
     if (!isset($params[$sFormname])) {
         $params[$sFormname] = [];
     }
     $params[$sFormname] = array_merge($params[$sFormname], $aDop);
     $this->load($params);
     if (!empty($this->conferenceid)) {
         $query->joinWith(['section']);
         $query->andFilterWhere([Section::tableName() . '.sec_cnf_id' => $this->conferenceid]);
     }
     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(['prs_id' => $this->prs_id, 'prs_active' => $this->prs_active, 'prs_type' => $this->prs_type, 'prs_sec_id' => $this->prs_sec_id, 'prs_doc_id' => $this->prs_doc_id, 'ekis_id' => $this->ekis_id, 'prs_hischool' => $this->prs_hischool]);
     $query->andFilterWhere(['like', 'prs_fam', $this->prs_fam])->andFilterWhere(['like', 'prs_name', $this->prs_name])->andFilterWhere(['like', 'prs_otch', $this->prs_otch])->andFilterWhere(['like', 'prs_email', $this->prs_email])->andFilterWhere(['like', 'prs_phone', $this->prs_phone])->andFilterWhere(['like', 'prs_org', $this->prs_org])->andFilterWhere(['like', 'prs_group', $this->prs_group])->andFilterWhere(['like', 'prs_position', $this->prs_position])->andFilterWhere(['like', 'prs_lesson', $this->prs_lesson]);
     return $dataProvider;
 }
示例#2
0
 /**
  * Export data without division to section
  * @return mixed
  */
 public function actionExportall()
 {
     $searchModel = new DocladSearch();
     $searchModel->conferenceid = Yii::$app->db->createCommand('Select s.sec_cnf_id' . ' From ' . Usersection::tableName() . ' us, ' . Section::tableName() . ' s' . ' Where s.sec_id = us.usec_section_id And us.usec_section_primary = 1 And us.usec_user_id = :uid', [':uid' => Yii::$app->user->getId()])->queryColumn();
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     //        echo nl2br(print_r($searchModel->conferenceid, true));
     //        return;
     $sDir = Yii::getAlias('@webroot/assets');
     $sFileName = $sDir . DIRECTORY_SEPARATOR . 'doclad-all-' . date('Y-m-d-H-i-s') . '.xls';
     $this->clearDestinationDir($sDir, 'xls', time() - 300);
     $this->exportToFile($dataProvider, $sFileName);
     Yii::$app->response->sendFile($sFileName);
     //        return $this->renderContent(
     //            Html::a(
     //                'Загрузить',
     //                substr($sFileName, str_replace(DIRECTORY_SEPARATOR, '/', strlen($_SERVER['DOCUMENT_ROOT'])))
     //            )
     //        );
 }
示例#3
0
 /**
  * @param string|null $docType
  * @return \yii\db\ActiveQuery
  */
 public function getSections($docType = null)
 {
     $query = $this->hasMany(Section::className(), ['sec_cnf_id' => 'cnf_id']);
     // тут мы делаем выборку секций по типу доклада, если нужно не просто все связанные записи
     if ($docType !== null) {
         $query->andOnCondition(['or', [Section::tableName() . '.sec_doclad_type' => $docType], [Section::tableName() . '.sec_doclad_type' => ''], ['is', Section::tableName() . '.sec_doclad_type', new Expression('Null')]]);
     }
     return $query;
 }
示例#4
0
 /**
  * Импорт модераторов
  * Взят вордовский файл с секциями для инжененрных классов
  * Таблица скопирована в эксель и сохранена как csv
  * Ручками подправлено так, чтобы в строке были полностью данные по людям:
  * 1 столбец: номер
  * 2 столбец: Образовательная  организация
  * 3 столбец: Фамилия
  * 4 столбец: Имя
  * 5 столбец: Отчество
  * 6 столбец: Должность
  * 7 столбец: Электронный адрес
  * могут быть пустые строки
  */
 public function actionImportmed($filename, $idConference = 2)
 {
     $aConfFields = [2 => ['', 'us_description', 'us_name', 'us_name', 'us_name', 'us_description', 'us_email'], 3 => ['us_name', 'us_description', 'us_email']];
     if (($hd = fopen($filename, "r")) !== false) {
         $aFields = $aConfFields[$idConference];
         $nFields = count($aFields);
         $aResultData = [];
         $aSectionId = Yii::$app->db->createCommand('Select sec_id From ' . Section::tableName() . ' Where sec_cnf_id = ' . $idConference)->queryColumn();
         $this->printStr("aSectionId: " . implode(', ', $aSectionId) . "\n\n");
         $nRow = 0;
         while (($data = fgetcsv($hd, 2000, ";")) !== false) {
             $nRow++;
             if ($nRow == 1) {
                 continue;
             }
             $num = count($data);
             if ($num < $nFields) {
                 $this->printStr("Error fields: " . implode(', ', $data) . " num = " . $num . " [{$nRow}]\n\n");
                 continue;
             }
             // *************************************************************************************************
             // конвертируем в UTF-8
             $data = array_map(function ($s) {
                 return iconv('CP1251', 'UTF-8', $s);
             }, $data);
             // *************************************************************************************************
             // тут пропускаем строку с заголовками колонок
             if (strpos($data[1], 'Фамилия') !== false && strpos($data[2], 'ВУЗ') !== false) {
                 //                    $this->printStr(
                 //                        "Col titles: " . implode(', ', $data) . " num = ".$num." [{$nRow}]\n\n"
                 //                    );
                 continue;
             }
             // *************************************************************************************************
             // тут получаем данные по полям строки
             $bEmpty = true;
             // это останется true в полностью пустой строке
             $aAttr = [];
             for ($i = 0; $i < $num; $i++) {
                 if (!empty($data[$i])) {
                     $bEmpty = false;
                     //                        $this->printStr(
                     //                            "row [{$nRow}]: $i = " . $data[$i] . " -> {$aFields[$i]}\n\n"
                     //                        );
                     if (!empty($aFields[$i])) {
                         $aAttr[$aFields[$i]] = (isset($aAttr[$aFields[$i]]) ? $aAttr[$aFields[$i]] . ' ' : '') . trim($data[$i]);
                     }
                 }
             }
             // *************************************************************************************************
             // тут пропускаем полностью пустую строку
             if ($bEmpty) {
                 //                    $this->printStr(
                 //                        "Empty row: " . implode(', ', $data) . " num = ".$num." [{$nRow}]\n\n"
                 //                    );
                 continue;
             }
             // *************************************************************************************************
             // тут пропускаем без почты
             if (!isset($aAttr['us_email'])) {
                 $this->printStr("No email: " . implode(', ', $data) . " [{$nRow}]\n\n");
                 continue;
             }
             //                $this->printStr(
             //                    "aAttr: " . print_r($aAttr, true) . " [{$nRow}]\n\n"
             //                );
             //                continue;
             $oUser = User::find()->where(['us_email' => $aAttr['us_email']])->one();
             //                $this->printStr(
             //                    "Data row: " . print_r($aAttr, true) . " [{$nRow}]\n\n"
             //                );
             if ($oUser === null) {
                 //нового заводим
                 $oUser = new User();
                 $oUser->scenario = 'modregister';
                 $aAttr['password'] = Yii::$app->security->generateRandomString(6);
                 $oUser->us_group = User::USER_GROUP_MODERATOR;
                 $oUser->attributes = $aAttr;
                 $oUser->sectionids = $aSectionId;
                 $oUser->us_active = User::STATUS_ACTIVE;
                 if (!$oUser->save()) {
                     $this->printStr("Error save new user: "******" [{$nRow}]\n\n");
                 } else {
                     $aResultData[] = ['us_name' => $aAttr['us_name'], 'password' => $aAttr['password'], 'us_description' => $aAttr['us_description'], 'us_email' => $aAttr['us_email'], 'section' => ''];
                 }
             } else {
                 $oldSec = $oUser->sectionids;
                 foreach ($aSectionId as $id) {
                     if (!in_array($id, $oldSec)) {
                         $oldSec[] = $id;
                     }
                 }
                 $oUser->sectionids = $oldSec;
                 if (!$oUser->save()) {
                     $this->printStr("Error save exists user: "******" [{$nRow}]\n\n");
                 } else {
                     $this->printStr("New user sections: " . $oUser->us_email . ' ' . implode(', ', $oldSec) . " [{$nRow}]\n\n");
                 }
             }
         }
         fclose($hd);
         if (count($aResultData) > 0) {
             $sFile = dirname($filename) . DIRECTORY_SEPARATOR . 'users-' . time() . '.csv';
             $this->printResult($aResultData, $sFile);
             $this->printStr("Users save: " . count($aResultData) . ", file {$sFile}\n\n");
         }
     } else {
         echo "\n\nCan't open file {$filename}\n\n";
     }
 }