public function Resource_Link_getUserResultSourcedIDs($resource_link, $local_only, $id_scope)
 {
     $users = array();
     if ($local_only) {
         $sql = 'SELECT u.consumer_key, u.context_id, u.user_id, u.lti_result_sourcedid ' . 'FROM ' . $this->dbTableNamePrefix . LTI_Data_Connector::USER_TABLE_NAME . ' AS u ' . 'INNER JOIN ' . $this->dbTableNamePrefix . LTI_Data_Connector::RESOURCE_LINK_TABLE_NAME . ' AS c ' . 'ON u.consumer_key = c.consumer_key AND u.context_id = c.context_id ' . 'WHERE (c.consumer_key = :key) AND (c.context_id = :id) AND (c.primary_consumer_key IS NULL) AND (c.primary_context_id IS NULL)';
     } else {
         $sql = 'SELECT u.consumer_key, u.context_id, u.user_id, u.lti_result_sourcedid ' . 'FROM ' . $this->dbTableNamePrefix . LTI_Data_Connector::USER_TABLE_NAME . ' AS u ' . 'INNER JOIN ' . $this->dbTableNamePrefix . LTI_Data_Connector::RESOURCE_LINK_TABLE_NAME . ' AS c ' . 'ON u.consumer_key = c.consumer_key AND u.context_id = c.context_id ' . 'WHERE ((c.consumer_key = :key) AND (c.context_id = :id) AND (c.primary_consumer_key IS NULL) AND (c.primary_context_id IS NULL)) OR ' . '((c.primary_consumer_key = :key) AND (c.primary_context_id = :id) AND (share_approved = 1))';
     }
     $key = $resource_link->getKey();
     $id = $resource_link->getId();
     $query = $this->db->prepare($sql);
     $query->bindValue('key', $key, PDO::PARAM_STR);
     $query->bindValue('id', $id, PDO::PARAM_STR);
     if ($query->execute()) {
         while ($row = $query->fetch()) {
             $user = new LTI_User($resource_link, $row['user_id']);
             $user->consumer_key = $row['consumer_key'];
             $user->context_id = $row['context_id'];
             $user->lti_result_sourcedid = $row['lti_result_sourcedid'];
             if (is_null($id_scope)) {
                 $users[] = $user;
             } else {
                 $users[$user->getId($id_scope)] = $user;
             }
         }
     }
     return $users;
 }
 public function getUserResultSourcedIDs($context_only = FALSE, $id_scope = NULL)
 {
     $users = array();
     if ($context_only) {
         $sql = sprintf('SELECT u.consumer_instance_guid, u.context_id, u.user_id, u.lti_result_sourcedid ' . "FROM {$this->consumer_instance->dbTableNamePrefix}" . BasicLTI_Tool_Provider::USER_TABLE_NAME . ' AS u ' . "INNER JOIN {$this->consumer_instance->dbTableNamePrefix}" . BasicLTI_Tool_Provider::CONTEXT_TABLE_NAME . ' AS c ' . 'ON u.consumer_instance_guid = c.consumer_instance_guid AND u.context_id = c.context_id ' . "WHERE (c.consumer_instance_guid = %s AND c.context_id = %s AND c.primary_consumer_instance_guid IS NULL AND c.primary_context_id IS NULL)", BasicLTI_Tool_Provider::quoted($this->consumer_instance->guid), BasicLTI_Tool_Provider::quoted($this->id));
     } else {
         $sql = sprintf('SELECT u.consumer_instance_guid, u.context_id, u.user_id, u.lti_result_sourcedid ' . "FROM {$this->consumer_instance->dbTableNamePrefix}" . BasicLTI_Tool_Provider::USER_TABLE_NAME . ' AS u ' . "INNER JOIN {$this->consumer_instance->dbTableNamePrefix}" . BasicLTI_Tool_Provider::CONTEXT_TABLE_NAME . ' AS c ' . 'ON u.consumer_instance_guid = c.consumer_instance_guid AND u.context_id = c.context_id ' . "WHERE (c.consumer_instance_guid = %s AND c.context_id = %s AND c.primary_consumer_instance_guid IS NULL AND c.primary_context_id IS NULL) OR " . "(c.primary_consumer_instance_guid = %s AND c.primary_context_id = %s AND share_approved = 1)", BasicLTI_Tool_Provider::quoted($this->consumer_instance->guid), BasicLTI_Tool_Provider::quoted($this->id), BasicLTI_Tool_Provider::quoted($this->consumer_instance->guid), BasicLTI_Tool_Provider::quoted($this->id));
     }
     $rs_user = mysql_query($sql);
     if ($rs_user) {
         while ($row = mysql_fetch_object($rs_user)) {
             $user = new LTI_User($this, $row->user_id);
             $user->consumer_instance_guid = $row->consumer_instance_guid;
             $user->context_id = $row->context_id;
             $user->lti_result_sourcedid = $row->lti_result_sourcedid;
             if (is_null($id_scope)) {
                 $users[] = $user;
             } else {
                 $users[$user->getId($id_scope)] = $user;
             }
         }
     }
     return $users;
 }
 public function Resource_Link_getUserResultSourcedIDs($resource_link, $local_only, $id_scope)
 {
     $users = array();
     if ($local_only) {
         $sql = sprintf('SELECT u.consumer_key, u.context_id, u.user_id, u.lti_result_sourcedid ' . "FROM {$this->dbTableNamePrefix}" . LTI_Data_Connector::USER_TABLE_NAME . ' AS u ' . "INNER JOIN {$this->dbTableNamePrefix}" . LTI_Data_Connector::RESOURCE_LINK_TABLE_NAME . ' AS c ' . 'ON u.consumer_key = c.consumer_key AND u.context_id = c.context_id ' . "WHERE (c.consumer_key = %s) AND (c.context_id = %s) AND (c.primary_consumer_key IS NULL) AND (c.primary_context_id IS NULL)", LTI_Data_Connector::quoted($resource_link->getKey()), LTI_Data_Connector::quoted($resource_link->getId()));
     } else {
         $sql = sprintf('SELECT u.consumer_key, u.context_id, u.user_id, u.lti_result_sourcedid ' . "FROM {$this->dbTableNamePrefix}" . LTI_Data_Connector::USER_TABLE_NAME . ' AS u ' . "INNER JOIN {$this->dbTableNamePrefix}" . LTI_Data_Connector::RESOURCE_LINK_TABLE_NAME . ' AS c ' . 'ON u.consumer_key = c.consumer_key AND u.context_id = c.context_id ' . 'WHERE ((c.consumer_key = %s) AND (c.context_id = %s) AND (c.primary_consumer_key IS NULL) AND (c.primary_context_id IS NULL)) OR ' . '((c.primary_consumer_key = %s) AND (c.primary_context_id = %s) AND (share_approved = 1))', LTI_Data_Connector::quoted($resource_link->getKey()), LTI_Data_Connector::quoted($resource_link->getId()), LTI_Data_Connector::quoted($resource_link->getKey()), LTI_Data_Connector::quoted($resource_link->getId()));
     }
     $rs_user = mysql_query($sql);
     if ($rs_user) {
         while ($row = mysql_fetch_object($rs_user)) {
             $user = new LTI_User($resource_link, $row->user_id);
             $user->consumer_key = $row->consumer_key;
             $user->context_id = $row->context_id;
             $user->lti_result_sourcedid = $row->lti_result_sourcedid;
             if (is_null($id_scope)) {
                 $users[] = $user;
             } else {
                 $users[$user->getId($id_scope)] = $user;
             }
         }
     }
     return $users;
 }
 public function Resource_Link_getUserResultSourcedIDs($resource_link, $local_only, $id_scope)
 {
     $users = array();
     if ($local_only) {
         $sql = 'SELECT u.consumer_key, u.context_id, u.user_id, u.lti_result_sourcedid ' . 'FROM ' . $this->dbTableNamePrefix . LTI_Data_Connector::USER_TABLE_NAME . ' u ' . 'INNER JOIN ' . $this->dbTableNamePrefix . LTI_Data_Connector::RESOURCE_LINK_TABLE_NAME . ' c ' . 'ON u.consumer_key = c.consumer_key AND u.context_id = c.context_id ' . 'WHERE (c.consumer_key = :key) AND (c.context_id = :id) AND (c.primary_consumer_key IS NULL) AND (c.primary_context_id IS NULL)';
     } else {
         $sql = 'SELECT u.consumer_key, u.context_id, u.user_id, u.lti_result_sourcedid ' . 'FROM ' . $this->dbTableNamePrefix . LTI_Data_Connector::USER_TABLE_NAME . ' u ' . 'INNER JOIN ' . $this->dbTableNamePrefix . LTI_Data_Connector::RESOURCE_LINK_TABLE_NAME . ' c ' . 'ON u.consumer_key = c.consumer_key AND u.context_id = c.context_id ' . 'WHERE ((c.consumer_key = :key) AND (c.context_id = :id) AND (c.primary_consumer_key IS NULL) AND (c.primary_context_id IS NULL)) OR ' . '((c.primary_consumer_key = :key) AND (c.primary_context_id = :id) AND (share_approved = 1))';
     }
     $key = $resource_link->getKey();
     $id = $resource_link->getId();
     $query = oci_parse($this->db, $sql);
     oci_bind_by_name($query, ':key', $key);
     oci_bind_by_name($query, ':id', $id);
     if (oci_execute($query)) {
         while ($row = oci_fetch_assoc($query)) {
             $row = array_change_key_case($row);
             $user = new LTI_User($resource_link, $row['user_id']);
             $user->consumer_key = $row['consumer_key'];
             $user->context_id = $row['context_id'];
             $user->lti_result_sourcedid = $row['lti_result_sourcedid'];
             if (is_null($id_scope)) {
                 $users[] = $user;
             } else {
                 $users[$user->getId($id_scope)] = $user;
             }
         }
     }
     return $users;
 }
 public function Resource_Link_getUserResultSourcedIDs($resource_link, $local_only, $id_scope)
 {
     $users = array();
     $ok = FALSE;
     $key = $resource_link->getKey();
     $id = $resource_link->getId();
     if ($local_only) {
         $sql = 'SELECT u.consumer_key, u.context_id, u.user_id, u.lti_result_sourcedid ' . "FROM {$this->dbTableNamePrefix}" . LTI_Data_Connector::USER_TABLE_NAME . ' AS u ' . "INNER JOIN {$this->dbTableNamePrefix}" . LTI_Data_Connector::RESOURCE_LINK_TABLE_NAME . ' AS c ' . 'ON u.consumer_key = c.consumer_key AND u.context_id = c.context_id ' . 'WHERE (c.consumer_key = ?) AND (c.context_id = ?) AND (c.primary_consumer_key IS NULL) AND (c.primary_context_id IS NULL)';
         $result = $this->db->prepare($sql);
         if ($result) {
             $ok = $result->bind_param('ss', $key, $id);
         }
     } else {
         $sql = 'SELECT u.consumer_key, u.context_id, u.user_id, u.lti_result_sourcedid ' . "FROM {$this->dbTableNamePrefix}" . LTI_Data_Connector::USER_TABLE_NAME . ' AS u ' . "INNER JOIN {$this->dbTableNamePrefix}" . LTI_Data_Connector::RESOURCE_LINK_TABLE_NAME . ' AS c ' . 'ON u.consumer_key = c.consumer_key AND u.context_id = c.context_id ' . 'WHERE ((c.consumer_key = ?) AND (c.context_id = ?) AND (c.primary_consumer_key IS NULL) AND (c.primary_context_id IS NULL)) OR ' . '((c.primary_consumer_key = ?) AND (c.primary_context_id = ?) AND (share_approved = 1))';
         $result = $this->db->prepare($sql);
         if ($result) {
             $ok = $result->bind_param('ssss', $key, $id, $key, $id);
         }
     }
     if ($result && $ok) {
         if ($result->execute()) {
             if ($result->bind_result($consumer_key, $resource_link_id, $user_id, $lti_result_sourcedid)) {
                 while ($result->fetch()) {
                     $user = new LTI_User($resource_link, $user_id);
                     $user->consumer_key = $consumer_key;
                     $user->context_id = $resource_link_id;
                     $user->lti_result_sourcedid = $lti_result_sourcedid;
                     if (is_null($id_scope)) {
                         $users[] = $user;
                     } else {
                         $users[$user->getId($id_scope)] = $user;
                     }
                 }
             }
         }
     }
     if ($result) {
         $result->close();
     }
     return $users;
 }
 /**
  * Perform a Memberships service request.
  *
  * The user table is updated with the new list of user objects.
  *
  * @param boolean $withGroups True is group information is to be requested as well
  *
  * @return mixed Array of LTI_User objects or False if the request was not successful
  */
 public function doMembershipsService($withGroups = FALSE)
 {
     $users = array();
     $old_users = $this->getUserResultSourcedIDs(TRUE, LTI_Tool_Provider::ID_SCOPE_RESOURCE);
     $this->ext_response = NULL;
     $url = $this->getSetting('ext_ims_lis_memberships_url');
     $params = array();
     $params['id'] = $this->getSetting('ext_ims_lis_memberships_id');
     $ok = FALSE;
     if ($withGroups) {
         $ok = $this->doService('basic-lis-readmembershipsforcontextwithgroups', $url, $params);
     }
     if ($ok) {
         $this->group_sets = array();
         $this->groups = array();
     } else {
         $ok = $this->doService('basic-lis-readmembershipsforcontext', $url, $params);
     }
     if ($ok) {
         if (!isset($this->ext_nodes['memberships']['member'])) {
             $members = array();
         } else {
             if (!isset($this->ext_nodes['memberships']['member'][0])) {
                 $members = array();
                 $members[0] = $this->ext_nodes['memberships']['member'];
             } else {
                 $members = $this->ext_nodes['memberships']['member'];
             }
         }
         for ($i = 0; $i < count($members); $i++) {
             $user = new LTI_User($this, $members[$i]['user_id']);
             #
             ### Set the user name
             #
             $firstname = isset($members[$i]['person_name_given']) ? $members[$i]['person_name_given'] : '';
             $lastname = isset($members[$i]['person_name_family']) ? $members[$i]['person_name_family'] : '';
             $fullname = isset($members[$i]['person_name_full']) ? $members[$i]['person_name_full'] : '';
             $user->setNames($firstname, $lastname, $fullname);
             #
             ### Set the user email
             #
             $email = isset($members[$i]['person_contact_email_primary']) ? $members[$i]['person_contact_email_primary'] : '';
             $user->setEmail($email, $this->consumer->defaultEmail);
             #
             ### Set the user roles
             #
             if (isset($members[$i]['roles'])) {
                 $user->roles = LTI_Tool_Provider::parseRoles($members[$i]['roles']);
             }
             #
             ### Set the user groups
             #
             if (!isset($members[$i]['groups']['group'])) {
                 $groups = array();
             } else {
                 if (!isset($members[$i]['groups']['group'][0])) {
                     $groups = array();
                     $groups[0] = $members[$i]['groups']['group'];
                 } else {
                     $groups = $members[$i]['groups']['group'];
                 }
             }
             for ($j = 0; $j < count($groups); $j++) {
                 $group = $groups[$j];
                 if (isset($group['set'])) {
                     $set_id = $group['set']['id'];
                     if (!isset($this->group_sets[$set_id])) {
                         $this->group_sets[$set_id] = array('title' => $group['set']['title'], 'groups' => array(), 'num_members' => 0, 'num_staff' => 0, 'num_learners' => 0);
                     }
                     $this->group_sets[$set_id]['num_members']++;
                     if ($user->isStaff()) {
                         $this->group_sets[$set_id]['num_staff']++;
                     }
                     if ($user->isLearner()) {
                         $this->group_sets[$set_id]['num_learners']++;
                     }
                     if (!in_array($group['id'], $this->group_sets[$set_id]['groups'])) {
                         $this->group_sets[$set_id]['groups'][] = $group['id'];
                     }
                     $this->groups[$group['id']] = array('title' => $group['title'], 'set' => $set_id);
                 } else {
                     $this->groups[$group['id']] = array('title' => $group['title']);
                 }
                 $user->groups[] = $group['id'];
             }
             #
             ### If a result sourcedid is provided save the user
             #
             if (isset($members[$i]['lis_result_sourcedid'])) {
                 $user->lti_result_sourcedid = $members[$i]['lis_result_sourcedid'];
                 $user->save();
             }
             $users[] = $user;
             #
             ### Remove old user (if it exists)
             #
             unset($old_users[$user->getId(LTI_Tool_Provider::ID_SCOPE_RESOURCE)]);
         }
         #
         ### Delete any old users which were not in the latest list from the tool consumer
         #
         foreach ($old_users as $id => $user) {
             $user->delete();
         }
     } else {
         $users = FALSE;
     }
     return $users;
 }
Exemplo n.º 7
0
 /**
  * Delete the user from the database
  *
  * @param LTI_User $user
  * @return bool
  */
 public function User_delete($user)
 {
     $key = $user->getResourceLink()->getKey();
     $id = $user->getResourceLink()->getId();
     $userId = $user->getId(LTI_Tool_Provider::ID_SCOPE_ID_ONLY);
     $sql = 'DELETE FROM ' . $this->dbTableNamePrefix . LTI_Data_Connector::USER_TABLE_NAME . ' ' . 'WHERE (consumer_key = :key) AND (context_id = :id) AND (user_id = :user_id)';
     $query = $this->db->prepare($sql);
     $query->bindValue('key', $key, PDO::PARAM_STR);
     $query->bindValue('id', $id, PDO::PARAM_STR);
     $query->bindValue('user_id', $userId, PDO::PARAM_STR);
     $ok = $query->execute();
     if ($ok) {
         $user->initialise();
     }
     return $ok;
 }