*对不起,我不知道怎么问这个问题。例子-
类别名称/分类短名称-1
网站/web-1网站/web-2网站/web-3 android/andr-1
1-如果在类别表上有字段分类名、id、分类代码。
2-假设类别名称是网站,类别代码是WEB。
3-假设任何用户将任务分配给任何其他成员,那么他将选择类别代码(WEB)并分配任务。
4-在分配任务类别后,代码将插入到任务表中。
5之后,如果用户使用类别代码( ANDR)将任务分配给同一用户。
现在,分配任务的用户应该将类别代码视为WEB-1,android任务的类别代码为Andr2。
$tasktime = new Tasktime();
$tasktime->TaskTitle = Input::get('tasktitle');
$tasktime->Description_Task = Input::get('taskdescribe');
$tasktime->Estimated_Time = $case;
$tasktime->Task_Status = Input::get('status');
$tasktime->Priority_Task = Input::get('priority');
$tasktime->Assignee_Id = Input::get('Assignee_Id');
$tasktime->categorycode = Input::get('cateorycode');
$tasktime->Task_DueDate = Input::get('duedate');
$tasktime->Task_created_by = Auth::user()->firstname;
$tasktime->Created_User_Id = Auth::user()->id;
$tasktime->tasktype = Input::get('tasktype');
$tasktime->save();
// send mail to assignee id
$assigneeUser = User::find(Input::get('Assignee_Id'));
Mail::send('emails.send', array('TaskTitle' => Input::get('tasktitle'), 'Priority_Task' => Input::get('priority')), function ($message) use ($assigneeUser) {
$message->to($assigneeUser->email)->subject('verify');
});
return Redirect::to('index')->with('message', 'Email has been sent to assignee related to work');此代码与插入到任务表中的类别代码相关。
如果用户根据类别代码分配任务,我希望按顺序进行分类代码,例如Web1、Web2、Andr1、Web3。
请帮帮我,.i已经尽力解释我的问题了。
发布于 2015-08-13 12:07:34
如果我说得对,你想为website/web-{n}这样的类别自动生成子弹,每个子类别总是从1开始吗?然后:
$table = $tasktime->getTable(); // table with tasks
$category = Input::get('cateorycode');
$max = DB::table($table)
->where('Assignee_Id', Input::get('Assignee_Id'))
->where('categorycode', $category)
->select('count(id) as sub_count')->first();
$max = ($max != null) ? intval($max['sub_count']) : 0;
$max++;
$generatedSlug = "$category-{$max}";
// web-1, web-2, andr-1, web-3
// [] + web = web-1, web-2, andr-1, web-3, web-4
// [] + andr = web-1, web-2, andr-1, web-3, web-4, andr-2未检查代码,可能需要稍作修改。
Upd.
也许,更具可读性的解决方案:
$assignee = Input::get('Assignee_Id');
$category = Input::get('cateorycode');
$max = Tasktime::where('Assignee_Id', $assignee)
->where('categorycode', $category)
->value('count(id)');
$next = (intval($max) ?: 0) + 1;
$generatedSlug = "$category-{$next}";https://stackoverflow.com/questions/31984829
复制相似问题