Last active
December 12, 2015 09:49
-
-
Save henrystivens/4754598 to your computer and use it in GitHub Desktop.
Inicialmente para que funcione en form.php, en línea 93 añadir: if ($value !== null && $filter) { if(is_array($value) === FALSE){ $value = htmlspecialchars($value, ENT_COMPAT, APP_CHARSET); }
} //Se debe mejorar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* KumbiaPHP web & app Framework | |
* | |
* LICENSE | |
* | |
* This source file is subject to the new BSD license that is bundled | |
* with this package in the file LICENSE.txt. | |
* It is also available through the world-wide-web at this URL: | |
* http://wiki.kumbiaphp.com/Licencia | |
* If you did not receive a copy of the license and are unable to | |
* obtain it through the world-wide-web, please send an email | |
* to license@kumbiaphp.com so we can send you a copy immediately. | |
* | |
* @category KumbiaPHP | |
* @package Helpers | |
* @copyright Copyright (c) 2005-2012 KumbiaPHP Team (http://www.kumbiaphp.com) | |
* @license http://wiki.kumbiaphp.com/Licencia New BSD License | |
*/ | |
/** | |
* Helper para Formularios | |
* | |
* @category KumbiaPHP | |
* @package Helpers | |
*/ | |
class Form2 extends Form { | |
/** | |
* Crea campos check que toma los valores de un array de objetos | |
* | |
* @param string $field Nombre de campo | |
* @param string $show Campo que se mostrara (opcional) | |
* @param array $data Array('modelo','metodo','param') (opcional) | |
* @param string|array $attrs Atributos de campo (opcional) | |
* @param string|array $value (opcional) Array en select multiple | |
* @return string | |
*/ | |
public static function dbCheck($field, $show = NULL, $data = NULL, $attrs = NULL, $value = NULL) { | |
if (is_array($attrs)) { | |
$attrs = Tag::getAttrs($attrs); | |
} | |
// Obtiene name, id y value (solo para autoload) para el campo y los carga en el scope | |
extract(self::getFieldData($field, $value), EXTR_OVERWRITE); | |
$checks = ''; | |
//por defecto el modelo de modelo(_id) | |
if ($data === NULL) { | |
$model_asoc = explode('.', $field, 2); | |
$model_asoc = substr(end($model_asoc), 0); //No se elimina el _id, porque no debe venir | |
$model_asoc = Load::model($model_asoc); | |
$pk = $model_asoc->primary_key[0]; | |
if (!$show) { | |
//por defecto el primer campo no pk | |
$show = $model_asoc->non_primary[0]; | |
} | |
$data = $model_asoc->find("columns: $pk,$show", "order: $show asc"); //mejor usar array | |
} else { | |
$model_asoc = Load::model($data[0]); | |
$pk = $model_asoc->primary_key[0]; | |
// Verifica si existe el parámetro | |
if (isset($data[2])) { | |
$data = $model_asoc->$data[1]($data[2]); | |
} else { | |
$data = $model_asoc->$data[1](); | |
} | |
} | |
$i = 1; | |
$j = 4; | |
foreach ($data as $p) { | |
$checks .= "<label class=\"checkbox\">"; | |
$checks .= Form::check($id . '[]', $p->$pk); | |
$checks .= htmlspecialchars($p->$show, ENT_COMPAT, APP_CHARSET) . '</label>' . PHP_EOL; | |
/*if($i==1){ | |
$checks .= '<div class="row-fluid">'. PHP_EOL; | |
} | |
$checks .= '<div class="span3">'. PHP_EOL; | |
$idx = $id . '_' . $p->$pk; | |
$namex = $id . '[]'; | |
$checks .= "<label class=\"checkbox\"><input id=\"$idx\" name=\"$namex\" type=\"checkbox\" value=\"{$p->$pk}\""; | |
// Si es array $value para select multiple se seleccionan todos | |
//var_dump($value); die(); | |
$checked = ''; | |
if (is_array($value)) { | |
if (in_array($p->$pk, $value)) { | |
$checks .= ' checked="checked"'; | |
} | |
} else { | |
if ($p->$pk == $value) { | |
$checks .= ' checked="checked"'; | |
} | |
} | |
$checks .= " $attrs>" . htmlspecialchars($p->$show, ENT_COMPAT, APP_CHARSET) . '</label>' . PHP_EOL; | |
$checks .= '</div>'. PHP_EOL; | |
if($i===$j){ | |
$checks .= '</div>'. PHP_EOL; | |
$i=0; | |
} | |
$i++;*/ | |
} | |
/*if($i !== 1){ | |
$checks .= '</div>'. PHP_EOL; | |
}*/ | |
return $checks . PHP_EOL; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment