/**
  * Get a result by object and user key
  *
  * @param integer   object id
  * @param integer   user id
  * @param boolean   save a new result object result if not exists
  *
  * @return ExternalContentResult
  */
 public static function getByKeys($a_obj_id, $a_usr_id, $a_create = false)
 {
     global $ilDB;
     $query = 'SELECT * FROM xxco_results' . ' WHERE obj_id = ' . $ilDB->quote($a_obj_id, 'integer') . ' AND usr_id = ' . $ilDB->quote($a_usr_id, 'integer');
     $res = $ilDB->query($query);
     if ($row = $ilDB->fetchAssoc($res)) {
         $resObj = new ilExternalContentResult();
         $resObj->fillData($row);
         return $resObj;
     } elseif ($a_create) {
         $resObj = new ilExternalContentResult();
         $resObj->obj_id = $a_obj_id;
         $resObj->usr_id = $a_usr_id;
         $resObj->result = null;
         $resObj->save();
         return $resObj;
     } else {
         return null;
     }
 }
 /**
  * Delete a stored result
  * @param SimpleXMLElement $request
  */
 protected function deleteResult($request)
 {
     $this->result->result = null;
     $this->result->save();
     require_once $this->plugin_path . '/classes/class.ilExternalContentLPStatus.php';
     $lp_status = ilExternalContentLPStatus::LP_STATUS_IN_PROGRESS_NUM;
     $lp_percentage = 0;
     ilExternalContentLPStatus::trackResult($this->result->usr_id, $this->result->obj_id, $lp_status, $lp_percentage);
     $code = "success";
     $severity = "status";
     $response = $this->loadResponse('deleteResult.xml');
     $response = str_replace('{message_id}', md5(rand(0, 999999999)), $response);
     $response = str_replace('{message_ref_id}', $this->message_ref_id, $response);
     $response = str_replace('{operation}', $this->operation, $response);
     $response = str_replace('{code}', $code, $response);
     $response = str_replace('{severity}', $severity, $response);
     header('Content-type: application/xml');
     echo $response;
 }
 /**
  * fill an ILIAS field
  * @param $a_field
  * @return unknown_type
  */
 private function fillIliasField($a_field)
 {
     global $ilias, $ilUser, $ilSetting, $ilAccess, $ilClientIniFile;
     switch ($a_field['field_name']) {
         // object information
         case "ILIAS_REF_ID":
             $value = $this->getRefId();
             break;
         case "ILIAS_TITLE":
             $value = $this->getTitle();
             break;
         case "ILIAS_DESCRIPTION":
             $value = $this->getDescription();
             break;
         case "ILIAS_INSTRUCTIONS":
             $value = $this->getInstructions();
             break;
             // object context
         // object context
         case "ILIAS_CONTEXT_ID":
             $context = $this->getContext();
             $value = $context['id'];
             break;
         case "ILIAS_CONTEXT_TYPE":
             $context = $this->getContext();
             $value = $context['type'];
             break;
         case "ILIAS_CONTEXT_TITLE":
             $context = $this->getContext();
             $value = $context['title'];
             break;
             // call-time imformation
         // call-time imformation
         case "ID":
             $value = $this->selectID();
             break;
         case "ILIAS_REMOTE_ADDR":
             $value = $_SERVER["REMOTE_ADDR"];
             break;
         case "ILIAS_TIME":
             $value = date('Y-m-d H:i:s', time());
             break;
         case "ILIAS_TIMESTAMP":
             $value = time();
             break;
         case "ILIAS_SESSION_ID":
             $value = session_id();
             break;
         case "ILIAS_TOKEN":
             $value = $this->fillToken($a_field);
             break;
         case "ILIAS_RESULT_ID":
             if ($this->getLPMode() == self::LP_ACTIVE) {
                 $this->plugin->includeClass('class.ilExternalContentResult.php');
                 $result = ilExternalContentResult::getByKeys($this->getId(), $ilUser->getId(), true);
                 $value = $result->id;
             } else {
                 $value = "";
             }
             break;
             // service urls
         // service urls
         case "ILIAS_CALLBACK_URL":
             $value = ILIAS_HTTP_PATH . "/Customizing/global/plugins/Services/Repository/RepositoryObject/ExternalContent/callback.php";
             break;
         case "ILIAS_EVENT_LOG_URL":
             $value = ILIAS_HTTP_PATH . "/Customizing/global/plugins/Services/Repository/RepositoryObject/ExternalContent/event_log.php";
             break;
         case "ILIAS_RETURN_URL":
             $value = $this->getReturnUrl();
             break;
         case "ILIAS_RESULT_URL":
             if ($this->getLPMode() == self::LP_ACTIVE) {
                 $value = ILIAS_HTTP_PATH . "/Customizing/global/plugins/Services/Repository/RepositoryObject/ExternalContent/result.php" . '?client_id=' . CLIENT_ID;
             } else {
                 $value = '';
             }
             break;
             // user information
         // user information
         case "ILIAS_USER_ID":
             $value = $ilUser->getId();
             break;
         case "ILIAS_USER_CODE":
             $value = sha1($ilUser->getId() . $ilUser->getCreateDate());
             break;
         case "ILIAS_USER_LOGIN":
             $value = $ilUser->getLogin();
             break;
         case "ILIAS_USER_FIRSTNAME":
             $value = $ilUser->getFirstname();
             break;
         case "ILIAS_USER_LASTNAME":
             $value = $ilUser->getLastname();
             break;
         case "ILIAS_USER_FULLNAME":
             $value = $ilUser->getFullname();
             break;
         case "ILIAS_USER_EMAIL":
             $value = $ilUser->getEmail();
             break;
         case "ILIAS_USER_IMAGE":
             $value = ILIAS_HTTP_PATH . "/" . $ilUser->getPersonalPicturePath("small");
             break;
         case "ILIAS_USER_LANG":
             $value = $this->lng->getLangKey();
             break;
         case "ILIAS_USER_WRITE_ACCESS":
             $value = $ilAccess->checkAccess('write', '', $this->getRefId()) ? "1" : "0";
             break;
             // platform information
         // platform information
         case "ILIAS_VERSION":
             $value = $ilias->getSetting("ilias_version");
             break;
         case "ILIAS_CONTACT_EMAIL":
             $value = $ilSetting->get("admin_email");
             break;
         case "ILIAS_CLIENT_ID":
             $value = CLIENT_ID;
             break;
         case "ILIAS_HTTP_PATH":
             $value = ILIAS_HTTP_PATH;
             break;
         case "ILIAS_LMS_URL":
             require_once './Services/Link/classes/class.ilLink.php';
             $value = ilLink::_getLink(ROOT_FOLDER_ID, "root");
             break;
         case "ILIAS_LMS_GUID":
             $parsed = parse_url(ILIAS_HTTP_PATH);
             $value = CLIENT_ID . "." . implode(".", array_reverse(explode("/", $parsed["path"]))) . $parsed["host"];
             break;
         case "ILIAS_LMS_NAME":
             if (!($value = $ilSetting->get("short_inst_name"))) {
                 $value = $ilClientIniFile->readVariable('client', 'name');
             }
             break;
         case "ILIAS_LMS_DESCRIPTION":
             require_once "Modules/SystemFolder/classes/class.ilObjSystemFolder.php";
             if (!($value = ilObjSystemFolder::_getHeaderTitle())) {
                 $value = $ilClientIniFile->readVariable('client', 'description');
             }
             break;
         default:
             $value = "";
             break;
     }
     return $value;
 }