[eluser]sn4k3[/eluser]
[quote author="kevinprince" date="1263714952"]Better solution is:
Cache the returned db object in memcache etc
When the object is returned include the expiry time
Use this expiry time to build the view and use frontend code along with validation of the bid method to make sure you cant bid if the expiry based.
If you want you can cache the view and use javascript to evaluate if the auction has closed.[/quote]
Im not understanding very well what that mean
in that part:
Quote:Use this expiry time to build the view and use frontend code along with validation of the bid method to make sure you cant bid if the expiry based.
If you want you can cache the view and use javascript to evaluate if the auction has closed.
i current have that in my view: (Fragment only)
Code:
< script type = "text/javascript" >
var liveids = <?php echo json_encode($this->Auction_model->AuctionsToIds($auctions)); ?>;
function joinArray(ar)
{
var b;
b = ar.join(",");
return(b);
}
function updateAuctions()
{
jQuery.ajax({
type: "POST",
url: base_url+"Api/GetAuctions",
data: ({ ids : '['+joinArray(liveids)+']' }),
timeout: 1000,
/*contentType: "application/json; charset=utf-8",*/
dataType: "json",
success: function(message) {
for (var i in message)
{
var oldcurrentuser = jQuery("#AICurrentuser"+message[i].id).text();
if(message[i].closed == 1){
jQuery("#AICurrenttime"+message[i].id).text('Terminou');
jQuery("#AICurrenttime"+message[i].id).css('color', 'red');
jQuery("#AIBid"+message[i].id).fadeOut('slow');
jQuery.jGrowl('Vencedor: '+message[i].currentuser+'<br />Preço de mercado: <strong>'+message[i].realprice+' €</strong><br />Preço Final: <strong>'+message[i].currentprice+' €</strong><br />Poupou: <strong>'
+message[i].saveprice+' €</strong>',
{ header: 'Leilão #'+message[i].id+' Terminado: '+message[i].name,
sticky: true, glue: 'before', position: 'top-left' });
liveids.splice(i, 1);
}else{
if(message[i].standby == 1)
jQuery("#AICurrenttime"+message[i].id).text('Suspenso');
else
jQuery("#AICurrenttime"+message[i].id).text(message[i].currenttime);
jQuery("#AICurrentprice"+message[i].id).html(message[i].currentprice+' €');
jQuery("#AICurrentuser"+message[i].id).text(message[i].currentuser);
jQuery("#AISeconduser"+message[i].id).text(message[i].seconduser);
jQuery("#AIThirduser"+message[i].id).text(message[i].thirduser);
if(message[i].currentuser == myusername)
jQuery("#AICurrentuser"+message[i].id).css('color', 'red');
else
jQuery("#AICurrentuser"+message[i].id).css('color', '#666');
if(message[i].seconduser == myusername)
{
jQuery("#AISeconduser"+message[i].id).css('color', 'red');
if(message[i].currentuser != myusername && oldcurrentuser == myusername)
jQuery.jGrowl("Um utilizador licitou por cima da sua licitação!<br />Utilizador: <strong>"+message[i].currentuser+"</strong><br /><a >Licitar</a>",
{ header: message.name, life: 7500, glue: 'before' });
}
else
jQuery("#AISeconduser"+message[i].id).css('color', '#666');
if(message[i].thirduser == myusername)
jQuery("#AIThirduser"+message[i].id).css('color', 'red');
else
jQuery("#AIThirduser"+message[i].id).css('color', '#666');
}
}
//jQuery("#cDateHour").text(message.d);
}
});
setTimeout('updateAuctions()',1000);
}
function bidAuction(itemid)
{
jQuery.ajax({
type: "POST",
url: base_url+"Api/BidAuction",
data: ({ id : itemid }),
dataType: "json",
success: function(message) {
if(message == -2) // Error in make changes
jQuery.jGrowl("Erro ao tentar proceder a sua licitação!<br />Se este problema continuar faça refresh à página.", { header: 'Erro', life: 10000, glue: 'before' });
if(message == -1) // Logout
document.location=base_url+'Utilizador/Entrar';
else if(message == 0) // No Bids
document.location=base_url+'Utilizador/Comprar';
else // OK
{
jQuery("#AIBid"+itemid).show('pulsate');
jQuery.jGrowl("A sua licitação foi aceite, fique atento.", { header: message.name, life: 7500, glue: 'before' });
}
}
});
}
jQuery(document).ready(function() {
setTimeout('updateAuctions()',1000);
});
</ script>