LTI Integration Library  3.1.0
PHP class library for building LTI integrations
DataConnector_pdo_pgsql.php
Go to the documentation of this file.
1 <?php
2 
4 
5 use ceLTIc\LTI;
8 use PDO;
9 
19 {
20 ###
21 ### ResourceLink methods
22 ###
23 
36  public function getUserResultSourcedIDsResourceLink($resourceLink, $localOnly, $idScope)
37  {
38  $id = $resourceLink->getRecordId();
39  $userResults = array();
40 
41  if ($localOnly) {
42  $sql = 'SELECT u.user_result_pk, u.lti_result_sourcedid, u.lti_user_id, u.created, u.updated ' .
43  "FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . ' AS u ' .
44  "INNER JOIN {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' AS rl ' .
45  'ON u.resource_link_pk = rl.resource_link_pk ' .
46  'WHERE (rl.resource_link_pk = :id) AND (rl.primary_resource_link_pk IS NULL)';
47  $query = $this->db->prepare($sql);
48  $query->bindValue('id', $id, \PDO::PARAM_INT);
49  } else {
50  $sql = 'SELECT u.user_result_pk, u.lti_result_sourcedid, u.lti_user_id, u.created, u.updated ' .
51  "FROM {$this->dbTableNamePrefix}" . static::USER_RESULT_TABLE_NAME . ' AS u ' .
52  "INNER JOIN {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_TABLE_NAME . ' AS rl ' .
53  'ON u.resource_link_pk = rl.resource_link_pk ' .
54  'WHERE ((rl.resource_link_pk = :id) AND (rl.primary_resource_link_pk IS NULL)) OR ' .
55  '((rl.primary_resource_link_pk = :pid) AND share_approved)';
56  $query = $this->db->prepare($sql);
57  $query->bindValue('id', $id, \PDO::PARAM_INT);
58  $query->bindValue('pid', $id, \PDO::PARAM_INT);
59  }
60  if ($query->execute()) {
61  while ($row = $query->fetch(\PDO::FETCH_ASSOC)) {
62  $row = array_change_key_case($row);
63  $userresult = LTI\UserResult::fromRecordId($row['user_result_pk'], $resourceLink->getDataConnector());
64  $userresult->setRecordId(intval($row['user_result_pk']));
65  $userresult->ltiResultSourcedId = $row['lti_result_sourcedid'];
66  $userresult->created = strtotime($row['created']);
67  $userresult->updated = strtotime($row['updated']);
68  if (is_null($idScope)) {
69  $userResults[] = $userresult;
70  } else {
71  $userResults[$userresult->getId($idScope)] = $userresult;
72  }
73  }
74  }
75 
76  return $userResults;
77  }
78 
79 ###
80 ### ResourceLinkShareKey methods
81 ###
82 
90  public function saveResourceLinkShareKey($shareKey)
91  {
92  $id = $shareKey->getId();
93  $expires = date("{$this->dateFormat} {$this->timeFormat}", $shareKey->expires);
94  $sql = "INSERT INTO {$this->dbTableNamePrefix}" . static::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' ' .
95  '(share_key_id, resource_link_pk, auto_approve, expires) ' .
96  'VALUES (:id, :prlid, :approve, :expires)';
97  $query = $this->db->prepare($sql);
98  $query->bindValue('id', $id, \PDO::PARAM_STR);
99  $query->bindValue('prlid', $shareKey->resourceLinkId, \PDO::PARAM_INT);
100  $query->bindValue('approve', $shareKey->autoApprove, \PDO::PARAM_INT);
101  $query->bindValue('expires', $expires, \PDO::PARAM_STR);
102  $ok = $query->execute();
103 
104  return $ok;
105  }
106 
107 }
getUserResultSourcedIDsResourceLink($resourceLink, $localOnly, $idScope)
Get array of user objects.
saveResourceLinkShareKey($shareKey)
Save resource link share key object.
Class to represent a tool consumer.
Class to represent a tool consumer context.
Definition: Context.php:17
Class to represent an LTI Data Connector for PDO connections.
Class to represent an LTI Data Connector for PDO variations for PostgreSQL connections.
static fromRecordId($id, $dataConnector)
Load the user from the database.
Definition: UserResult.php:238