I must check the current value of a timestamp field and do the following:
a) if the value < NOW(), then I must perform DATE_ADD(NOW(), INTERVAL 30 DAY)
but if the field is > NOW(), then I must perform DATE_ADD(VIP_UNTIL, INTERVAL 30 DAY), where VIP_UNTIL is the timestamp fields I am talking about.
I've developed the following code so far, but it doesn't work properly without any errors appearing:
$users=users::model()->findByPK(Yii::app()->user->getState("USER_ID"));
if($users->VIP_UNTIL < new CDbExpression("NOW()")){
$users->VIP_UNTIL = new CDbExpression("DATE_ADD(NOW(), INTERVAL 30 DAY)");
}
else{
$users->VIP_UNTIL = new CDbExpression("DATE_ADD(VIP_UNTIL, INTERVAL 30 DAY)");
}
The problem is that I am not sure this compare method is proper, as well as the expression for the else case. Could you remove my doubts, by referring to a hidden magic Yii feature )?
I could do it with a simple CdbCommand, but I don't want to destroy the nice looking AR code style, without being sure that this is the only approach.
I am using MySQL. I have never used such approach in MySQL, so I'd try to search about something like that. Anyway, if you have any suggestion on this, please share. I will provide my feedback on the implementation with switch.