나는 이것을하기에 가장 좋은 방법을 찾으려 고 노력하면서 원을 돌고 있습니다. 너무 어려워 야한다고 생각하지 않지만 그런 식으로 만들고 있습니다! 내 사이트에서 회원이 데이터를 제공 할 때마다 해당 회원의 항목에 대해 저장합니다. 한 달에 한 번씩 연속적으로 데이터를 제출하는 회원에게는 어떤 단계에서 보상이 주어질 것이라는 아이디어가 있습니다. 그러나 일부 매개 변수가 있습니다. 마지막 방문 후 21 일 이내에 사이트로 돌아온 회원에게는 새 항목으로 계산되지 않지만 이전 항목과 동일한 항목 기간에 대해서는 다른 항목으로 계산됩니다. 마찬가지로 회원이 마지막 입국 일로부터 49 일 이상 사이트로 돌아 오면 입장 번호는 연속되지 않고 2 점씩 증가하여 항목간에 휴식을 표시합니다. 정확한 시간 내에 데이터를 채우는 회원간에 구별이 가능하도록하기 위해 내가 생각해 왔던 것입니다. 모든 것이 의미가 있기를 바랍니다.PHP/OOP 도움말 - 논리 및 디자인 문제
내 코드/디자인 문제에 대해서는 누구나 내 코드를 개선하는 데 도움이 될 수 있으며 시간 측정에 추가하는 것이 가장 좋습니다. 이것은 내 모델입니다. 그래서 항목을 관리하여 정확한 항목을 반환합니다 (즉, 새 항목 - 마지막 항목이 하나 또는 두 개씩 증가하거나 현재 기간의 항목이 이미 증가됨) .
모든 포인터가 정말 감사하겠습니다!
//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();
}**