저는 오늘 아침에 자신을 발견 한 까다로운 상황을 처리하는 방법을 알아 내려고하고 있습니다. 내 데이터베이스에 사용자의 월별 항목 (정보 수집 항목)에 대한 세부 정보를 저장하는 항목 테이블이 있습니다. 한 달에 한 번씩 각 항목의 번호 (ID가 아님)를 늘리고 싶습니다. 아이디어는 연속적인 월별 항목을 식별하고 서로 근접한 항목을 무시할 수 있도록 "번호"필드를 사용하는 것입니다.연속적인 데이터 엔트리를 확인하기위한 논리로 애 쓰고 있습니다.
사용자가 새 항목을 시작하기 위해 사이트를 방문하면 완료된 마지막 항목의 날짜를 확인하여 21 일 (유효한 달인 것으로 간주) 이상인지 확인한 다음 "숫자 "이 새로운 항목에 대해. 문제는 내가 21 일 이하의 간격을두고 (따라서 모두 동일한 숫자를 가짐) 일련의 항목으로 끝날 수 있지만 21 일 이상을 종합적으로 나타낼 수 있다는 것입니다. 나는 이것을 처리 할 수있는 논리를 찾을 수 있어야합니다 - 누구든지 아이디어가 있습니까?
이 데이터가 저장되는 방식과 내가 가지고있는 문제의 예는 아래에서 확인할 수 있습니다. 내 PHP는 논리는 다음과 같습니다
+------+--------+------------+------------+----------------------------+
| id | number | initiated | updated | last_category_reached |
+------+--------+------------+------------+----------------------------+
| 4 | 1 | 1277914181 | 1277914320 | complete |
| 105 | 2 | 1282639343 | 1283444717 | complete |
| 397 | 3 | 1284999429 | 1285001298 | complete |
| 404 | 3 | 1287478550 | 1287478631 | complete |
| 636 | 3 | 1287479243 | 1287479377 | complete |
| 649 | 3 | 1287581361 | 1287581466 | complete |
| 652 | 3 | 1287585123 | 1287585365 | complete |
| 656 | 3 | 1290185205 | 1290424128 | complete |
| 1105 | 3 | 1292421193 | 1292426686 | complete |
| 1106 | 3 | 1292426769 | 1292426870 | complete |
+------+--------+------------+------------+----------------------------+
... 나는 의사 코드에 어떻게 할 것인지
public function update_entry($stage = NULL)
{
// Get last number entered for this user
$last_entry = $this->last_entry();
// If part one, user profile is calling the update (passing the next stage as a param)
if ($stage === 'user/profile/2?s=p_prof&p=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
else
{
// Check if time difference between last visit and current time is less than 49 days and more than 21 days
if (($last_entry->initiated > time() - 4233600) && ($last_entry->initiated < time() - 1814400))
{
// Within allowed timeframe, ok to increment by one as a new entry
$num = $last_entry->number + 1;
}
// More than 49 days since last visit
elseif (($last_entry->initiated < time() - 4233600))
{
// Increment by two to break consecutive entries
$num = $last_entry->number + 2;
}
// Entry is within the last 21 days - if user never finished stages, use last entry created instead of creating a new one
else
{
// If they are back at the start having completed a full entry the last time, ok to create a new entry - otherwise use the one created the last time
if ($last_entry->last_category_reached !== 'complete')
$entry = $last_entry;
$num = $last_entry->number;
}
}
// 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->user_id = $this->id;
$entry->save();
}
// If it's been more than 49 days since last part completion of an entry, user won't be given option to finish the entry, so no need for time check here
elseif ($stage !== NULL)
{
// This must be a continuation of a form, not the beginning of a new one
// 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
* @return
*/
public function last_entry()
{
return $this
->limit(1)
->data_entries
->current();
}
4233600으로 타임 스탬프를 늘리면 일광 절약 시간제 변경을 고려하지 않으므로 'time() - (strtotime ('- 49 days '))'와 같은 것을 시도하십시오. – acm
다소 추상적입니다. 올바른 로직은이 애플리케이션에 대한 진정한 비즈니스 요구 사항에 대해 가지고 있지 않은 정보에 달려 있습니다. 원래의 목표와 현재의 계획에 기반한 제안이 요구 사항에 부합하는지 또는 더 멀리 뒤돌아 있는지를 알기 위해 측정 할 수없는 해결책이 잠재적으로 커질 수 있습니다. 내가 생각을 버리라고 강요한다면, 증가하는 숫자를 재사용하는 대신 엔트리 그룹을 고유하게 식별하는 것이 될 것입니다. 최신 항목이 마지막 그룹에 속하는지 여부를 결정하십시오. –
Dan 씨, 당신 말이 맞아요 - 간결하게 설명하기가 어렵습니다! 나는 @LaGrandMere가 내가 현재 가지고있는 것을 기반으로 찾고 있다고 생각한다. – nicky77