/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Discipline::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'school_id' => $this->school_id, 'area_id' => $this->area_id]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'short_name', $this->short_name]);
     return $dataProvider;
 }
示例#2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Discipline::find();
     $query->joinWith(['area', 'school']);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $dataProvider->sort->attributes['area'] = ['asc' => ['area.name' => SORT_ASC], 'desc' => ['area.name' => SORT_DESC]];
     $dataProvider->sort->attributes['school'] = ['asc' => ['school.name' => SORT_ASC], 'desc' => ['school.name' => SORT_DESC]];
     $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, 'discipline.active' => $this->active]);
     $query->andFilterWhere(['like', 'discipline.name', $this->name])->andFilterWhere(['like', 'short_name', $this->short_name])->andFilterWhere(['like', 'area.name', $this->area])->andFilterWhere(['like', 'school.name', $this->school]);
     return $dataProvider;
 }
 public function upload()
 {
     if ($this->validate()) {
         $isValidFormat = true;
         $isValidEncoding = true;
         if (($handle = fopen($this->csvFile->tempName, "r")) !== FALSE) {
             if (($firstLine = fgetcsv($handle)) !== FALSE) {
                 if (count($firstLine) >= 2) {
                     if (mb_detect_encoding($firstLine[0]) !== 'ASCII') {
                         $isValidEncoding = false;
                         $firstLine = $this->convert_to_ASCII($firstLine);
                     }
                 } else {
                     $isValidFormat = false;
                 }
                 if ($isValidFormat) {
                     if ($firstLine[0] !== 'client_id' || $firstLine[1] !== 'full_name' || $firstLine[2] !== 'client_type_id' || $firstLine[3] !== 'discipline_id' || $firstLine[4] !== 'active') {
                         $isValidFormat = false;
                     }
                 }
             }
             if ($isValidFormat) {
                 $success = true;
                 $row = 1;
                 while (($data = fgetcsv($handle)) !== FALSE) {
                     if (!$isValidEncoding) {
                         $data = $this->convert_to_ASCII($data);
                     }
                     $row++;
                     $model = new Client();
                     $model->client_id = $data[0];
                     $model->full_name = $data[1];
                     $model->client_type_id = $data[2];
                     $model->discipline_id = $data[3];
                     $model->active = $data[4];
                     if (!$model->save()) {
                         $idClient = Client::find()->where(['client_id' => $model->client_id])->exists();
                         $typeClient = ClientType::find()->where(['id' => $model->client_type_id])->exists();
                         $idDiscipline = Discipline::find()->where(['id' => $model->discipline_id])->exists();
                         $activo = Client::find()->where(['active' => $model->active])->exists();
                         if ($idClient == true) {
                             Yii::$app->session->addFlash("error-upload", "Error en línea: [" . $row . "] ----- El cliente con id: [" . $model->client_id . "] ya se encuentra registrado.");
                         } else {
                             if ($typeClient == false || $idDiscipline == false || $activo == false) {
                                 if ($typeClient == false) {
                                     $typeClient = "[client_type_id] No Válido. ";
                                 } else {
                                     $typeClient = "";
                                 }
                                 if ($idDiscipline == false) {
                                     $idDiscipline = "[discipline_id] No Válido. ";
                                 } else {
                                     $idDiscipline = "";
                                 }
                                 if ($activo == false) {
                                     $activo = "[active] No Válido.";
                                 } else {
                                     $activo = "";
                                 }
                                 Yii::$app->session->addFlash("error-upload", "Error en línea: [" . $row . "] ----- " . $typeClient . "" . $idDiscipline . "" . $activo . "");
                             }
                         }
                     }
                 }
                 if (!feof($handle)) {
                     $success = false;
                     Yii::$app->session->setFlash('error', Yii::t('app', 'Unexpected error.'));
                 }
             } else {
                 Yii::$app->session->setFlash('error', Yii::t('app', 'El formato del archivo No es válido. El formato válido es: ') . "<div class=\"panel panel-default\">\n\t\t\t\t\t\t\t<div class=\"panel-body\">\n\t\t\t\t\t\t\t\t<p>client_id,full_name,client_type_id,discipline_id,active</p>\n\t\t\t\t\t\t\t\t<p>98341245,Pedro Salazar Dos,1,5,1</p>\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t</div>");
             }
             fclose($handle);
         }
         return $isValidFormat && $success;
     } else {
         return false;
     }
 }
 /**
  * Finds the Discipline model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return Discipline the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Discipline::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
示例#5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getDiscipline()
 {
     return $this->hasOne(Discipline::className(), ['id' => 'discipline_id']);
 }
示例#6
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getDisciplines()
 {
     return $this->hasMany(Discipline::className(), ['school_id' => 'id']);
 }
示例#7
0
?>

    <?php 
echo $form->field($model, 'first_name')->textInput(['maxlength' => 175]);
?>

    <?php 
echo $form->field($model, 'last_name')->textInput(['maxlength' => 175]);
?>

    <?php 
echo $form->field($model, 'client_type_id')->radioList(ArrayHelper::map(ClientType::find()->all(), 'id', 'type'));
?>

    <?php 
echo $form->field($model, 'discipline_id')->dropDownList(ArrayHelper::map(Discipline::find()->all(), 'id', 'name', 'short_name'), ['prompt' => Yii::t('app', 'You could select a discipline')]);
?>

    <?php 
echo $form->field($model, 'active')->checkbox([], false);
?>
	

    <div class="form-group">
        <?php 
echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
    </div>

    <?php 
ActiveForm::end();
示例#8
0
?>

    <?php 
echo $form->field($model, 'client_id')->textInput(['maxlength' => 30, 'onkeyup' => 'javascript:this.value=this.value.toUpperCase();']);
?>

    <?php 
echo $form->field($model, 'full_name')->textInput(['maxlength' => 175, 'onkeyup' => 'javascript:this.value=this.value.toUpperCase();']);
?>

    <?php 
echo $form->field($model, 'client_type_id')->radioList(ArrayHelper::map(ClientType::find()->all(), 'id', 'type'));
?>

    <?php 
echo $form->field($model, 'discipline_id')->dropDownList(ArrayHelper::map(Discipline::find()->orderBy('name ASC')->all(), 'id', 'name'));
?>

    <?php 
echo $form->field($model, 'active')->checkbox([], false);
?>

    <div class="form-group">
        <?php 
echo Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary', 'style' => 'float:left; margin-left:299px;']);
?>
		<?php 
echo Html::a('Cancelar', ['assignation/create'], ['class' => 'btn btn-danger btn-md', 'style' => 'margin-left:396px;']);
?>
		<!--?= Html::a('Cancelar', [Yii::$app->request->referrer], ['class' => 'btn btn-danger btn-md', 'style' => 'margin-left:396px;']) ?-->
    </div>