\doxysection{candidatos.\+php}
\hypertarget{candidatos_8php_source}{}\label{candidatos_8php_source}\index{api/candidatos.php@{api/candidatos.php}}
\mbox{\hyperlink{candidatos_8php}{Go to the documentation of this file.}}
\begin{DoxyCode}{0}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00001}00001\ <?php}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00002}00002\ }
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00025}00025\ \textcolor{comment}{//\ Gera\ um\ objeto\ com\ os\ dados\ dos\ vereadores,\ prefeitos\ e\ seus\ respectivos\ vice-\/prefeitos.}}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00026}00026\ \mbox{\hyperlink{candidatos_8php_a81260297007ddb8c90c088cf48a27eef}{\$candidatos}}[\textcolor{charliteral}{'0'}]\ =\ \mbox{\hyperlink{candidatos_8php_a308a276a167b775c361cbfe303cab725}{getVereadores}}();}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00027}00027\ \mbox{\hyperlink{candidatos_8php_a81260297007ddb8c90c088cf48a27eef}{\$candidatos}}[\textcolor{charliteral}{'1'}]\ =\ \mbox{\hyperlink{candidatos_8php_ab0b5cc5fd1a70c079e48b942887de869}{getPrefeitos}}();}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00028}00028\ }
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00029}00029\ \textcolor{comment}{//\ print\_r(\$candidatos);}}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00030}00030\ }
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00031}00031\ \textcolor{comment}{//\ Retorna\ um\ json\ contendo\ os\ dados\ dos\ candidatos}}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00032}00032\ header(\textcolor{stringliteral}{'Content-\/Type:\ application/json;\ charset=utf-\/8'});}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00033}00033\ echo\ json\_encode(\mbox{\hyperlink{candidatos_8php_a81260297007ddb8c90c088cf48a27eef}{\$candidatos}});}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00034}00034\ }
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00042}00042\ \textcolor{keyword}{function}\ \mbox{\hyperlink{candidatos_8php_a308a276a167b775c361cbfe303cab725}{getVereadores}}()}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00043}00043\ \{}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00044}00044\ \ \ \ \ \textcolor{comment}{//\ Conecta\ com\ o\ banco\ de\ dados}}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00045}00045\ \ \ \ \ require(\textcolor{stringliteral}{'connect.php'});}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00046}00046\ }
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00047}00047\ \ \ \ \ \mbox{\hyperlink{connect-local_8php_aa8a5a87b9c1a6a0819b88447cbe41877}{\$conn}}-\/>set\_charset(\textcolor{stringliteral}{"{}utf8mb4"{}});}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00048}00048\ }
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00049}00049\ \ \ \ \ \textcolor{comment}{//\ Executa\ a\ query\ para\ obter\ vereadores}}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00050}00050\ \ \ \ \ \$vereadores\_query\ =\ \mbox{\hyperlink{connect-local_8php_aa8a5a87b9c1a6a0819b88447cbe41877}{\$conn}}-\/>query(}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00051}00051\ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}SELECT\ \`{}numero`,\ \`{}nome`,\ \`{}partido`,\ \`{}foto`}}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00052}00052\ \textcolor{stringliteral}{\ \ \ \ \ \ \ \ FROM\ \`{}Candidato`}}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00053}00053\ \textcolor{stringliteral}{\ \ \ \ \ \ \ \ WHERE\ \`{}titulo`\ =\ 'vereador'"{}}}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00054}00054\ \ \ \ \ );}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00055}00055\ }
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00056}00056\ \ \ \ \ \textcolor{comment}{//\ Retorna\ erro\ em\ caso\ de\ falha\ na\ query}}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00057}00057\ \ \ \ \ \textcolor{keywordflow}{if}\ (!\$vereadores\_query)\ \{}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00058}00058\ \ \ \ \ \ \ \ \ http\_response\_code(500);}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00059}00059\ \ \ \ \ \ \ \ \ die(\textcolor{stringliteral}{"{}Erro\ ao\ obter\ vereadores."{}});}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00060}00060\ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00061}00061\ }
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00062}00062\ \ \ \ \ \$row\ =\ \$vereadores\_query-\/>fetch\_assoc();}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00063}00063\ }
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00064}00064\ \ \ \ \ \$vereadores[\textcolor{stringliteral}{'titulo'}]\ =\ \textcolor{stringliteral}{'vereador'};}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00065}00065\ \ \ \ \ \$vereadores[\textcolor{stringliteral}{'numeros'}]\ =\ strlen(\$row[\textcolor{stringliteral}{'numero'}]);}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00066}00066\ }
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00067}00067\ \ \ \ \ \textcolor{keywordflow}{do}\ \{}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00068}00068\ \ \ \ \ \ \ \ \ \$vereadores[\textcolor{stringliteral}{'candidatos'}][\$row[\textcolor{stringliteral}{'numero'}]]\ =\ \$row;}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00069}00069\ \ \ \ \ \ \ \ \ unset(\$vereadores[\textcolor{stringliteral}{'candidatos'}][\$row[\textcolor{stringliteral}{'numero'}]][\textcolor{stringliteral}{'numero'}]);}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00070}00070\ \ \ \ \ \ \ \ \ \$row\ =\ \$vereadores\_query-\/>fetch\_assoc();}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00071}00071\ \ \ \ \ \}\ \textcolor{keywordflow}{while}\ (\$row\ !=\ \textcolor{keyword}{null});}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00072}00072\ }
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00073}00073\ \ \ \ \ \textcolor{keywordflow}{return}\ \$vereadores;}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00074}00074\ \}}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00075}00075\ }
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00084}00084\ \textcolor{keyword}{function}\ \mbox{\hyperlink{candidatos_8php_ab0b5cc5fd1a70c079e48b942887de869}{getPrefeitos}}()}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00085}00085\ \{}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00086}00086\ \ \ \ \ \textcolor{comment}{//\ Conecta\ com\ o\ banco\ de\ dados}}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00087}00087\ \ \ \ \ require(\textcolor{stringliteral}{'connect.php'});}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00088}00088\ }
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00089}00089\ \ \ \ \ \mbox{\hyperlink{connect-local_8php_aa8a5a87b9c1a6a0819b88447cbe41877}{\$conn}}-\/>set\_charset(\textcolor{stringliteral}{"{}utf8mb4"{}});}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00090}00090\ }
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00091}00091\ \ \ \ \ \textcolor{comment}{//\ Executa\ a\ query\ para\ obter\ prefeitos\ e\ vice-\/prefeitos}}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00092}00092\ \ \ \ \ \$prefeitos\_query\ =\ \mbox{\hyperlink{connect-local_8php_aa8a5a87b9c1a6a0819b88447cbe41877}{\$conn}}-\/>query(}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00093}00093\ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}SELECT\ *}}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00094}00094\ \textcolor{stringliteral}{\ \ \ \ \ \ \ \ FROM\ \`{}Candidato`\ INNER\ JOIN\ \`{}Vice`\ USING\ (numero)}}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00095}00095\ \textcolor{stringliteral}{\ \ \ \ \ \ \ \ WHERE\ \`{}titulo`\ =\ 'prefeito'"{}}}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00096}00096\ \ \ \ \ );}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00097}00097\ }
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00098}00098\ \ \ \ \ \textcolor{comment}{//\ Retorna\ erro\ em\ caso\ de\ falha\ na\ query}}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00099}00099\ \ \ \ \ \textcolor{keywordflow}{if}\ (!\$prefeitos\_query)\ \{}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00100}00100\ \ \ \ \ \ \ \ \ http\_response\_code(500);}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00101}00101\ \ \ \ \ \ \ \ \ die(\textcolor{stringliteral}{"{}Erro\ ao\ obter\ prefeitos."{}});}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00102}00102\ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00103}00103\ }
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00104}00104\ \ \ \ \ \$row\ =\ \$prefeitos\_query-\/>fetch\_row();}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00105}00105\ }
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00106}00106\ \ \ \ \ \$prefeitos[\textcolor{stringliteral}{'titulo'}]\ =\ \textcolor{stringliteral}{'prefeito'};}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00107}00107\ \ \ \ \ \$prefeitos[\textcolor{stringliteral}{'numeros'}]\ =\ strlen(\$row[0]);}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00108}00108\ }
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00109}00109\ \ \ \ \ \textcolor{keywordflow}{do}\ \{}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00110}00110\ \ \ \ \ \ \ \ \ \$prefeitos[\textcolor{stringliteral}{'candidatos'}][\$row[0]][\textcolor{stringliteral}{'nome'}]\ =\ \$row[1];}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00111}00111\ \ \ \ \ \ \ \ \ \$prefeitos[\textcolor{stringliteral}{'candidatos'}][\$row[0]][\textcolor{stringliteral}{'partido'}]\ =\ \$row[3];}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00112}00112\ \ \ \ \ \ \ \ \ \$prefeitos[\textcolor{stringliteral}{'candidatos'}][\$row[0]][\textcolor{stringliteral}{'foto'}]\ =\ \$row[4];}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00113}00113\ \ \ \ \ \ \ \ \ \$prefeitos[\textcolor{stringliteral}{'candidatos'}][\$row[0]][\textcolor{stringliteral}{'vice'}][\textcolor{stringliteral}{'nome'}]\ =\ \$row[6];}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00114}00114\ \ \ \ \ \ \ \ \ \$prefeitos[\textcolor{stringliteral}{'candidatos'}][\$row[0]][\textcolor{stringliteral}{'vice'}][\textcolor{stringliteral}{'partido'}]\ =\ \$row[7];}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00115}00115\ \ \ \ \ \ \ \ \ \$prefeitos[\textcolor{stringliteral}{'candidatos'}][\$row[0]][\textcolor{stringliteral}{'vice'}][\textcolor{stringliteral}{'foto'}]\ =\ \$row[8];}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00116}00116\ \ \ \ \ \ \ \ \ \$row\ =\ \$prefeitos\_query-\/>fetch\_row();}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00117}00117\ \ \ \ \ \}\ \textcolor{keywordflow}{while}\ (\$row\ !=\ \textcolor{keyword}{null});}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00118}00118\ }
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00119}00119\ \ \ \ \ \textcolor{keywordflow}{return}\ \$prefeitos;}
\DoxyCodeLine{\Hypertarget{candidatos_8php_source_l00120}00120\ \}}

\end{DoxyCode}
