当前位置: 首页>>代码示例>>PHP>>正文


PHP Task::createNew方法代码示例

本文整理汇总了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;
 }
开发者ID:rogerapras,项目名称:invoice-ninja,代码行数:33,代码来源:TaskRepository.php

示例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;
 }
开发者ID:ricoa,项目名称:invoice-ninja,代码行数:49,代码来源:TaskRepository.php

示例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;
 }
开发者ID:hillelcoren,项目名称:invoice-ninja,代码行数:46,代码来源:TaskRepository.php


注:本文中的app\models\Task::createNew方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。