private function processSingleModule($moduleRow, $courseId, $possibleOrder = null, $firstItemId = null, &$itemIdsArr = null)
 {
     //check if module exists
     $module = Module::firstOrNew(array('module_id' => $moduleRow->id));
     //('moduleId','=',$module->id);
     $module->module_id = $moduleRow->id;
     $module->course_id = $courseId;
     $module->name = $moduleRow->name;
     //        $module->position = $moduleRow->position;
     $module->unlock_at = $moduleRow->unlock_at;
     $module->require_sequential_progress = $moduleRow->require_sequential_progress;
     $module->publish_final_grade = $moduleRow->publish_final_grade;
     $module->prerequisite_module_ids = implode(", ", $moduleRow->prerequisite_module_ids);
     $module->items_count = $moduleRow->items_count;
     if (isset($moduleRow->published)) {
         $module->published = $moduleRow->published;
     }
     if (isset($moduleRow->state)) {
         $module->state = $moduleRow->state;
     }
     if (isset($moduleRow->items)) {
         //save moduleItems
         $moduleItems = $this->saveModuleItems($moduleRow->items, $courseId, $itemIdsArr);
         $module->module_items = $moduleItems;
     }
     $orderedMod = $this->retrieveOrderedModuleInfo($moduleRow->id, $courseId);
     if ($orderedMod) {
         $module->order = $orderedMod->order;
         $module->parent_id = $orderedMod->parent_id;
     } else {
         if (!is_null($firstItemId)) {
             if ($firstItemId == $moduleRow->id) {
                 $module->parent_id = 1;
             } else {
                 $module->parent_id = $firstItemId;
             }
         }
     }
     $module->save();
     $modArr = $module->toArray();
     $modArr['module_items'] = $module->module_items->toArray();
     return $modArr;
 }
Beispiel #2
0
 public function qualityAssuranceModules($courseId, $currenModuleIdsArr)
 {
     $modules = Module::where('course_id', '=', $courseId)->select('module_id')->get();
     $fromDBArr = array();
     foreach ($modules as $mod) {
         $fromDBArr[] = $mod['module_id'];
     }
     $toBeDeleted = array_diff($fromDBArr, $currenModuleIdsArr);
     foreach ($toBeDeleted as $module) {
         //TODO: verify cascading delete
         Module::where('course_id', '=', $courseId)->where('module_id', '=', intval($module))->delete();
     }
 }