本文整理汇总了PHP中Participant::filterParticipantNames方法的典型用法代码示例。如果您正苦于以下问题:PHP Participant::filterParticipantNames方法的具体用法?PHP Participant::filterParticipantNames怎么用?PHP Participant::filterParticipantNames使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Participant
的用法示例。
在下文中一共展示了Participant::filterParticipantNames方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update
/**
* 更新请求
*
* @param Request $request
* @param int $id
* @return void
*/
public function update(Request $request, $id)
{
// 验证
$this->validate($request, ['topic' => 'string', 'participants' => 'string', 'state' => 'required|in:1,-1', 'reply_message' => 'required|string']);
$log = Comment::find($id);
// 更新
DB::transaction(function () use($request, $log) {
if (Comment::STATUS['ENABLE'] == $request->state) {
// 参与人
$participantIds = [];
$participantNames = Participant::filterParticipantNames($request->participants);
if (!empty($participantNames)) {
foreach ($participantNames as $name) {
$participant = Participant::firstOrCreate(['name' => $name]);
$participant->increment('counts', 1);
$participantIds[] = $participant->id;
}
}
// 节目
$program = Program::where('date', date('Y-m-d', strtotime($log->metas->thread_key)))->first();
$topic = Program::filterTopic($request->topic);
if (!empty($topic)) {
$program->update(['topic' => $topic]);
}
if (!empty($participantIds)) {
$program->participants()->sync($participantIds);
}
}
// 刷新首页文件缓存
Cache::forget(Program::INDEX_CACHE_KEY);
// 刷新贡献记录页文件缓存
Cache::forget(Comment::CONTRIBUTION_CACHE_KEY);
// 记录日志
Comment::where('id', $log->id)->update(['ext_is_agree' => $request->state]);
});
// 回复评论
$state = Comment::replyPost($request->reply_message, $log->metas->thread_id, $log->metas->post_id, $log->metas->author_email);
// 跳转
$status = ['status' => $state ? 'success' : 'error', 'message' => $state ? '审核成功~' : '审核成功,回复失败'];
return Redirect::to($request->_redirect_url)->with($status['status'], $status['message']);
}
示例2: handle
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
// 获取文本路径
$path = $this->argument('path');
if (!is_file($path)) {
return $this->error("Invalid file path {$path}.");
}
// 解析数据
$list = self::decodeText($path);
// 插入数据
foreach ($list as $group) {
DB::transaction(function () use(&$group) {
// 插入声音记录
self::insertAudios($group);
// 插入参与人记录
$data = $group['all'] ?? end($group);
$participantIds = [];
$participantNames = Participant::filterParticipantNames($data['participant']);
foreach ($participantNames as $name) {
$participant = Participant::firstOrCreate(['name' => $name]);
$participant->increment('counts', 1);
$participantIds[] = $participant->id;
}
// 插入节目记录
$topic = Program::filterTopic($data['topic']);
if (empty($group['all'])) {
if (in_array(mb_substr($topic, -1), ['a', 'b', 'c'])) {
$topic = mb_substr($topic, 0, -1);
}
}
$program = Program::firstOrCreate(['date' => $data['date'], 'topic' => $topic, 'state' => Program::STATE_ENABLE]);
if (!empty($participantIds)) {
$program->participants()->sync($participantIds);
}
// 输出日期
$this->info(sprintf("%s\t%s", $data['date'], $topic));
});
}
}