I had the same problem but here is something like you want:
---
--Licitations
CREATE TABLE `licitaciones` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `codigo` varchar(50) collate latin1_general_ci NOT NULL,
  `nombre` varchar(50) collate latin1_general_ci NOT NULL,
  `descripcion` text collate latin1_general_ci NOT NULL,
  `fecha` datetime NOT NULL,
  `fecha_fin` datetime NOT NULL,
  `publicar` tinyint(1) NOT NULL default '0',
  PRIMARY KEY  (`id`),
  UNIQUE KEY `codigo_index` (`codigo`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci
AUTO_INCREMENT=2 ;

-- --------------------------------------------------------
--where you store the type of coin $us, Euro
CREATE TABLE `monedas` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `nombre` varchar(20) collate latin1_general_ci NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci
AUTO_INCREMENT=4 ;

-- --------------------------------------------------------
--
--Users table
--

CREATE TABLE `usuarios` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `nombre` varchar(50) collate latin1_general_ci NOT NULL,
  `login` varchar(16) collate latin1_general_ci NOT NULL,
  `pass` varchar(32) collate latin1_general_ci NOT NULL,
  `direccion` varchar(200) collate latin1_general_ci default NULL,
  `telefono` varchar(16) collate latin1_general_ci default NULL,
  `telefono2` varchar(16) collate latin1_general_ci default NULL,
  `email` varchar(100) collate latin1_general_ci default NULL,
  `web` varchar(50) collate latin1_general_ci default NULL,
  `descripcion` text collate latin1_general_ci,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `login_index` (`login`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci
AUTO_INCREMENT=2 ;

-- --------------------------------------------------------

--
-- the join table for licitaciones and usuarios
--

CREATE TABLE `usuarios_licitaciones` (
  `usuario_id` int(10) unsigned NOT NULL,
  `fecha` datetime NOT NULL,
  `licitacione_id` int(10) unsigned NOT NULL,
  `moneda_id` int(10) unsigned NOT NULL,
  `valor` decimal(12,2) NOT NULL,
  `descripcion` text collate latin1_general_ci,
  PRIMARY KEY  (`usuario_id`,`fecha`,`licitacione_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;


//All about Licitaciones
/////////////////////////////////////////////
//Model

class Licitacione extends AppModel {
        var $name = 'Licitacione';
        var $displayField = 'nombre';
        var $hasAndBelongsToMany = array('Usuario'=>
                                                                
array('className'=>'Usuario',
                                                                        
'joinTable'=>'usuarios_licitaciones',
                                                                        
'foreingKey'=>'licitacion_id'
                                                                         ));
}

//Controller
class LicitacionesController extends AppController {
        var $scaffold;
}


///////////////////////////////////
//All about moneda
//Model
class Moneda extends AppModel {
        var $name = 'Moneda';
        var $hasMany = array('Oferta'=>array(
                                        'className'=>'Oferta',
                                        'foreignKey'=>'moneda_id'));
        var $displayField = 'nombre';
}

//controller
class MonedasController extends AppController {
        var $scaffold;
}

///////////////////////////////////////////
//All About usuarios
//Model
class Usuario extends AppModel {
        var $name = 'Usuario';
        var $displayField = 'nombre';
        var $hasAndBelongsToMany = array('Licitacione'=>
                                                                
array('className'=>'Licitacione',
                                                                        
'joinTable'=>'usuarios_licitaciones',
                                                                        
'foreingKey'=>'usuario_id'));
        var $validate = array('nombre'=>VALID_NOT_EMPTY);
}

//Controller
class UsuariosController extends AppController {
        var $name = 'Usuarios';
        function login() {
                if(!empty($this->data)) {
                        $user =
$this->Usuario->findBylogin($this->params['data']['Usuario']['login']);
                        
if($user['Usuario']['pass']==$this->params['data']['Usuario']['pass'])
{
                                
$this->Session->write('user',$this->params['data']['Usuario']['login']);
                                
$this->Session->write('usuario_id',$user['Usuario']['id']);
                                $this->redirect('ofertas');
                        }
                }
        }

        function index() {
                $this->set('usuarios',$this->Usuario->findAll());
        }

        function add() {
                if(!empty($this->data)) {
                        $this->Usuario->Save($this->params['data']);
                        $this->redirect('usuarios');
                }
        }

        function edit($id = null) {

                if($id==null) $id = $this->params['data']['Usuario']['id'];


                $this->set('data', $this->Usuario->findByid($id));


                if(empty($this->params['data'])) {
                        $this->params['data'] = $this->Usuario->read();
                }else {
                        if($this->Usuario->save($this->params['data'])) {
                                //return $this->Usuario->flash("Se Edito 
Correctamente los Datos");
                                $this->redirect('usuarios');
                        }
                }
        }
        //$this->checkSession();
}
//
//usuarios views
//////////
//Add
<h1>Adicion de Nuevos Usuarios</h1>
<?php echo $html->formTag('add');?>
<table>
<tr><td><label>Nombre:</label></td><td><?php echo
$html->input('Usuario/nombre') ?></td></tr>
<tr><td><label>Login:</label></td><td><?php echo
$html->input('Usuario/login') ?></td></tr>
<tr><td><label>Pass:</label></td><td><?php echo
$html->input('Usuario/pass') ?></td></tr>
<tr><td><label>Dirección:</label></td><td><?php echo
$html->textarea('Usuario/direccion') ?></td></tr>
<tr><td><label>Telefono:</label></td><td><?php echo
$html->input('Usuario/telefono') ?></td></tr>
<tr><td><label>Email:</label></td><td><?php echo
$html->input('Usuario/email') ?></td></tr>
<tr><td><label>Web:</label></td><td><?php echo
$html->input('Usuario/web') ?></td></tr>
<tr><td><label>Descripcion:</label></td><td><?php echo
$html->textarea('Usuario/descripcion') ?></td></tr>
<tr><td colspan="2" align="center">
<?php echo
$html->input('Usuario/Ingresar',array('type'=>'submit','value'=>'Ingresar'));
?>
</td></tr>
</table>
</form>

//Edit
<h1>Edición de Usuarios</h1>
<h2>Editando <?php echo $data['Usuario']['nombre']?></h2>
<?php echo $html->formTag('/usuarios/edit/');?>
<?php echo $html->hidden('Usuario/id');?>
<table>
<tr><td><label for="data[Usuario][nombre]">Nombre:</label></td>
<td><?php echo $html->input('Usuario/nombre'); ?></td></tr>
<tr><td><label>Login:</label></td>
<td><?php echo $html->input('Usuario/login'); ?></td></tr>
<tr><td><label>Pass:</label></td>
<td><?php echo $html->input('Usuario/pass'); ?></td></tr>
<tr><td><label>Dirección:</label></td>
<td><?php echo $html->textarea('Usuario/direccion',array('cols'=>35));
?></td></tr>
<tr><td><label>Telefono:</label></td>
<td><?php echo $html->input('Usuario/telefono'); ?></td></tr>
<tr><td><label>Email:</label></td>
<td><?php echo $html->input('Usuario/email',array('size'=>35));
?></td></tr>
<tr><td><label>Web:</label></td>
<td><?php echo $html->input('Usuario/web',array('size'=>35));
?></td></tr>
<tr><td><label>Descripcion:</label></td>
<td><?php echo $html->textarea('Usuario/descripcion',array('cols'=>35))
?></td></tr>
<tr><td colspan="2" align="center">
<?php echo
$html->input('Usuario/Ingresar',array('type'=>'submit','value'=>'Ingresar'));
?>
</td></tr>
</table>
</form>

//Index
<h1>Usuarios</h1>

<h2>Lista de Usuarios</h2>
<h3><?php echo $html->link('Adicionar Usuario','add');?></h3>
<table>
<tr>
<th>Nombre</th>
<th>Login</th>
<th>Telefono</th>
<th>Email</th>
<th>Web</th>
<th>&nbsp;</th>
</tr>
<?php foreach($usuarios as $v):?>
<tr>
<td><?php echo $v['Usuario']['nombre'];?></td>
<td><?php echo $v['Usuario']['login'];?></td>
<td><?php echo $v['Usuario']['telefono'];?></td>
<td><?php echo $v['Usuario']['email'];?></td>
<td><?php echo $v['Usuario']['web'];?></td>
<td><small><?php echo
$html->link('editar',"edit/{$v['Usuario']['id']}"); ?></small></td>
</tr>
<?php endforeach; //print_r($_SESSION)?>
</table>

//login
<h2>Login y Contraseña</h2>
<?php echo $html->formTag('login')?>
<table>
<tr><td><label>Usuario: </label></td><td><?php echo
$html->input('Usuario/login')?></td></tr>
<tr><td><label>Contraseña:</label></td><td><?php echo
$html->password('Usuario/pass')?></td></tr>
<tr><td colspan="2"><?php echo $html->submit('Ingresar')?></td></tr>
</table>
</form>

/****************************************************
This might be the most important part for you (Ofertas) it uses the
table usuarios_licitaciones
/****************************************************
*/

//Model

class Oferta extends AppModel {
        //Checks if the user has logged in but you wont need to understand
this part
var $beforeFilter = array('checkSession');
        var $useTable = 'usuarios_licitaciones';
}

/**This is the most important part I think
//controller
class OfertasController extends AppController {
        var $uses = array('Oferta','Licitacione','Moneda','Usuario');
        var $beforeFilter = array('checkSession');

        function index() {
                //Ofertas
                $sql = "select l.codigo, l.id, l.nombre,
date_format(o.fecha,'%d-%m-%Y %H:%i') as fecha, o.valor,
                u.nombre as usuario, l.nombre as licitacion
                 from usuarios_licitaciones as o, usuarios u,
                licitaciones l where u.id=o.usuario_id and l.id=o.licitacione_id
                and u.login='{$_SESSION['user']}'";
                $this->set('ofertas',$this->Oferta->query($sql));
                //Licitaciones
                $sql = "select id, codigo, nombre, descripcion,
date_format(fecha,'%d-%m-%Y %H:%i') as fecha,
                date_format(fecha_fin,'%d-%m-%Y %H:%i') as fecha_fin
                 from licitaciones l where fecha_fin>now() and l.publicar=1";
                $this->set('licitaciones',$this->Oferta->query($sql));
        }

        function add($id=null) {
                if($id == null ) $id =
$this->params['data']['Oferta']['licitacione_id'];
                else $this->params['data']['Oferta']['licitacione_id'] = $id;

                $this->set('oferta',$this->Licitacione->findByid($id));
                $this->set('moneda', $this->Moneda->generateList());

                if(empty($this->params['data']['Oferta']['valor']) ) {
                        $this->params['data']['Oferta']['moneda_id'] = 1;
                }else {
                        $this->params['data']['Oferta']['usuario_id'] =
$_SESSION['usuario_id'];
                        $this->params['data']['Oferta']['fecha'] = date('Y-m-d 
H:i:s');
                        if($this->Oferta->save($this->params['data'])) {
                                $this->redirect('/ofertas');
                        }
                }
        }

        function edit() {
                $sql = "select * from ";
        }
}
/////////////////////
//Views

//Add
<h1>Adicionar Oferta</h1>
<h2>Datos Licitación</h2>
<table style="width:400px">
<tr><td>Código: </td><td><?php echo
$oferta['Licitacione']['codigo']?></td></tr>
<tr><td>Descripción: </td><td><?php echo
$oferta['Licitacione']['descripcion'] ?></td></tr>
<tr><td>Plazo: </td><td><?php echo $oferta['Licitacione']['fecha_fin']
?></td></tr>
</table>
<?php echo $html->formTag('/ofertas/add/');
echo $html->hidden('Oferta/licitacione_id');
?>
<h2></h2>
<table>
<tr><td>Valor:</td><td>

<?php echo $html->input('Oferta/valor',array('size'=>10));?></td>
<td>Moneda:</td><td><?php echo
$html->selectTag('Oferta/moneda_id',$moneda);?></td>
</td></tr>
<tr><td>Descripción:</td>
        <td colspan="3"><?php echo
$html->textarea('Oferta/descripcion',array('cols'=>35))?></td>
</tr>
<tr><td colspan="4"><?php echo $html->submit('Ingresar')?></td></tr>
</table>
</form>

//Index
<h1>Licitaciones Y Ofertas</h1>
<h2>Ultimas Ofertas Realizadas</h2>
<table>
<tr>
<th>Código</th>
<th>Licitacion</th>
<th>Empresa</th>
<th>Oferta</th><th>Fecha</th>
<?php foreach ($ofertas as $v):?>
<tr>

        <td><?php echo $v['l']['codigo'] ?></td>
        <td><?php echo $v['l']['licitacion'] ?></td>
        <td><?php echo $v['u']['usuario'] ?></td>
        <td><?php echo $v['o']['valor'] ?></td>
        <td><?php echo $v[0]['fecha'] ?></td>
</tr>
<?php endforeach;?>
</table>
<h2>Ultimas Licitaciones Publicadas</h2>
<table>
<tr>

<th>Código</th>
<th>Nombre</th><th>descripción</th>
<th>Fecha</th>
<th>Plazo</th>
<th>&nbsp;</th>
</tr>
<?php foreach ($licitaciones as $v):?>
<tr>
        <td><?php echo $v['l']['codigo'] ?></td>
        <td><?php echo $v['l']['nombre'] ?></td>

        <td><?php echo $v['l']['descripcion'] ?></td>
        <td><?php echo $v[0]['fecha'] ?></td>
        <td><?php echo $v[0]['fecha_fin'] ?></td>
        <td><small><?php echo
$html->link('ingresar',"add/{$v['l']['id']}");?></small></td>
</tr>
<?php endforeach; //print_r($licitaciones)?>
</table>

I hope this helps it is not finished yet but the table that joins a
many to many relationship is  used to store other the relation data and
a value, fecha ( or date that is part of the id of this table). This
application when fished it is supposed that it will make auction for
licitaciones (licitations).


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---

Reply via email to