PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 1.0.98
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v1.0.98
2.10.0 2.10.01 2.9.1 2.9.0 2.8.1 2.8.0 2.7.7 2.7.5 2.7.0 2.6.01 2.6.0 2.5.0 2.4.01 trunk 1.0.90 1.0.91 1.0.92 1.0.93 1.0.94 1.0.95 1.0.96 1.0.97 1.0.98 1.0.99 1.1.0 All 77 releases
fluent-community / Modules / Course / Model / Course.php

Course.php in FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses 1.0.98, at Modules/Course/Model/Course.php

101 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCommunity\Modules\Course\Model;
4
5 use FluentCommunity\App\Functions\Utility;
6 use FluentCommunity\App\Models\Activity;
7 use FluentCommunity\App\Models\BaseSpace;
8 use FluentCommunity\App\Models\Meta;
9 use FluentCommunity\App\Models\Term;
10 use FluentCommunity\App\Models\User;
11 use FluentCommunity\Framework\Support\Arr;
12 use FluentCommunity\App\Models\SpaceGroup;
13
14 /**
15 * Course Model - DB Model for Individual Courses
16 *
17 * Database Model
18 *
19 * @package FluentCrm\App\Models
20 *
21 * @version 1.1.0
22 */
23 class Course extends BaseSpace
24 {
25 protected static $type = 'course';
26
27 public static function boot()
28 {
29 parent::boot();
30 }
31
32 public function scopeByAdminAccess($query, $userId = null)
33 {
34 if (!$userId) {
35 $userId = get_current_user_id();
36 }
37
38 $userModel = User::find($userId);
39
40 if ($userModel->isCommunityAdmin()) {
41 return $query;
42 }
43
44 return $this->where('user_id', $userId);
45 }
46
47 public function scopeByPostTopic($query, $topicSlug = null)
48 {
49 if (!$topicSlug) {
50 return $query;
51 }
52
53 $postTpic = Term::where('taxonomy_name', 'post_topic')->where('slug', $topicSlug)->first();
54
55 if (!$postTpic) {
56 return $query;
57 }
58
59 return $query->whereHas('categories', function ($q) use ($postTpic) {
60 $q->where('object_id', $postTpic->id);
61 });
62 }
63
64 public function students()
65 {
66 return $this->belongsToMany(User::class, 'fcom_space_user', 'space_id', 'user_id')
67 ->wherePivot('role', 'student')
68 ->withPivot(['role', 'created_at', 'status']);
69 }
70
71 public function getCompletedStrundesCount()
72 {
73 return Activity::where('feed_id', $this->id)
74 ->where('action_name', 'course_completed')
75 ->count();
76 }
77
78 public function getCourseType()
79 {
80 return Arr::get($this->settings, 'course_type', 'self_paced'); // possible values: slef_paced | scheduled | structured
81 }
82
83 public function group()
84 {
85 return $this->belongsTo(SpaceGroup::class, 'parent_id', 'id');
86 }
87
88 public function categories()
89 {
90 return $this->belongsToMany(Term::class, 'fcom_meta', 'meta_key', 'object_id')
91 ->wherePivot('object_type', 'term_space_relation')
92 ->where('taxonomy_name', 'post_topic');
93 }
94
95 public function syncCategories($categoryIds = [])
96 {
97 $this->syncTopics($categoryIds);
98 return $this;
99 }
100 }
101