PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 2.10.0
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v2.10.0
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
← All changes | Modules/Course/Model/CourseLesson.php +41 -6 2.8.12.10.0 View file →
@@ -139,21 +139,56 @@
139 139 'document_lists' => [],
140 140 ];
141 141 }
142 142
143 - protected static function generateNewSlug($newModel)
143 + /**
144 + * A lesson slug only has to be unique among the lessons of one course.
145 + *
146 + * A lesson is read at course/{courseSlug}/lessons/{lessonSlug} and
147 + * CourseController::getLessonBySlug() looks it up with a space_id filter, so the
148 + * same slug in two courses never competes. The type global scope keeps this off
149 + * the other row types sharing fcom_posts.
150 + *
151 + * Every write path goes through here - the creating hook below for generated
152 + * slugs, CourseAdminController::patchLesson() for author supplied ones. A
153 + * collision gets a -{time()} suffix.
154 + *
155 + * @param string $slug
156 + * @param int|null $courseId the owning course, fcom_posts.space_id
157 + * @param int|null $ignoreId the lesson being renamed, so it can keep its own slug
158 + * @param string $fallbackTitle used when $slug sanitizes down to nothing
159 + * @return string
160 + */
161 + public static function uniqueSlug($slug, $courseId, $ignoreId = null, $fallbackTitle = '')
144 162 {
145 - $slug = Utility::slugify($newModel->title, 'lesson-' . time());
163 + $slug = sanitize_title($slug);
146 164
147 - // check if the slug is available for this type
148 - $exist = self::where('slug', $slug)
149 - ->exists();
165 + if (!$slug) {
166 + $slug = Utility::slugify($fallbackTitle, 'lesson-' . time());
167 + }
150 168
151 - if ($exist) {
169 + $query = self::where('slug', $slug);
170 +
171 + if ($courseId) {
172 + $query->where('space_id', $courseId);
173 + } else {
174 + $query->whereNull('space_id');
175 + }
176 +
177 + if ($ignoreId) {
178 + $query->where('id', '!=', $ignoreId);
179 + }
180 +
181 + if ($query->exists()) {
152 182 $slug = $slug . '-' . time();
153 183 }
154 184
155 185 return $slug;
186 + }
187 +
188 + protected static function generateNewSlug($newModel)
189 + {
190 + return self::uniqueSlug('', $newModel->space_id, null, $newModel->title);
156 191 }
157 192
158 193 public function topic()
159 194 {