本文整理汇总了PHP中app\models\Task::createNew方法的典型用法代码示例。如果您正苦于以下问题:PHP Task::createNew方法的具体用法?PHP Task::createNew怎么用?PHP Task::createNew使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Task
的用法示例。
在下文中一共展示了Task::createNew方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save
public function save($publicId, $data)
{
if ($publicId) {
$task = Task::scope($publicId)->firstOrFail();
} else {
$task = Task::createNew();
}
if (isset($data['client']) && $data['client']) {
$task->client_id = Client::getPrivateId($data['client']);
}
if (isset($data['description'])) {
$task->description = trim($data['description']);
}
//$timeLog = $task->time_log ? json_decode($task->time_log, true) : [];
$timeLog = isset($data['time_log']) ? json_decode($data['time_log']) : [];
if ($data['action'] == 'start') {
$task->is_running = true;
$timeLog[] = [strtotime('now'), false];
} else {
if ($data['action'] == 'resume') {
$task->is_running = true;
$timeLog[] = [strtotime('now'), false];
} else {
if ($data['action'] == 'stop' && $task->is_running) {
$timeLog[count($timeLog) - 1][1] = time();
$task->is_running = false;
}
}
}
$task->time_log = json_encode($timeLog);
$task->save();
return $task;
}
示例2: save
public function save($publicId, $data)
{
if ($publicId) {
$task = Task::scope($publicId)->firstOrFail();
} else {
$task = Task::createNew();
}
if (isset($data['client']) && $data['client']) {
$task->client_id = Client::getPrivateId($data['client']);
}
if (isset($data['description'])) {
$task->description = trim($data['description']);
}
$timeLog = $task->time_log ? json_decode($task->time_log, true) : [];
if ($data['action'] == 'start') {
$task->start_time = Carbon::now()->toDateTimeString();
$task->is_running = true;
$timeLog[] = [strtotime('now'), false];
} else {
if ($data['action'] == 'resume') {
$task->break_duration = strtotime('now') - strtotime($task->start_time) + $task->duration;
$task->resume_time = Carbon::now()->toDateTimeString();
$task->is_running = true;
$timeLog[] = [strtotime('now'), false];
} else {
if ($data['action'] == 'stop' && $task->is_running) {
if ($task->resume_time) {
$task->duration = $task->duration + strtotime('now') - strtotime($task->resume_time);
$task->resume_time = null;
} else {
$task->duration = strtotime('now') - strtotime($task->start_time);
}
$timeLog[count($timeLog) - 1][1] = strtotime('now');
$task->is_running = false;
} else {
if ($data['action'] == 'save' && !$task->is_running) {
$task->start_time = $data['start_time'];
$task->duration = $data['duration'];
$task->break_duration = $data['break_duration'];
}
}
}
}
$task->duration = max($task->duration, 0);
$task->break_duration = max($task->break_duration, 0);
$task->time_log = json_encode($timeLog);
$task->save();
return $task;
}
示例3: save
public function save($publicId, $data, $task = null)
{
if ($task) {
// do nothing
} elseif ($publicId) {
$task = Task::scope($publicId)->withTrashed()->firstOrFail();
} else {
$task = Task::createNew();
}
if ($task->is_deleted) {
return $task;
}
if (isset($data['client']) && $data['client']) {
$task->client_id = Client::getPrivateId($data['client']);
}
if (isset($data['description'])) {
$task->description = trim($data['description']);
}
if (isset($data['time_log'])) {
$timeLog = json_decode($data['time_log']);
} elseif ($task->time_log) {
$timeLog = json_decode($task->time_log);
} else {
$timeLog = [];
}
array_multisort($timeLog);
if (isset($data['action'])) {
if ($data['action'] == 'start') {
$task->is_running = true;
$timeLog[] = [strtotime('now'), false];
} else {
if ($data['action'] == 'resume') {
$task->is_running = true;
$timeLog[] = [strtotime('now'), false];
} else {
if ($data['action'] == 'stop' && $task->is_running) {
$timeLog[count($timeLog) - 1][1] = time();
$task->is_running = false;
}
}
}
}
$task->time_log = json_encode($timeLog);
$task->save();
return $task;
}