예제 #1
0
 function exportXML()
 {
     include_once 'Modules/Group/classes/class.ilGroupXMLWriter.php';
     $xml_writer = new ilGroupXMLWriter($this);
     $xml_writer->start();
     $xml = $xml_writer->getXML();
     $name = time() . '__' . $this->ilias->getSetting('inst_id') . '__grp_' . $this->getId();
     $this->__initFileObject();
     $this->file_obj->addGroupDirectory();
     $this->file_obj->addDirectory($name);
     $this->file_obj->writeToFile($xml, $name . '/' . $name . '.xml');
     $this->file_obj->zipFile($name, $name . '.zip');
     $this->file_obj->deleteDirectory($name);
     return true;
 }
 /**
  * get groups which belong to a specific user, fullilling the status
  *
  * @param string $sid
  * @param string $parameters following xmlresultset, columns (user_id, status with values  1 = "MEMBER", 2 = "TUTOR", 4 = "ADMIN", 8 = "OWNER" and any xor operation e.g.  1 + 4 = 5 = ADMIN and TUTOR, 7 = ADMIN and TUTOR and MEMBER)
  * @param string XMLResultSet, columns (ref_id, xml, parent_ref_id) 
  */
 function getGroupsForUser($sid, $parameters)
 {
     $this->initAuth($sid);
     $this->initIlias();
     if (!$this->__checkSession($sid)) {
         return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
     }
     global $rbacreview, $ilObjDataCache, $tree;
     include_once 'webservice/soap/classes/class.ilXMLResultSetParser.php';
     $parser = new ilXMLResultSetParser($parameters);
     try {
         $parser->startParsing();
     } catch (ilSaxParserException $exception) {
         return $this->__raiseError($exception->getMessage(), "Client");
     }
     $xmlResultSet = $parser->getXMLResultSet();
     if (!$xmlResultSet->hasColumn("user_id")) {
         return $this->__raiseError("parameter user_id is missing", "Client");
     }
     if (!$xmlResultSet->hasColumn("status")) {
         return $this->__raiseError("parameter status is missing", "Client");
     }
     $user_id = (int) $xmlResultSet->getValue(0, "user_id");
     $status = (int) $xmlResultSet->getValue(0, "status");
     $ref_ids = array();
     // get roles
     #var_dump($xmlResultSet);
     #echo "uid:".$user_id;
     #echo "status:".$status;
     if (ilSoapGroupAdministration::MEMBER == ($status & ilSoapGroupAdministration::MEMBER) || ilSoapGroupAdministration::ADMIN == ($status & ilSoapGroupAdministration::ADMIN)) {
         foreach ($rbacreview->assignedRoles($user_id) as $role_id) {
             if ($role = ilObjectFactory::getInstanceByObjId($role_id, false)) {
                 #echo $role->getType();
                 if ($role->getType() != "role") {
                     continue;
                 }
                 if ($role->getParent() == ROLE_FOLDER_ID) {
                     continue;
                 }
                 $role_title = $role->getTitle();
                 if ($ref_id = ilUtil::__extractRefId($role_title)) {
                     if (!ilObject::_exists($ref_id, true) || ilObject::_isInTrash($ref_id)) {
                         continue;
                     }
                     #echo $role_title;
                     if (ilSoapGroupAdministration::MEMBER == ($status & ilSoapGroupAdministration::MEMBER) && strpos($role_title, "member") !== false) {
                         $ref_ids[] = $ref_id;
                     } elseif (ilSoapGroupAdministration::ADMIN == ($status & ilSoapGroupAdministration::ADMIN) && strpos($role_title, "admin") !== false) {
                         $ref_ids[] = $ref_id;
                     }
                 }
             }
         }
     }
     if (($status & ilSoapGroupAdministration::OWNER) == ilSoapGroupAdministration::OWNER) {
         $owned_objects = ilObjectFactory::getObjectsForOwner("grp", $user_id);
         foreach ($owned_objects as $obj_id) {
             $allrefs = ilObject::_getAllReferences($obj_id);
             $refs = array();
             foreach ($allrefs as $r) {
                 if ($tree->isDeleted($r)) {
                     continue;
                 }
                 if ($tree->isInTree($r)) {
                     $refs[] = $r;
                 }
             }
             if (count($refs) > 0) {
                 $ref_ids[] = array_pop($refs);
             }
         }
     }
     $ref_ids = array_unique($ref_ids);
     #print_r($ref_ids);
     include_once 'webservice/soap/classes/class.ilXMLResultSetWriter.php';
     include_once 'Modules/Group/classes/class.ilObjGroup.php';
     include_once 'Modules/Group/classes/class.ilGroupXMLWriter.php';
     $xmlResultSet = new ilXMLResultSet();
     $xmlResultSet->addColumn("ref_id");
     $xmlResultSet->addColumn("xml");
     $xmlResultSet->addColumn("parent_ref_id");
     foreach ($ref_ids as $group_id) {
         $group_obj = $this->checkObjectAccess($group_id, "grp", "write", true);
         if ($group_obj instanceof ilObjGroup) {
             $row = new ilXMLResultSetRow();
             $row->setValue("ref_id", $group_id);
             $xmlWriter = new ilGroupXMLWriter($group_obj);
             $xmlWriter->setAttachUsers(false);
             $xmlWriter->start();
             $row->setValue("xml", $xmlWriter->getXML());
             $row->setValue("parent_ref_id", $tree->getParentId($group_id));
             $xmlResultSet->addRow($row);
         }
     }
     $xmlResultSetWriter = new ilXMLResultSetWriter($xmlResultSet);
     $xmlResultSetWriter->start();
     return $xmlResultSetWriter->getXML();
 }