/**
  * @return \yii\db\ActiveQuery
  */
 public function getFunction()
 {
     return $this->hasOne(Functions::className(), ['ID' => 'function_Id']);
 }
 /**
  * Import booth data using spreadsheet
  * @return mixed
  */
 public function actionExcel()
 {
     $model = new Booths();
     if ($model->load(Yii::$app->request->post())) {
         $congid = $_POST['Booths']['id'];
         $model->fileName = UploadedFile::getInstance($model, 'fileName');
         $time = time();
         $model->fileName->saveAs('csv/' . $time . '.' . $model->fileName->extension);
         $model->fileName = 'csv/' . $time . '.' . $model->fileName->extension;
         $handle = fopen($model->fileName, "r");
         $row = 1;
         while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
             $row++;
             if ($row == 2) {
                 //Ignoring row 2
             } else {
                 //Parsing Time
                 $time = $data[2];
                 $exp = explode('-', $time);
                 $starttime = $exp[0];
                 $endtime = $exp[1];
                 //Getting User ID
                 $userData = AmgenContactList::find()->where(['Name' => $data[6]])->one();
                 $userid = $userData['id'];
                 $title = $data[7];
                 $departmentData = Functions::find()->where(['Name' => $data[8]])->one();
                 $department_id = $departmentData['ID'];
                 $group = CostCenter::find()->where(['Group_name' => $data[9]])->one();
                 $group_id = $group['id'];
                 //Getting Status  ID
                 $statusInfo = Status::find()->where(['status' => $data[10]])->one();
                 $status_id = $statusInfo['id'];
                 $sql = "INSERT into booths(congress_id,booth_name,from_time,to_time,date,location) values('{$congid}','{$data['1']}','{$starttime}','{$endtime}','{$data['3']}','{$data['4']}')";
                 $query = Yii::$app->db->createCommand($sql)->execute();
                 $booth_id = Yii::$app->db->getLastInsertID();
                 $sql_booth_schedule = "INSERT into booth_schedules(booth_id,attendee_id,title,function_id,cost_center_id,status_id) values('{$booth_id}','{$userid}','{$title}','{$department_id}','{$group_id}','{$status_id}')";
                 Yii::$app->db->createCommand($sql_booth_schedule)->execute();
             }
         }
         fclose($handle);
         print "Import done";
     }
     return $this->render('excel', ['model' => $model]);
 }
Exemplo n.º 3
0
   <?php 
echo $form->field($model, 'Name')->textInput(['maxlength' => true]);
?>
                </div>
</div>
<div class="col-xs-6 col-sm-4 p5">
            	<div class="ml20"> 
    <?php 
echo $form->field($model, 'Title')->textInput(['maxlength' => true]);
?>
                </div>
</div>
    <div class="col-xs-6 col-sm-4 p5">
            	<div class="ml20"> 
    <?php 
echo $form->field($model, 'function_Id', array('labelOptions' => array('class' => 'f18')))->dropDownList(ArrayHelper::map(Functions::find()->asArray()->all(), 'ID', 'Name'), ['ID' => 'Name']);
?>
  
           
                </div>
    </div>
   
    <div class="col-xs-6 col-sm-4 p5">
            	<div class="ml20"> 
  <?php 
echo $form->field($model, 'group_Id', array('labelOptions' => array('class' => 'f18')))->dropDownList(ArrayHelper::map(CostCenter::find()->asArray()->all(), 'id', 'Group_name'), ['id' => 'Group_name']);
?>
  
                </div>
    </div>
                    <div class="col-xs-6 col-sm-4 p5">