public function actionSalvaConteudoAula()
 {
     // echo print_r(Yii::$app->request->post());
     //  exit();
     $salvos = 0;
     if (Yii::$app->request->post()) {
         $post = Yii::$app->request->post();
         //  $transaction = Yii::$app->db->beginTransaction();
         // try {
         unset($post['_csrf']);
         foreach ($post as $i => $item) {
             $aux = split('_', $i);
             $scheduleContent = Acdscheduleprofessorcontent::findOne(['scheduleprofessorcontentid' => (int) $aux[1]]);
             if ($scheduleContent == null) {
                 $scheduleContent = new Acdscheduleprofessorcontent();
             }
             $scheduleContent->ipaddress = $_SERVER['REMOTE_ADDR'];
             $scheduleContent->datetime = Yii::$app->DadosServidor->getDateNow();
             $scheduleContent->realstartdate = $aux[3] . ' ' . $aux[5];
             $scheduleContent->realenddate = $aux[3] . ' ' . $aux[6];
             $scheduleContent->scheduleprofessorid = $aux[2];
             $scheduleContent->timeid = $aux[4];
             $scheduleContent->date = $aux[3];
             // $scheduleContent->username = '******';
             $scheduleContent->description = $item;
             $scheduleContent->classoccurred = true;
             if ($scheduleContent->description != '' || $scheduleContent->description != null) {
                 if ($scheduleContent->save()) {
                     $salvos++;
                 } else {
                 }
             }
         }
         if ($salvos != 0) {
             echo 1;
         } else {
             echo 0;
         }
         // $transaction->commit();
         /*   } catch (\Exception $e) {
                  $transaction->rollback();
                  echo 0;
                  throw $e;
                 // return false;
              }*/
     } else {
         //echo 0;
         // return false;
     }
     ///exit();
 }
 public function getRegistro2($params)
 {
     $dataPesq = [];
     $timePesq = [];
     if ($params) {
         if (isset($params['Acdscheduleprofessorcontent']['dataInicial'])) {
             $this->dataInicial = $params['Acdscheduleprofessorcontent']['dataInicial'];
         }
         if (isset($params['Acdscheduleprofessorcontent']['dataFinal'])) {
             $this->dataFinal = $params['Acdscheduleprofessorcontent']['dataFinal'];
         }
         if (isset($params['Acdscheduleprofessorcontent']['horas'])) {
             if (!empty($params['Acdscheduleprofessorcontent']['horas'])) {
                 // foreach ($params['Acdscheduleprofessorcontent']['horas'] as $itemPesqTime) {
                 $vetTime = $params['Acdscheduleprofessorcontent']['horas'];
                 //}
                 $timePesq = ['in', 'acdscheduleprofessorcontent.timeid', $vetTime];
             }
         }
         if (isset($params['Acdscheduleprofessorcontent']['dataInicial']) && $this->dataInicial != '' && $this->dataFinal != '' && isset($params['Acdscheduleprofessorcontent']['dataFinal'])) {
             $dataPesq = ['between', 'acdscheduleprofessorcontent.date', $this->dataInicial, $this->dataFinal];
         }
         //   }
     }
     $conteudo = Acdscheduleprofessorcontent::find()->indexBy('scheduleprofessorcontentid')->joinWith(['scheduleprofessor.professor', 'scheduleprofessor.schedule', 'time'])->andwhere(['acdscheduleprofessor.professorid' => (int) Yii::$app->session['idprofessor']])->andwhere($timePesq)->andwhere($dataPesq)->andWhere(['acdschedule.groupid' => (int) Yii::$app->session['groupid']])->orderBy('date')->all();
     $retorno = array();
     $retorno['agenda'] = Acdscheduleprofessor::find()->joinWith(['schedule'])->andwhere(['acdschedule.groupid' => Yii::$app->session['groupid']])->andwhere(['professorid' => Yii::$app->session['idprofessor']])->orderBy('groupid')->all();
     $times = array();
     $agendaTab = array();
     $compareInicial = str_replace('-', '', $this->dataInicial);
     $compareFinal = str_replace('-', '', $this->dataFinal);
     foreach ($retorno['agenda'] as $str) {
         $str->schedule->timeids = str_replace('{', '', $str->schedule->timeids);
         $str->schedule->timeids = str_replace('}', '', $str->schedule->timeids);
         $timeAux = split(',', $str->schedule->timeids);
         $str->schedule->occurrencedates = str_replace('{', '', $str->schedule->occurrencedates);
         $str->schedule->occurrencedates = str_replace('}', '', $str->schedule->occurrencedates);
         $colunAux = split(',', $str->schedule->occurrencedates);
         $colunTabAux = array();
         $colunTime = array();
         foreach ($colunAux as $data) {
             $compareData = str_replace('-', '', $data);
             if ($compareData >= $compareInicial && $compareData <= $compareFinal) {
                 foreach ($timeAux as $hora) {
                     if (!empty($vetTime)) {
                         foreach ($vetTime as $pesquisaHoraAula) {
                             if ($pesquisaHoraAula == $hora) {
                                 $agendaTab[$data][$hora] = $str->scheduleprofessorid;
                             }
                         }
                     } else {
                         $agendaTab[$data][$hora] = $str->scheduleprofessorid;
                     }
                 }
             }
         }
     }
     $cont = 0;
     $provider = [];
     foreach ($agendaTab as $data => $colunaItem) {
         // echo $data.'   ';
         foreach ($colunaItem as $hora => $id) {
             // foreach ($retorno['timeData'] as $tempo) {
             // foreach ($conteudo as $obj) {
             $cont++;
             array_push($provider, ['scheduleprofessorcontentid' => '', 'date' => $data, 'timeid' => Acdtime::findOne(["timeid" => $hora]), 'description' => '', 'scheduleprofessorid' => $id, 'classoccurred' => 'true', 'id' => $cont]);
             //}
         }
     }
     $cont = 0;
     foreach ($conteudo as $obj) {
         foreach ($provider as $i => $item) {
             //echo '$obj->scheduleprofessorid'.$obj->scheduleprofessorid.'=='.$item['scheduleprofessorid'].'/////////////';
             if ($obj->date == $provider[$i]['date'] && $obj->timeid == $provider[$i]['timeid']->timeid) {
                 // echo $obj->description;
                 //$cont++;
                 // echo '</br>'.$obj->description;
                 $provider[$i]['scheduleprofessorcontentid'] = $obj->scheduleprofessorcontentid;
                 //  $item['date'] = $data;
                 //  $item['timeid'] = $tempo;
                 $provider[$i]['description'] = $obj->description;
                 // $item['scheduleprofessorid'] = $id;
                 $provider[$i]['classoccurred'] = $obj->classoccurred;
             }
         }
     }
     //   echo $cont;
     //   exit();
     /* foreach ($conteudo as $item){
               echo $item->scheduleprofessorcontentid;
     
               } */
     // echo ''.print_r($provider);
     //  exit();
     $dataProvider = new ArrayDataProvider(['allModels' => $this->ordenaVet($provider)]);
     return $dataProvider;
 }
Exemplo n.º 3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAcdscheduleprofessorcontents()
 {
     return $this->hasMany(Acdscheduleprofessorcontent::className(), ['timeid' => 'timeid']);
 }