catalogo_id = $data["catalogo_id"];
if ( isset( $data["tipo"])) $this->tipo = $data["tipo"];
if ( isset( $data["nombre"])) $this->nombre = $data["nombre"];
if ( isset( $data["extra"])) $this->extra = $data["extra"];
}
public static function getById( $catalogo_id ) {
$result = ConnectionFactory::getFactory()->getByArray("catalogo", array("catalogo_id"), array($catalogo_id), "Catalogo");
return $result["object"];
}
public static function getAllList($tipo, $extra = null) {
$where = array("tipo = $tipo");
if ($tipo == 3) $where[] = " extra = $extra ";
$result = ConnectionFactory::getFactory()->getList("catalogo", "Catalogo", null, $where, null );
return (array("results" => $result["list"], "totalRows" => $result["totalRows"]));
}
public function delete() {
$result = ConnectionFactory::getFactory()->delete("catalogo", "catalogo_id", $this->catalogo_id);
}
public function validateBeforeInsert(){
$error = false;
if ($this->nombre == '' ) $error[] = 'CATALOGO_ERROR_1';
return $error;
}
public function insert() {
$error = $this->validateBeforeInsert();
$id = "0";
if (!$error){
$fields = array("tipo","nombre","extra");
$result = ConnectionFactory::getFactory()->insert($this, "catalogo", $fields);
if ($result["error"]) $error = array($result["error"]);
$id = $result["id"];
}
return array("error" => $error, "id" => $id);
}
public function update() {
if ( is_null( $this->catalogo_id ) ) trigger_error ( "Update error", E_USER_ERROR );
$error = $this->validateBeforeInsert();
if (!$error){
$fields = array("tipo","nombre","extra");
$error = ConnectionFactory::getFactory()->update($this, "catalogo", $fields, "catalogo_id");
if ($error) $error = array($error);
}
return array("error" => $error, "id" => $this->catalogo_id);
}
public static function getCatalogoSelect($name, $selected, $tipo, $extra = false){
$catalogos = Catalogo::getAllList($tipo, $extra);
$select = '';
return $select;
}
public static function getCatalogoSelectFront($name, $selected, $tipo, $null , $extra = false){
$catalogos = Catalogo::getAllList($tipo, $extra);
$select = '';
return $select;
}
}
?>