Ejemplo n.º 1
0
 function updateQuickEdit_scorm_propagate($request, $type)
 {
     $module_id = $this->md_obj->obj_id;
     if ($this->md_obj->obj_type == 'sco') {
         $module_id = $this->md_obj->rbac_id;
     }
     $tree = new ilTree($module_id);
     $tree->setTableNames('sahs_sc13_tree', 'sahs_sc13_tree_node');
     $tree->setTreeTablePK("slm_id");
     foreach ($tree->getSubTree($tree->getNodeData($tree->getRootId()), true, 'sco') as $sco) {
         $sco_md = new ilMD($module_id, $sco['obj_id'], 'sco');
         if ($_POST[$request] != "") {
             $sco_md_section;
             if (!is_object($sco_md_section = $sco_md->getLifecycle())) {
                 $sco_md_section = $sco_md->addLifecycle();
                 $sco_md_section->save();
             }
             // determine all entered authors
             $auth_arr = explode(",", $_POST[$request]);
             for ($i = 0; $i < count($auth_arr); $i++) {
                 $auth_arr[$i] = trim($auth_arr[$i]);
             }
             $md_con_author = "";
             // update existing author entries (delete if not entered)
             foreach ($ids = $sco_md_section->getContributeIds() as $con_id) {
                 $md_con = $sco_md_section->getContribute($con_id);
                 if ($md_con->getRole() == $type) {
                     foreach ($ent_ids = $md_con->getEntityIds() as $ent_id) {
                         $md_ent = $md_con->getEntity($ent_id);
                         // entered author already exists
                         if (in_array($md_ent->getEntity(), $auth_arr)) {
                             unset($auth_arr[array_search($md_ent->getEntity(), $auth_arr)]);
                         } else {
                             $md_ent->delete();
                         }
                     }
                     $md_con_author = $md_con;
                 }
             }
             // insert enterd, but not existing authors
             if (count($auth_arr) > 0) {
                 if (!is_object($md_con_author)) {
                     $md_con_author = $sco_md_section->addContribute();
                     $md_con_author->setRole($type);
                     $md_con_author->save();
                 }
                 foreach ($auth_arr as $auth) {
                     $md_ent = $md_con_author->addEntity();
                     $md_ent->setEntity(ilUtil::stripSlashes($auth));
                     $md_ent->save();
                 }
             }
         } else {
             if (is_object($sco_md_section = $sco_md->getLifecycle())) {
                 foreach ($ids = $sco_md_section->getContributeIds() as $con_id) {
                     $md_con = $sco_md_section->getContribute($con_id);
                     if ($md_con->getRole() == $type) {
                         $md_con->delete();
                     }
                 }
             }
         }
         $sco_md->update();
     }
     $this->updateQuickEdit_scorm();
 }