【发布时间】:2011-03-07 05:34:15
【问题描述】:
我正在兜圈子,试图找出如何最好地做到这一点,我认为这应该不会太难,但我正在这样做!在我的站点中,每次成员提供一些数据时,我都会将其存储在该成员的条目中。这个想法是,每月连续提交数据的成员将在某个阶段获得奖励。但是有一些参数:在上次访问后 21 天内返回站点的成员不会将其视为新条目,而只是在与前一个条目相同的条目期间再次提交。同样,如果会员在最后一个条目日期后超过 49 天返回网站,则条目编号将不是连续的,而是将增加 2,显示条目之间的中断。这就是我想出的方法,以便区分在正确时间范围内填写数据的成员 - 希望这一切都有意义!
对于我的代码/设计问题,谁能帮我在这里改进我的代码以及如何最好地添加时间框架检查?这是我的模型,我正在尝试管理条目,以便它返回正确的条目(即一个新条目 - 将最后一个增加一或两个,或者当前期间已经存在的条目) .
任何指针将不胜感激!
//example call from a controller after successful form submission - $this->entry is then passed around for use within that session
$this->entry = $this->pet->update_entry('pet/profile/2');
public function update_entry($stage = NULL)
{
//get last number entered for this pet
$last_entry = $this->last_entry();
//if part one, pet profile is calling the update (passing the next stage as a param)
if ($stage === 'pet/profile/2')
{
//only at this stage do we ever create a new entry
$entry = ORM::factory('data_entry');
//if no previous sessions, start from 1
if ($last_entry === FALSE)
$num = 1;
//here we need to check the time period elapsed since the last submission, still to be ironed out
//for now just increment each time, but this may change
else
$num = $last_entry->number + 1;
//save the rest of the data for a new entry
$entry->number = $num;
$entry->initiated = time();
$entry->updated = time();
$entry->last_category_reached = $stage;
$entry->pet_id = $this->id;
$entry->save();
}
elseif ($stage !== NULL)
{
//echo $stage; correctly prints out stage
//this must be a continuation of a form, not the beginning of a new one
//timeframe checks to be added here
//just update the stage reached and save
$last_entry->last_category_reached = $stage;
$last_entry->updated = time();
$last_entry->save();
//assign to $entry for return
$entry = $last_entry;
}
return $entry;
}
/**
*
* Returns the the last data entry session
*/
public function last_entry()
{
return $this
->limit(1)
->data_entries
->current();
}**
【问题讨论】:
标签: php model-view-controller oop