Exemplo n.º 1
0
 /**
  * Add table values. Exspects a 2-dimension array. Column indeces of second dimensions in first row are column names.
  *
  * e.g. array (array("first" => "val1_1", "second" => "val1_2), array ("first" => "val2_1", "second" => "val2_2"))
  * results in Table   first       second
  *                    val1_1      va11_2
  *                    val2_1      val2_2
  *
  * @param array $array 2 dimensional array
  * @param boolean $overwrite if false, column names won't be changed, rows will be added,true: result set will be reset to null and data will be added.
  */
 function addArray($array, $overwrite = false)
 {
     if ($overwrite) {
         $this->clear();
     }
     foreach ($array as $row) {
         if ($overwrite) {
             // add column names from first row
             $columnNames = array_keys($row);
             foreach ($columnNames as $columnName) {
                 $this->addColumn($columnName);
             }
             $overwrite = false;
         }
         $xmlRow = new ilXMLResultSetRow();
         $xmlRow->setValues($row);
         $this->addRow($xmlRow);
     }
 }
 /**
  * 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();
 }
 /**
  * get results of test
  *
  * @param string $sid
  * @param int $test_ref_id
  * @param boolean $sum_only
  *
  * @return XMLResultSet with columns 
  * 	sum only = true: user_id, login, firstname, lastname, matriculation, maximum points, received points
  *  sum only = false: user_id, login, firstname, lastname, matriculation, question id, question title, question points, received points
  */
 function getTestResults($sid, $test_ref_id, $sum_only)
 {
     $this->initAuth($sid);
     $this->initIlias();
     if (!$this->__checkSession($sid)) {
         return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
     }
     if (!strlen($test_ref_id)) {
         return $this->__raiseError('No test id given. Aborting!', 'Client');
     }
     global $rbacsystem, $tree, $ilLog;
     if (ilObject::_isInTrash($test_ref_id)) {
         return $this->__raiseError('Test is trashed. Aborting!', 'Client');
     }
     // get obj_id
     if (!($obj_id = ilObject::_lookupObjectId($test_ref_id))) {
         return $this->__raiseError('No test found for id: ' . $test_ref_id, 'Client');
     }
     // Check access
     $permission_ok = false;
     foreach ($ref_ids = ilObject::_getAllReferences($obj_id) as $ref_id) {
         if ($rbacsystem->checkAccess('write', $ref_id)) {
             $permission_ok = true;
             break;
         }
     }
     if (!$permission_ok) {
         return $this->__raiseError('No permission to edit the object with id: ' . $test_ref_id, 'Server');
     }
     // store into xml result set
     include_once './webservice/soap/classes/class.ilXMLResultSet.php';
     include_once './webservice/soap/classes/class.ilXMLResultSetWriter.php';
     $xmlResultSet = new ilXMLResultSet();
     $xmlResultSet->addColumn("user_id");
     $xmlResultSet->addColumn("login");
     $xmlResultSet->addColumn("firstname");
     $xmlResultSet->addColumn("lastname");
     $xmlResultSet->addColumn("matriculation");
     include_once './Modules/Test/classes/class.ilObjTest.php';
     $test_obj = new ilObjTest($obj_id, false);
     $participants = $test_obj->getTestParticipants();
     if ($sum_only) {
         $data = $test_obj->getAllTestResults($participants, false);
         // create xml
         $xmlResultSet->addColumn("maximum_points");
         $xmlResultSet->addColumn("received_points");
         // skip titles
         $titles = array_shift($data);
         foreach ($data as $row) {
             $xmlRow = new ilXMLResultSetRow();
             $xmlRow->setValue(0, $row["user_id"]);
             $xmlRow->setValue(1, $row["login"]);
             $xmlRow->setValue(2, $row["firstname"]);
             $xmlRow->setValue(3, $row["lastname"]);
             $xmlRow->setValue(4, $row["matriculation"]);
             $xmlRow->setValue(5, $row["max_points"]);
             $xmlRow->setValue(6, $row["reached_points"]);
             $xmlResultSet->addRow($xmlRow);
         }
     } else {
         $data = $test_obj->getDetailedTestResults($participants);
         // create xml
         $xmlResultSet->addColumn("question_id");
         $xmlResultSet->addColumn("question_title");
         $xmlResultSet->addColumn("maximum_points");
         $xmlResultSet->addColumn("received_points");
         foreach ($data as $row) {
             $xmlRow = new ilXMLResultSetRow();
             $xmlRow->setValue(0, $row["user_id"]);
             $xmlRow->setValue(1, $row["login"]);
             $xmlRow->setValue(2, $row["firstname"]);
             $xmlRow->setValue(3, $row["lastname"]);
             $xmlRow->setValue(4, $row["matriculation"]);
             $xmlRow->setValue(5, $row["question_id"]);
             $xmlRow->setValue(6, $row["question_title"]);
             $xmlRow->setValue(7, $row["max_points"]);
             $xmlRow->setValue(8, $row["reached_points"]);
             $xmlResultSet->addRow($xmlRow);
         }
     }
     // create writer
     $xmlWriter = new ilXMLResultSetWriter($xmlResultSet);
     $xmlWriter->start();
     return $xmlWriter->getXML();
 }
 /**
  * return user  mapping as xml
  *
  * @param array (user_id => login) $a_array
  * @return XML String, following resultset.dtd
  */
 function __getUserMappingAsXML($a_array)
 {
     include_once './webservice/soap/classes/class.ilXMLResultSet.php';
     include_once './webservice/soap/classes/class.ilXMLResultSetWriter.php';
     $xmlResultSet = new ilXMLResultSet();
     $xmlResultSet->addColumn("userid");
     $xmlResultSet->addColumn("login");
     $xmlResultSet->addColumn("action");
     $xmlResultSet->addColumn("message");
     if (count($a_array)) {
         foreach ($a_array as $username => $message) {
             $xmlRow = new ilXMLResultSetRow();
             $xmlRow->setValue(0, $username);
             $xmlRow->setValue(1, $message["login"]);
             $xmlRow->setValue(2, $message["action"]);
             $xmlRow->setValue(3, $message["message"]);
             $xmlResultSet->addRow($xmlRow);
         }
     }
     $xml_writer = new ilXMLResultSetWriter($xmlResultSet);
     if ($xml_writer->start()) {
         return $xml_writer->getXML();
     }
     return $this->__raiseError('Error in __getUserMappingAsXML', 'Server');
 }