Etapas do ano anterior (".($this->ref_ano - 1).') | ||||||
';
+ $tabela .= '
| ||||||
Adicione as etapas abaixo para {$this->ref_ano} semelhante ao exemplo do ano anterior: | ||||||
"; + $tabela .= ' |
%s |
%s |
Nome | Turma | |
' + (i + 1) + ' | '; + html += '' + v.nome + ' | '; + html += '' + v.nm_turma + ' | '; + html += '
- * 5,
- * 'E2' => 7,
- * 'E3' => 8,
- * 'E4' => 10,
- * 'Et' => 4,
- * 'Rc' => 0,
- * 'Se' => 30
- * );
- *
- * $formula = $formulaModel->replaceTokens($formulaModel->formulaMedia, $values);
- *
- *
- * @param string $formula
- * @param array $values
- * @return string
- */
- public function replaceTokens($formula, $values = array())
- {
- $formula = $this->replaceAliasTokens($formula);
+ /**
+ * Executa o código da fórmula usando eval.
+ *
+ * @param string $code
+ *
+ * @return float|null
+ */
+ protected function _exec($code)
+ {
+ $result = null;
+
+ eval('?>');
+
+ return $result;
+ }
- if($this->substituiMenorNotaRc && is_numeric($values['Rc'])){
- $values = $this->substituiMenorNotaPorRecuperacao($values);
+ /**
+ * Retorna os tokens permitidos para uma fórmula.
+ *
+ * @return array
+ */
+ public function getTokens()
+ {
+ return $this->_tokens;
}
- $patterns = array();
- foreach ($values as $key => $value) {
- if ($this->isNumericToken($key)) {
- // Usa @ como delimitador para evitar problemas com o sinal de divisão
- $patterns[$key] = '@' . $key . '@';
- }
+ /**
+ * Verifica se um token pode receber um valor numérico.
+ *
+ * @param string $token
+ *
+ * @return bool
+ */
+ public function isNumericToken($token)
+ {
+ return in_array($token, $this->_tokenNumerics);
}
- // Usa locale en_US para evitar problemas com pontos flutuantes
- $this->getLocale()->resetLocale();
+ /**
+ * Substitui os tokens numéricos de uma fórmula, através de um array
+ * associativo.
+ *
+ *
+ * 5,
+ * 'E2' => 7,
+ * 'E3' => 8,
+ * 'E4' => 10,
+ * 'Et' => 4,
+ * 'Rc' => 0,
+ * 'Se' => 30
+ * );
+ *
+ * $formula = $formulaModel->replaceTokens($formulaModel->formulaMedia, $values);
+ *
+ *
+ * @param string $formula
+ * @param array $values
+ *
+ * @return string
+ */
+ public function replaceTokens($formula, $values = [])
+ {
+ $formula = $this->replaceAliasTokens($formula);
- // Substitui os tokens
- $replaced = preg_replace($patterns, $values, $formula);
+ if ($this->substituiMenorNotaRc && is_numeric($values['Rc'])) {
+ $values = $this->substituiMenorNotaPorRecuperacao($values);
+ }
- // Retorna ao locale anterior
- $this->getLocale()->setLocale();
+ $patterns = [];
+ foreach ($values as $key => $value) {
+ if ($this->isNumericToken($key)) {
+ // Usa @ como delimitador para evitar problemas com o sinal de divisão
+ $patterns[$key] = '@' . $key . '@';
+ }
+ }
- return $replaced;
- }
+ // Usa locale en_US para evitar problemas com pontos flutuantes
+ $this->getLocale()->resetLocale();
- /**
- * Troca os tokens de alias pelos usados durante a execução da fórmula.
- * @param string $formula
- * @return string
- */
- public function replaceAliasTokens($formula)
- {
- return preg_replace(array('/\(/', '/\)/', '/x/'), array(' ( ', ' ) ', '*'), $formula);
- }
+ // Substitui os tokens
+ $replaced = preg_replace($patterns, $values, $formula);
- /**
- *
- * @param array $values
- * @return NULL|numeric
- */
- public function execFormulaMedia(array $values = array())
- {
+ // Retorna ao locale anterior
+ $this->getLocale()->setLocale();
- $formula = $this->replaceTokens($this->formulaMedia, $values);
- return $this->_exec($formula);
- }
+ return $replaced;
+ }
- /**
- * Executa um código de fórmula com eval.
- * @param string $code
- * @return NULL|numeric
- */
- protected function _exec($code)
- {
- $result = NULL;
- eval("?>");
- return $result;
- }
+ /**
+ * Troca os tokens de alias pelos usados durante a execução da fórmula.
+ *
+ * @param string $formula
+ *
+ * @return string
+ */
+ public function replaceAliasTokens($formula)
+ {
+ return preg_replace(['/\(/', '/\)/', '/x/'], [' ( ', ' ) ', '*'], $formula);
+ }
- /**
- * @see CoreExt_Entity_Validatable#getDefaultValidatorCollection()
- */
- public function getDefaultValidatorCollection()
- {
- $instituicoes = array_keys(App_Model_IedFinder::getInstituicoes());
- $tipoFormula = FormulaMedia_Model_TipoFormula::getInstance();
+ /**
+ *
+ * @param array $values
+ *
+ * @return float|null
+ */
+ public function execFormulaMedia(array $values = [])
+ {
+ $formula = $this->replaceTokens($this->formulaMedia, $values);
- // Se for de recuperação, inclui a token "Rc" como permitida.
- $formulaValidatorOptions = array();
- if (FormulaMedia_Model_TipoFormula::MEDIA_RECUPERACAO == $this->get('tipoFormula')) {
- $formulaValidatorOptions = array('excludeToken' => NULL);
+ return $this->_exec($formula);
}
- return array(
- 'instituicao' => new CoreExt_Validate_Choice(array('choices' => $instituicoes)),
- 'nome' => new CoreExt_Validate_String(array('min' => 5, 'max' => 50)),
- 'formulaMedia' => new FormulaMedia_Validate_Formula($formulaValidatorOptions),
- 'tipoFormula' => new CoreExt_Validate_Choice(array('choices' => $tipoFormula->getKeys()))
- );
- }
+ /**
+ * @see CoreExt_Entity_Validatable::getDefaultValidatorCollection()
+ *
+ * @return array
+ */
+ public function getDefaultValidatorCollection()
+ {
+ $instituicoes = array_keys(App_Model_IedFinder::getInstituicoes());
+ $tipoFormula = FormulaMedia_Model_TipoFormula::getInstance();
+
+ // Se for de recuperação, inclui o token "Rc" como permitido.
- /**
- * @see CoreExt_Entity#__toString()
- */
- public function __toString()
- {
- return $this->nome;
- }
+ $formulaValidatorOptions = [];
+
+ if (FormulaMedia_Model_TipoFormula::MEDIA_RECUPERACAO == $this->get('tipoFormula')) {
+ $formulaValidatorOptions = ['excludeToken' => null];
+ }
+
+ return [
+ 'instituicao' => new CoreExt_Validate_Choice(['choices' => $instituicoes]),
+ 'nome' => new CoreExt_Validate_String(['min' => 5, 'max' => 50]),
+ 'formulaMedia' => new FormulaMedia_Validate_Formula($formulaValidatorOptions),
+ 'tipoFormula' => new CoreExt_Validate_Choice(['choices' => $tipoFormula->getKeys()])
+ ];
+ }
}
diff --git a/ieducar/modules/FormulaMedia/Model/FormulaDataMapper.php b/ieducar/modules/FormulaMedia/Model/FormulaDataMapper.php
index df9fdac673..e04bd8fd30 100644
--- a/ieducar/modules/FormulaMedia/Model/FormulaDataMapper.php
+++ b/ieducar/modules/FormulaMedia/Model/FormulaDataMapper.php
@@ -1,37 +1,27 @@
- * @category i-Educar
- * @license @@license@@
- * @package FormulaMedia
- * @subpackage Modules
- * @since Classe disponível desde a versão 1.1.0
- * @version @@package_version@@
- */
class FormulaMedia_Model_FormulaDataMapper extends CoreExt_DataMapper
{
protected $_entityClass = 'FormulaMedia_Model_Formula';
- protected $_tableName = 'formula_media';
+
+ protected $_tableName = 'formula_media';
+
protected $_tableSchema = 'modules';
- protected $_attributeMap = array(
- 'id' => 'id',
- 'instituicao' => 'instituicao_id',
- 'nome' => 'nome',
- 'formulaMedia' => 'formula_media',
- 'tipoFormula' => 'tipo_formula',
- 'substituiMenorNotaRc' => 'substitui_menor_nota_rc'
- );
+ protected $_attributeMap = [
+ 'id' => 'id',
+ 'instituicao' => 'instituicao_id',
+ 'nome' => 'nome',
+ 'formulaMedia' => 'formula_media',
+ 'tipoFormula' => 'tipo_formula',
+ 'substituiMenorNotaRc' => 'substitui_menor_nota_rc'
+ ];
- protected $_primaryKey = array(
- 'id' => 'id',
- 'instituicao' => 'instituicao_id'
- );
+ protected $_primaryKey = [
+ 'id' => 'id',
+ 'instituicao' => 'instituicao_id'
+ ];
}
diff --git a/ieducar/modules/FormulaMedia/Model/TipoFormula.php b/ieducar/modules/FormulaMedia/Model/TipoFormula.php
index f406bd950d..185f4f961a 100644
--- a/ieducar/modules/FormulaMedia/Model/TipoFormula.php
+++ b/ieducar/modules/FormulaMedia/Model/TipoFormula.php
@@ -1,59 +1,19 @@
- *
- * Este programa é software livre; você pode redistribuí-lo e/ou modificá-lo
- * sob os termos da Licença Pública Geral GNU conforme publicada pela Free
- * Software Foundation; tanto a versão 2 da Licença, como (a seu critério)
- * qualquer versão posterior.
- *
- * Este programa é distribuído na expectativa de que seja útil, porém, SEM
- * NENHUMA GARANTIA; nem mesmo a garantia implícita de COMERCIABILIDADE OU
- * ADEQUAÇÃO A UMA FINALIDADE ESPECÍFICA. Consulte a Licença Pública Geral
- * do GNU para mais detalhes.
- *
- * Você deve ter recebido uma cópia da Licença Pública Geral do GNU junto
- * com este programa; se não, escreva para a Free Software Foundation, Inc., no
- * endereço 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA.
- *
- * @author Eriksen Costa Paixão