/** * Load user object. * * @param User $user User object * @return boolean True if the user object was successfully loaded */ public function loadUser($user) { global $DB; $userid = $user->getRecordId(); $fields = 'id, resourcelinkid, ltiuserkey, ltiresultsourcedid, created, updated'; if (!empty($userid)) { $row = $DB->get_record($this->userresulttable, ['id' => $userid], $fields); } else { $resourcelinkid = $user->getResourceLink()->getRecordId(); $userid = $user->getId(ToolProvider\ToolProvider::ID_SCOPE_ID_ONLY); $row = $DB->get_record_select($this->userresulttable, "resourcelinkid = ? AND ltiuserkey = ?", [$resourcelinkid, $userid], $fields); } if ($row) { $user->setRecordId($row->id); $user->setResourceLinkId($row->resourcelinkid); $user->ltiUserId = $row->ltiuserkey; $user->ltiResultSourcedId = $row->ltiresultsourcedid; $user->created = $row->created; $user->updated = $row->updated; return true; } return false; }
/** * Load user object. * * @param User $user User object * * @return boolean True if the user object was successfully loaded */ public function loadUser($user) { $ok = false; if (!empty($user->getRecordId())) { $sql = sprintf('SELECT user_pk, resource_link_pk, lti_user_id, lti_result_sourcedid, created, updated ' . "FROM {$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME . ' ' . 'WHERE (user_pk = %d)', $user->getRecordId()); } else { $sql = sprintf('SELECT user_pk, resource_link_pk, lti_user_id, lti_result_sourcedid, created, updated ' . "FROM {$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME . ' ' . 'WHERE (resource_link_pk = %d) AND (lti_user_id = %s)', $user->getResourceLink()->getRecordId(), DataConnector::quoted($user->getId(ToolProvider\ToolProvider::ID_SCOPE_ID_ONLY))); } $rsUser = mysql_query($sql); if ($rsUser) { $row = mysql_fetch_object($rsUser); if ($row) { $user->setRecordId(intval($row->user_pk)); $user->setResourceLinkId(intval($row->resource_link_pk)); $user->ltiUserId = $row->lti_user_id; $user->ltiResultSourcedId = $row->lti_result_sourcedid; $user->created = strtotime($row->created); $user->updated = strtotime($row->updated); $ok = true; } } return $ok; }
/** * Load user object. * * @param User $user User object * * @return boolean True if the user object was successfully loaded */ public function loadUser($user) { $ok = false; if (!empty($user->getRecordId())) { $id = $user->getRecordId(); $sql = 'SELECT user_pk, resource_link_pk, lti_user_id, lti_result_sourcedid, created, updated ' . "FROM {$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME . ' ' . 'WHERE (user_pk = :id)'; $query = $this->db->prepare($sql); $query->bindValue('id', $id, PDO::PARAM_INT); } else { $id = $user->getResourceLink()->getRecordId(); $uid = $user->getId(ToolProvider\ToolProvider::ID_SCOPE_ID_ONLY); $sql = 'SELECT user_pk, resource_link_pk, lti_user_id, lti_result_sourcedid, created, updated ' . "FROM {$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME . ' ' . 'WHERE (resource_link_pk = :id) AND (lti_user_id = :uid)'; $query = $this->db->prepare($sql); $query->bindValue('id', $id, PDO::PARAM_INT); $query->bindValue('uid', $uid, PDO::PARAM_STR); } if ($query->execute()) { $row = $query->fetch(PDO::FETCH_ASSOC); if ($row !== false) { $row = array_change_key_case($row); $user->setRecordId(intval($row['user_pk'])); $user->setResourceLinkId(intval($row['resource_link_pk'])); $user->ltiUserId = $row['lti_user_id']; $user->ltiResultSourcedId = $row['lti_result_sourcedid']; $user->created = strtotime($row['created']); $user->updated = strtotime($row['updated']); $ok = true; } } return $ok; }