<commit_before><?php

namespace App\Http\Controllers;

use App\Http\Controllers\SOAPController;
use App\Http\Controllers\MessagesController;
use PHPHtmlParser\Dom;

class TeacherController extends Controller {
    private $dom;
    private $soap;
    private $message;
    
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct(SOAPController $soap, MessagesController $message, Dom $dom) {
        $this->soap = $soap;
        $this->message = $message;
        $this->dom = $dom;
    }

    public function getTeachers($option) {
        if ($option == "all") {
            $docentes = [];

            foreach (json_decode($this->soap->getDataFromSOAPServer("docentes")->docentesResult)->Docentes as $docente) {
                $docentes[] = array("nome" => $docente->Docente, "sigla" => $docente->Sigla);
            }

            return $this->message->encodeMessage(0, $docentes);
        }

        $docente = [];

        $docenteAux = $this->soap->getDataFromSOAPServer("docente", array("docente" => array("sigla" => $option)));

        $detalhesDocente = str_replace("<hr>", "", json_decode($docenteAux->docenteResult)->Docente);

        $this->dom = new Dom();

        $this->dom->load($detalhesDocente);

        return json_encode($this->parseTeacherInformation($this->dom));

        return (!empty($parsedMenu)) ? $this->message->encodeMessage(0, $parsedMenu) : $this->message->encodeMessage(1, "No menu information found");
    }

    private function parseTeacherInformation($info) {
        $teacherInfo = [];
        $atendimentoAux = [];

        $nome = $info->find('b')->text;

        for($i = 0; $i < count($info->find('p')); $i++) {
            if ($info->find('p')[$i]->text == "Ocupação Semanal do Docente") {
                $aux = 0;
                for($j = ($i+1); $j < count($info->find('p')); $j++) {
                    preg_match("/([\d]{4}-[\d]{2}-[\d]{2})/", $info->find('p')[$j]->text, $ultimaAtualizacao);

                    preg_match("/(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})/", $info->find('p')[$j]->text, $email);

                    if (isset($ultimaAtualizacao) && count($ultimaAtualizacao) > 1)
                        $lastUpdated = $ultimaAtualizacao[0];

                    if (isset($email) && count($email) > 1)
                        $teacherEmail = $email[0];

                    if ($aux < count($info->find('ul'))) {
                        preg_match_all("/(?:<li>)(.*?)(?:<\/li>)/", $info->find('ul')[$aux]->innerHtml, $diasAtendimento);

                        $atendimentoAux[str_replace(":", "", $info->find('p')[$j]->text)] = $diasAtendimento[1];

                        $aux++;<commit_msg>Fix return teacher details return structure<commit_after><?php

namespace App\Http\Controllers;

use App\Http\Controllers\SOAPController;
use App\Http\Controllers\MessagesController;
use PHPHtmlParser\Dom;

class TeacherController extends Controller {
    private $dom;
    private $soap;
    private $message;
    
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct(SOAPController $soap, MessagesController $message, Dom $dom) {
        $this->soap = $soap;
        $this->message = $message;
        $this->dom = $dom;
    }

    public function getTeachers($option) {
        if ($option == "all") {
            $docentes = [];

            foreach (json_decode($this->soap->getDataFromSOAPServer("docentes")->docentesResult)->Docentes as $docente) {
                $docentes[] = array("nome" => $docente->Docente, "sigla" => $docente->Sigla);
            }

            return $this->message->encodeMessage(0, $docentes);
        }

        $docente = [];

        $docenteAux = $this->soap->getDataFromSOAPServer("docente", array("docente" => array("sigla" => $option)));

        $detalhesDocente = str_replace("<hr>", "", json_decode($docenteAux->docenteResult)->Docente);

        $this->dom = new Dom();

        $this->dom->load($detalhesDocente);
        
        return (!empty($this->parseTeacherInformation($this->dom))) ? $this->message->encodeMessage(0, $this->parseTeacherInformation($this->dom)) : $this->message->encodeMessage(1, "No menu information found");
    }

    private function parseTeacherInformation($info) {
        $teacherInfo = [];
        $atendimentoAux = [];

        $nome = $info->find('b')->text;

        for($i = 0; $i < count($info->find('p')); $i++) {
            if ($info->find('p')[$i]->text == "Ocupação Semanal do Docente") {
                $aux = 0;
                for($j = ($i+1); $j < count($info->find('p')); $j++) {
                    preg_match("/([\d]{4}-[\d]{2}-[\d]{2})/", $info->find('p')[$j]->text, $ultimaAtualizacao);

                    preg_match("/(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})/", $info->find('p')[$j]->text, $email);

                    if (isset($ultimaAtualizacao) && count($ultimaAtualizacao) > 1)
                        $lastUpdated = $ultimaAtualizacao[0];

                    if (isset($email) && count($email) > 1)
                        $teacherEmail = $email[0];

                    if ($aux < count($info->find('ul'))) {
                        preg_match_all("/(?:<li>)(.*?)(?:<\/li>)/", $info->find('ul')[$aux]->innerHtml, $diasAtendimento);

                        $atendimentoAux[str_replace(":", "", $info->find('p')[$j]->text)] = $diasAtendimento[1];

                        $aux++;
{'fraction_non_alphanumeric': 0.22366317285485876, 'fraction_numerical': 0.005329543435779001, 'mean_word_length': 2.3977066988533493, 'pattern_counts': {'":': 2, '<': 25, '<?xml version=': 0, '>': 109, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4927511', 'n_tokens_mistral': 1857, 'n_tokens_neox': 1793, 'n_words': 274}