38        if (
$db->getAttribute(PDO::ATTR_DRIVER_NAME) == 
'oci') {
 
   39            $this->date_format = 
'd-M-Y';
 
   45###  ToolConsumer methods 
   59        if (!empty($consumer->getRecordId())) {
 
   60            $sql = 
'SELECT consumer_pk, name, consumer_key256, consumer_key, secret, lti_version, ' .
 
   61                   'consumer_name, consumer_version, consumer_guid, ' .
 
   62                   'profile, tool_proxy, settings, protected, enabled, ' .
 
   63                   'enable_from, enable_until, last_access, created, updated ' .
 
   65                   'WHERE consumer_pk = :id';
 
   66            $query = $this->db->prepare($sql);
 
   67            $id = $consumer->getRecordId();
 
   68            $query->bindValue(
'id', 
$id, PDO::PARAM_INT);
 
   70            $sql = 
'SELECT consumer_pk, name, consumer_key256, consumer_key, secret, lti_version, ' .
 
   71                   'consumer_name, consumer_version, consumer_guid, ' .
 
   72                   'profile, tool_proxy, settings, protected, enabled, ' .
 
   73                   'enable_from, enable_until, last_access, created, updated ' .
 
   75                   'WHERE consumer_key256 = :key256';
 
   76            $query = $this->db->prepare($sql);
 
   78            $query->bindValue(
'key256', $key256, PDO::PARAM_STR);
 
   82            while (
$row = 
$query->fetch(PDO::FETCH_ASSOC)) {
 
   84                if (empty($key256) || empty(
$row[
'consumer_key']) || ($consumer->getKey() === 
$row[
'consumer_key'])) {
 
   85                    $consumer->setRecordId(intval(
$row[
'consumer_pk']));
 
   86                    $consumer->name = 
$row[
'name'];
 
   87                    $consumer->setkey(empty(
$row[
'consumer_key']) ? 
$row[
'consumer_key256'] : 
$row[
'consumer_key']);
 
   88                    $consumer->secret = 
$row[
'secret'];
 
   89                    $consumer->ltiVersion = 
$row[
'lti_version'];
 
   90                    $consumer->consumerName = 
$row[
'consumer_name'];
 
   91                    $consumer->consumerVersion = 
$row[
'consumer_version'];
 
   92                    $consumer->consumerGuid = 
$row[
'consumer_guid'];
 
   93                    $consumer->profile = json_decode(
$row[
'profile']);
 
   94                    $consumer->toolProxy = 
$row[
'tool_proxy'];
 
   95                    $settings = unserialize(
$row[
'settings']);
 
   96                    if (!is_array($settings)) {
 
   99                    $consumer->setSettings($settings);
 
  100                    $consumer->protected = (intval(
$row[
'protected']) === 1);
 
  101                    $consumer->enabled = (intval(
$row[
'enabled']) === 1);
 
  102                    $consumer->enableFrom = 
null;
 
  103                    if (!is_null(
$row[
'enable_from'])) {
 
  104                        $consumer->enableFrom = strtotime(
$row[
'enable_from']);
 
  106                    $consumer->enableUntil = 
null;
 
  107                    if (!is_null(
$row[
'enable_until'])) {
 
  108                        $consumer->enableUntil = strtotime(
$row[
'enable_until']);
 
  110                    $consumer->lastAccess = 
null;
 
  111                    if (!is_null(
$row[
'last_access'])) {
 
  112                        $consumer->lastAccess = strtotime(
$row[
'last_access']);
 
  114                    $consumer->created = strtotime(
$row[
'created']);
 
  115                    $consumer->updated = strtotime(
$row[
'updated']);
 
  136        $id = $consumer->getRecordId();
 
  137        $key = $consumer->getKey();
 
  139        if (
$key === $key256) {
 
  142        $protected = ($consumer->protected) ? 1 : 0;
 
  143        $enabled = ($consumer->enabled)? 1 : 0;
 
  144        $profile = (!empty($consumer->profile)) ? json_encode($consumer->profile) : 
null;
 
  145        $settingsValue = serialize($consumer->getSettings());
 
  147        $now = date(
"{$this->dateFormat} {$this->timeFormat}", 
$time);
 
  149        if (!is_null($consumer->enableFrom)) {
 
  150            $from = date(
"{$this->dateFormat} {$this->timeFormat}", $consumer->enableFrom);
 
  153        if (!is_null($consumer->enableUntil)) {
 
  154            $until = date(
"{$this->dateFormat} {$this->timeFormat}", $consumer->enableUntil);
 
  157        if (!is_null($consumer->lastAccess)) {
 
  158            $last = date($this->dateFormat, $consumer->lastAccess);
 
  162                   'secret, lti_version, consumer_name, consumer_version, consumer_guid, profile, tool_proxy, settings, protected, enabled, ' .
 
  163                   'enable_from, enable_until, last_access, created, updated) ' .
 
  164                   'VALUES (:key256, :key, :name, :secret, :lti_version, :consumer_name, :consumer_version, :consumer_guid, :profile, :tool_proxy, :settings, ' .
 
  165                   ':protected, :enabled, :enable_from, :enable_until, :last_access, :created, :updated)';
 
  166            $query = $this->db->prepare($sql);
 
  167            $query->bindValue(
'key256', $key256, PDO::PARAM_STR);
 
  168            $query->bindValue(
'key', 
$key, PDO::PARAM_STR);
 
  169            $query->bindValue(
'name', $consumer->name, PDO::PARAM_STR);
 
  170            $query->bindValue(
'secret', $consumer->secret, PDO::PARAM_STR);
 
  171            $query->bindValue(
'lti_version', $consumer->ltiVersion, PDO::PARAM_STR);
 
  172            $query->bindValue(
'consumer_name', $consumer->consumerName, PDO::PARAM_STR);
 
  173            $query->bindValue(
'consumer_version', $consumer->consumerVersion, PDO::PARAM_STR);
 
  174            $query->bindValue(
'consumer_guid', $consumer->consumerGuid, PDO::PARAM_STR);
 
  175            $query->bindValue(
'profile', $profile, PDO::PARAM_STR);
 
  176            $query->bindValue(
'tool_proxy', $consumer->toolProxy, PDO::PARAM_STR);
 
  177            $query->bindValue(
'settings', $settingsValue, PDO::PARAM_STR);
 
  178            $query->bindValue(
'protected', $protected, PDO::PARAM_INT);
 
  179            $query->bindValue(
'enabled', $enabled, PDO::PARAM_INT);
 
  180            $query->bindValue(
'enable_from', 
$from, PDO::PARAM_STR);
 
  181            $query->bindValue(
'enable_until', $until, PDO::PARAM_STR);
 
  182            $query->bindValue(
'last_access', $last, PDO::PARAM_STR);
 
  183            $query->bindValue(
'created', $now, PDO::PARAM_STR);
 
  184            $query->bindValue(
'updated', $now, PDO::PARAM_STR);
 
  187                   'SET consumer_key256 = :key256, consumer_key = :key, name = :name, secret = :secret, lti_version = :lti_version, ' .
 
  188                   'consumer_name = :consumer_name, consumer_version = :consumer_version, consumer_guid = :consumer_guid, ' .
 
  189                   'profile = :profile, tool_proxy = :tool_proxy, settings = :settings, ' .
 
  190                   'protected = :protected, enabled = :enabled, enable_from = :enable_from, enable_until = :enable_until, last_access = :last_access, updated = :updated ' .
 
  191                   'WHERE consumer_pk = :id';
 
  192            $query = $this->db->prepare($sql);
 
  193            $query->bindValue(
'key256', $key256, PDO::PARAM_STR);
 
  194            $query->bindValue(
'key', 
$key, PDO::PARAM_STR);
 
  195            $query->bindValue(
'name', $consumer->name, PDO::PARAM_STR);
 
  196            $query->bindValue(
'secret', $consumer->secret, PDO::PARAM_STR);
 
  197            $query->bindValue(
'lti_version', $consumer->ltiVersion, PDO::PARAM_STR);
 
  198            $query->bindValue(
'consumer_name', $consumer->consumerName, PDO::PARAM_STR);
 
  199            $query->bindValue(
'consumer_version', $consumer->consumerVersion, PDO::PARAM_STR);
 
  200            $query->bindValue(
'consumer_guid', $consumer->consumerGuid, PDO::PARAM_STR);
 
  201            $query->bindValue(
'profile', $profile, PDO::PARAM_STR);
 
  202            $query->bindValue(
'tool_proxy', $consumer->toolProxy, PDO::PARAM_STR);
 
  203            $query->bindValue(
'settings', $settingsValue, PDO::PARAM_STR);
 
  204            $query->bindValue(
'protected', $protected, PDO::PARAM_INT);
 
  205            $query->bindValue(
'enabled', $enabled, PDO::PARAM_INT);
 
  206            $query->bindValue(
'enable_from', 
$from, PDO::PARAM_STR);
 
  207            $query->bindValue(
'enable_until', $until, PDO::PARAM_STR);
 
  208            $query->bindValue(
'last_access', $last, PDO::PARAM_STR);
 
  209            $query->bindValue(
'updated', $now, PDO::PARAM_STR);
 
  210            $query->bindValue(
'id', 
$id, PDO::PARAM_INT);
 
  215                $consumer->setRecordId(intval($this->db->lastInsertId()));
 
  216                $consumer->created = 
$time;
 
  218            $consumer->updated = 
$time;
 
  235        $id = $consumer->getRecordId();
 
  239        $query = $this->db->prepare($sql);
 
  240        $query->bindValue(
'id', 
$id, PDO::PARAM_INT);
 
  244        $sql = 
'DELETE sk ' .
 
  247               'WHERE rl.consumer_pk = :id';
 
  248        $query = $this->db->prepare($sql);
 
  249        $query->bindValue(
'id', 
$id, PDO::PARAM_INT);
 
  253        $sql = 
'DELETE sk ' .
 
  257               'WHERE c.consumer_pk = :id';
 
  258        $query = $this->db->prepare($sql);
 
  259        $query->bindValue(
'id', 
$id, PDO::PARAM_INT);
 
  266               'WHERE rl.consumer_pk = :id';
 
  267        $query = $this->db->prepare($sql);
 
  268        $query->bindValue(
'id', 
$id, PDO::PARAM_INT);
 
  276               'WHERE c.consumer_pk = :id';
 
  277        $query = $this->db->prepare($sql);
 
  278        $query->bindValue(
'id', 
$id, PDO::PARAM_INT);
 
  284               'SET prl.primary_resource_link_pk = NULL, prl.share_approved = NULL ' .
 
  285               'WHERE rl.consumer_pk = :id';
 
  286        $query = $this->db->prepare($sql);
 
  287        $query->bindValue(
'id', 
$id, PDO::PARAM_INT);
 
  294               'SET prl.primary_resource_link_pk = NULL, prl.share_approved = NULL ' .
 
  295               'WHERE c.consumer_pk = :id';
 
  296        $query = $this->db->prepare($sql);
 
  297        $query->bindValue(
'id', 
$id, PDO::PARAM_INT);
 
  301        $sql = 
'DELETE rl ' .
 
  303               'WHERE rl.consumer_pk = :id';
 
  304        $query = $this->db->prepare($sql);
 
  305        $query->bindValue(
'id', 
$id, PDO::PARAM_INT);
 
  309        $sql = 
'DELETE rl ' .
 
  312               'WHERE c.consumer_pk = :id';
 
  313        $query = $this->db->prepare($sql);
 
  314        $query->bindValue(
'id', 
$id, PDO::PARAM_INT);
 
  320               'WHERE c.consumer_pk = :id';
 
  321        $query = $this->db->prepare($sql);
 
  322        $query->bindValue(
'id', 
$id, PDO::PARAM_INT);
 
  328               'WHERE c.consumer_pk = :id';
 
  329        $query = $this->db->prepare($sql);
 
  330        $query->bindValue(
'id', 
$id, PDO::PARAM_INT);
 
  334            $consumer->initialize();
 
  342#    Load all tool consumers from the database 
  347        $consumers = array();
 
  349        $sql = 
'SELECT consumer_pk, name, consumer_key256, consumer_key, secret, lti_version, ' .
 
  350               'consumer_name, consumer_version, consumer_guid, ' .
 
  351               'profile, tool_proxy, settings, protected, enabled, ' .
 
  352               'enable_from, enable_until, last_access, created, updated ' .
 
  355        $query = $this->db->prepare($sql);
 
  363            while (
$row = 
$query->fetch(PDO::FETCH_ASSOC)) {
 
  365                $key = empty(
$row[
'consumer_key']) ? 
$row[
'consumer_key256'] : 
$row[
'consumer_key'];
 
  367                $consumer->setRecordId(intval(
$row[
'consumer_pk']));
 
  368                $consumer->name = 
$row[
'name'];
 
  369                $consumer->secret = 
$row[
'secret'];
 
  370                $consumer->ltiVersion = 
$row[
'lti_version'];
 
  371                $consumer->consumerName = 
$row[
'consumer_name'];
 
  372                $consumer->consumerVersion = 
$row[
'consumer_version'];
 
  373                $consumer->consumerGuid = 
$row[
'consumer_guid'];
 
  374                $consumer->profile = json_decode(
$row[
'profile']);
 
  375                $consumer->toolProxy = 
$row[
'tool_proxy'];
 
  376                $settings = unserialize(
$row[
'settings']);
 
  377                if (!is_array($settings)) {
 
  380                $consumer->setSettings($settings);
 
  381                $consumer->protected = (intval(
$row[
'protected']) === 1);
 
  382                $consumer->enabled = (intval(
$row[
'enabled']) === 1);
 
  383                $consumer->enableFrom = 
null;
 
  384                if (!is_null(
$row[
'enable_from'])) {
 
  385                    $consumer->enableFrom = strtotime(
$row[
'enable_from']);
 
  387                $consumer->enableUntil = 
null;
 
  388                if (!is_null(
$row[
'enable_until'])) {
 
  389                    $consumer->enableUntil = strtotime(
$row[
'enable_until']);
 
  391                $consumer->lastAccess = 
null;
 
  392                if (!is_null(
$row[
'last_access'])) {
 
  393                    $consumer->lastAccess = strtotime(
$row[
'last_access']);
 
  395                $consumer->created = strtotime(
$row[
'created']);
 
  396                $consumer->updated = strtotime(
$row[
'updated']);
 
  397                $consumers[] = $consumer;
 
  410#    Load the tool proxy from the database 
  420#    Save the tool proxy to the database 
  430#    Delete the tool proxy from the database 
  454        if (!empty(
$context->getRecordId())) {
 
  455            $sql = 
'SELECT context_pk, consumer_pk, lti_context_id, settings, created, updated ' .
 
  457                   'WHERE (context_pk = :id)';
 
  458            $query = $this->db->prepare($sql);
 
  461            $sql = 
'SELECT context_pk, consumer_pk, lti_context_id, settings, created, updated ' .
 
  463                   'WHERE (consumer_pk = :cid) AND (lti_context_id = :ctx)';
 
  464            $query = $this->db->prepare($sql);
 
  465            $query->bindValue(
'cid', 
$context->getConsumer()->getRecordId(), PDO::PARAM_INT);
 
  478            $settings = unserialize(
$row[
'settings']);
 
  479            if (!is_array($settings)) {
 
  502        $now = date(
"{$this->dateFormat} {$this->timeFormat}", 
$time);
 
  503        $settingsValue = serialize(
$context->getSettings());
 
  505        $consumer_pk = 
$context->getConsumer()->getRecordId();
 
  508                   'settings, created, updated) ' .
 
  509                   'VALUES (:cid, :ctx, :settings, :created, :updated)';
 
  510            $query = $this->db->prepare($sql);
 
  511            $query->bindValue(
'cid', $consumer_pk, PDO::PARAM_INT);
 
  513            $query->bindValue(
'settings', $settingsValue, PDO::PARAM_STR);
 
  514            $query->bindValue(
'created', $now, PDO::PARAM_STR);
 
  515            $query->bindValue(
'updated', $now, PDO::PARAM_STR);
 
  518                   'lti_context_id = :ctx, settings = :settings, '.
 
  519                   'updated = :updated ' .
 
  520                   'WHERE (consumer_pk = :cid) AND (context_pk = :ctxid)';
 
  521            $query = $this->db->prepare($sql);
 
  523            $query->bindValue(
'settings', $settingsValue, PDO::PARAM_STR);
 
  524            $query->bindValue(
'updated', $now, PDO::PARAM_STR);
 
  525            $query->bindValue(
'cid', $consumer_pk, PDO::PARAM_INT);
 
  526            $query->bindValue(
'ctxid', 
$id, PDO::PARAM_INT);
 
  531                $context->setRecordId(intval($this->db->lastInsertId()));
 
  554        $sql = 
'DELETE sk ' .
 
  557               'WHERE rl.context_pk = :id';
 
  558        $query = $this->db->prepare($sql);
 
  559        $query->bindValue(
'id', 
$id, PDO::PARAM_INT);
 
  566               'WHERE rl.context_pk = :id';
 
  567        $query = $this->db->prepare($sql);
 
  568        $query->bindValue(
'id', 
$id, PDO::PARAM_INT);
 
  574               'SET prl.primary_resource_link_pk = null, prl.share_approved = null ' .
 
  575               'WHERE rl.context_pk = :id';
 
  576        $query = $this->db->prepare($sql);
 
  577        $query->bindValue(
'id', 
$id, PDO::PARAM_INT);
 
  581        $sql = 
'DELETE rl ' .
 
  583               'WHERE rl.context_pk = :id';
 
  584        $query = $this->db->prepare($sql);
 
  585        $query->bindValue(
'id', 
$id, PDO::PARAM_INT);
 
  591               'WHERE c.context_pk = :id';
 
  592        $query = $this->db->prepare($sql);
 
  593        $query->bindValue(
'id', 
$id, PDO::PARAM_INT);
 
  605###  ResourceLink methods 
  618        if (!empty($resourceLink->getRecordId())) {
 
  619            $sql = 
'SELECT resource_link_pk, context_pk, consumer_pk, lti_resource_link_id, settings, primary_resource_link_pk, share_approved, created, updated ' .
 
  621                   'WHERE (resource_link_pk = :id)';
 
  622            $query = $this->db->prepare($sql);
 
  623            $query->bindValue(
'id', $resourceLink->getRecordId(), PDO::PARAM_INT);
 
  624        } 
else if (!empty($resourceLink->getContext())) {
 
  625            $sql = 
'SELECT resource_link_pk, context_pk, consumer_pk, lti_resource_link_id, settings, primary_resource_link_pk, share_approved, created, updated ' .
 
  627                   'WHERE (context_pk = :id) AND (lti_resource_link_id = :rlid)';
 
  628            $query = $this->db->prepare($sql);
 
  629            $query->bindValue(
'id', $resourceLink->getContext()->getRecordId(), PDO::PARAM_INT);
 
  630            $query->bindValue(
'rlid', $resourceLink->getId(), PDO::PARAM_STR);
 
  632            $sql = 
'SELECT r.resource_link_pk, r.context_pk, r.consumer_pk, r.lti_resource_link_id, r.settings, r.primary_resource_link_pk, r.share_approved, r.created, r.updated ' .
 
  635                   ' WHERE ((r.consumer_pk = :id1) OR (c.consumer_pk = :id2)) AND (lti_resource_link_id = :rlid)';
 
  636            $query = $this->db->prepare($sql);
 
  637            $query->bindValue(
'id1', $resourceLink->getConsumer()->getRecordId(), PDO::PARAM_INT);
 
  638            $query->bindValue(
'id2', $resourceLink->getConsumer()->getRecordId(), PDO::PARAM_INT);
 
  639            $query->bindValue(
'rlid', $resourceLink->getId(), PDO::PARAM_STR);
 
  649            $resourceLink->setRecordId(intval(
$row[
'resource_link_pk']));
 
  650            if (!is_null(
$row[
'context_pk'])) {
 
  651                $resourceLink->setContextId(intval(
$row[
'context_pk']));
 
  653                $resourceLink->setContextId(
null);
 
  655            if (!is_null(
$row[
'consumer_pk'])) {
 
  656                $resourceLink->setConsumerId(intval(
$row[
'consumer_pk']));
 
  658                $resourceLink->setConsumerId(
null);
 
  660            $resourceLink->ltiResourceLinkId = 
$row[
'lti_resource_link_id'];
 
  661            $settings = unserialize(
$row[
'settings']);
 
  662            if (!is_array($settings)) {
 
  665            $resourceLink->setSettings($settings);
 
  666            if (!is_null(
$row[
'primary_resource_link_pk'])) {
 
  667                $resourceLink->primaryResourceLinkId = intval(
$row[
'primary_resource_link_pk']);
 
  669                $resourceLink->primaryResourceLinkId = 
null;
 
  671            $resourceLink->shareApproved = (is_null(
$row[
'share_approved'])) ? 
null : (intval(
$row[
'share_approved']) === 1);
 
  672            $resourceLink->created = strtotime(
$row[
'created']);
 
  673            $resourceLink->updated = strtotime(
$row[
'updated']);
 
  690        $now = date(
"{$this->dateFormat} {$this->timeFormat}", 
$time);
 
  691        $settingsValue = serialize($resourceLink->getSettings());
 
  692        if (!empty($resourceLink->getContext())) {
 
  694            $contextId = strval($resourceLink->getContext()->getRecordId());
 
  695        } 
else if (!empty($resourceLink->getContextId())) {
 
  697            $contextId = strval($resourceLink->getContextId());
 
  699            $consumerId = strval($resourceLink->getConsumer()->getRecordId());
 
  702        if (empty($resourceLink->primaryResourceLinkId)) {
 
  703            $primaryResourceLinkId = 
null;
 
  705            $primaryResourceLinkId = $resourceLink->primaryResourceLinkId;
 
  707        $id = $resourceLink->getRecordId();
 
  710                   'lti_resource_link_id, settings, primary_resource_link_pk, share_approved, created, updated) ' .
 
  711                   'VALUES (:cid, :ctx, :rlid, :settings, :prlid, :share_approved, :created, :updated)';
 
  712            $query = $this->db->prepare($sql);
 
  713            $query->bindValue(
'cid', $consumerId, PDO::PARAM_INT);
 
  714            $query->bindValue(
'ctx', $contextId, PDO::PARAM_INT);
 
  715            $query->bindValue(
'rlid', $resourceLink->getId(), PDO::PARAM_STR);
 
  716            $query->bindValue(
'settings', $settingsValue, PDO::PARAM_STR);
 
  717            $query->bindValue(
'prlid', $primaryResourceLinkId, PDO::PARAM_INT);
 
  718            $query->bindValue(
'share_approved', $resourceLink->shareApproved, PDO::PARAM_INT);
 
  719            $query->bindValue(
'created', $now, PDO::PARAM_STR);
 
  720            $query->bindValue(
'updated', $now, PDO::PARAM_STR);
 
  721        } 
else if (!is_null($contextId)) {
 
  723                   'consumer_pk = NULL, context_pk = :ctx, lti_resource_link_id = :rlid, settings = :settings, '.
 
  724                   'primary_resource_link_pk = :prlid, share_approved = :share_approved, updated = :updated ' .
 
  725                   'WHERE (resource_link_pk = :id)';
 
  726            $query = $this->db->prepare($sql);
 
  727            $query->bindValue(
'ctx', $contextId, PDO::PARAM_INT);
 
  728            $query->bindValue(
'rlid', $resourceLink->getId(), PDO::PARAM_STR);
 
  729            $query->bindValue(
'settings', $settingsValue, PDO::PARAM_STR);
 
  730            $query->bindValue(
'prlid', $primaryResourceLinkId, PDO::PARAM_INT);
 
  731            $query->bindValue(
'share_approved', $resourceLink->shareApproved, PDO::PARAM_INT);
 
  732            $query->bindValue(
'updated', $now, PDO::PARAM_STR);
 
  733            $query->bindValue(
'id', 
$id, PDO::PARAM_INT);
 
  736                   'context_pk = :ctx, lti_resource_link_id = :rlid, settings = :settings, '.
 
  737                   'primary_resource_link_pk = :prlid, share_approved = :share_approved, updated = :updated ' .
 
  738                   'WHERE (consumer_pk = :cid) AND (resource_link_pk = :id)';
 
  739            $query = $this->db->prepare($sql);
 
  740            $query->bindValue(
'ctx', $contextId, PDO::PARAM_INT);
 
  741            $query->bindValue(
'rlid', $resourceLink->getId(), PDO::PARAM_STR);
 
  742            $query->bindValue(
'settings', $settingsValue, PDO::PARAM_STR);
 
  743            $query->bindValue(
'prlid', $primaryResourceLinkId, PDO::PARAM_INT);
 
  744            $query->bindValue(
'share_approved', $resourceLink->shareApproved, PDO::PARAM_INT);
 
  745            $query->bindValue(
'updated', $now, PDO::PARAM_STR);
 
  746            $query->bindValue(
'cid', $consumerId, PDO::PARAM_INT);
 
  747            $query->bindValue(
'id', 
$id, PDO::PARAM_INT);
 
  752                $resourceLink->setRecordId(intval($this->db->lastInsertId()));
 
  753                $resourceLink->created = 
$time;
 
  755            $resourceLink->updated = 
$time;
 
  772        $id = $resourceLink->getRecordId();
 
  776               'WHERE (resource_link_pk = :id)';
 
  777        $query = $this->db->prepare($sql);
 
  778        $query->bindValue(
'id', 
$id, PDO::PARAM_INT);
 
  784                   'WHERE (resource_link_pk = :id)';
 
  785            $query = $this->db->prepare($sql);
 
  786            $query->bindValue(
'id', 
$id, PDO::PARAM_INT);
 
  793                   'SET primary_resource_link_pk = NULL ' .
 
  794                   'WHERE (primary_resource_link_pk = :id)';
 
  795            $query = $this->db->prepare($sql);
 
  796            $query->bindValue(
'id', 
$id, PDO::PARAM_INT);
 
  803                   'WHERE (resource_link_pk = :id)';
 
  804            $query = $this->db->prepare($sql);
 
  805            $query->bindValue(
'id', 
$id, PDO::PARAM_INT);
 
  810            $resourceLink->initialize();
 
  832        $id = $resourceLink->getRecordId();
 
  836            $sql = 
'SELECT u.user_pk, u.lti_result_sourcedid, u.lti_user_id, u.created, u.updated ' .
 
  839                   'ON u.resource_link_pk = rl.resource_link_pk ' .
 
  840                   'WHERE (rl.resource_link_pk = :id) AND (rl.primary_resource_link_pk IS NULL)';
 
  841            $query = $this->db->prepare($sql);
 
  842            $query->bindValue(
'id', 
$id, PDO::PARAM_INT);
 
  844            $sql = 
'SELECT u.user_pk, u.lti_result_sourcedid, u.lti_user_id, u.created, u.updated ' .
 
  847                   'ON u.resource_link_pk = rl.resource_link_pk ' .
 
  848                   'WHERE ((rl.resource_link_pk = :id) AND (rl.primary_resource_link_pk IS NULL)) OR ' .
 
  849                   '((rl.primary_resource_link_pk = :pid) AND (share_approved = 1))';
 
  850            $query = $this->db->prepare($sql);
 
  851            $query->bindValue(
'id', 
$id, PDO::PARAM_INT);
 
  852            $query->bindValue(
'pid', 
$id, PDO::PARAM_INT);
 
  855            while (
$row = 
$query->fetch(PDO::FETCH_ASSOC)) {
 
  858                if (is_null($idScope)) {
 
  880        $id = $resourceLink->getRecordId();
 
  884        $sql = 
'SELECT consumer_pk, resource_link_pk, share_approved ' .
 
  886               'WHERE (primary_resource_link_pk = :id) ' .
 
  887               'ORDER BY consumer_pk';
 
  888        $query = $this->db->prepare($sql);
 
  889        $query->bindValue(
'id', 
$id, PDO::PARAM_INT);
 
  891            while (
$row = 
$query->fetch(PDO::FETCH_ASSOC)) {
 
  894                $share->resourceLinkId = intval(
$row[
'resource_link_pk']);
 
  895                $share->approved = (intval(
$row[
'share_approved']) === 1);
 
  906###  ConsumerNonce methods 
  922        $now = date(
"{$this->dateFormat} {$this->timeFormat}", time());
 
  924        $query = $this->db->prepare($sql);
 
  925        $query->bindValue(
'now', $now, PDO::PARAM_STR);
 
  929        $id = $nonce->getConsumer()->getRecordId();
 
  930        $value = $nonce->getValue();
 
  932        $query = $this->db->prepare($sql);
 
  933        $query->bindValue(
'id', 
$id, PDO::PARAM_INT);
 
  934        $query->bindValue(
'value', $value, PDO::PARAM_STR);
 
  938            if (
$row === 
false) {
 
  957        $id = $nonce->getConsumer()->getRecordId();
 
  958        $value = $nonce->getValue();
 
  959        $expires = date(
"{$this->dateFormat} {$this->timeFormat}", $nonce->expires);
 
  961        $query = $this->db->prepare($sql);
 
  962        $query->bindValue(
'id', 
$id, PDO::PARAM_INT);
 
  963        $query->bindValue(
'value', $value, PDO::PARAM_STR);
 
  964        $query->bindValue(
'expires', $expires, PDO::PARAM_STR);
 
  973###  ResourceLinkShareKey methods 
  989        $now = date(
"{$this->dateFormat} {$this->timeFormat}", time());
 
  991        $query = $this->db->prepare($sql);
 
  992        $query->bindValue(
'now', $now, PDO::PARAM_STR);
 
  996        $id = $shareKey->getId();
 
  997        $sql = 
'SELECT resource_link_pk, auto_approve, expires ' .
 
  999               'WHERE share_key_id = :id';
 
 1000        $query = $this->db->prepare($sql);
 
 1001        $query->bindValue(
'id', 
$id, PDO::PARAM_STR);
 
 1004            if (
$row !== FALSE) {
 
 1005                $row = array_change_key_case(
$row);
 
 1006                if (intval(
$row[
'resource_link_pk']) === $shareKey->resourceLinkId) {
 
 1007                    $shareKey->autoApprove = (
$row[
'auto_approve'] === 1);
 
 1008                    $shareKey->expires = strtotime(
$row[
'expires']);
 
 1028        $id = $shareKey->getId();
 
 1029        $expires = date(
"{$this->dateFormat} {$this->timeFormat}", $shareKey->expires);
 
 1031               '(share_key_id, resource_link_pk, auto_approve, expires) ' .
 
 1032               'VALUES (:id, :prlid, :approve, :expires)';
 
 1033        $query = $this->db->prepare($sql);
 
 1034        $query->bindValue(
'id', 
$id, PDO::PARAM_STR);
 
 1035        $query->bindValue(
'prlid', $shareKey->resourceLinkId, PDO::PARAM_INT);
 
 1036        $query->bindValue(
'approve', $shareKey->autoApprove, PDO::PARAM_INT);
 
 1037        $query->bindValue(
'expires', $expires, PDO::PARAM_STR);
 
 1054        $id = $shareKey->getId();
 
 1056        $query = $this->db->prepare($sql);
 
 1057        $query->bindValue(
'id', 
$id, PDO::PARAM_STR);
 
 1061            $shareKey->initialize();
 
 1084        if (!empty(
$user->getRecordId())) {
 
 1086            $sql = 
'SELECT user_pk, resource_link_pk, lti_user_id, lti_result_sourcedid, created, updated ' .
 
 1088                   'WHERE (user_pk = :id)';
 
 1089            $query = $this->db->prepare($sql);
 
 1090            $query->bindValue(
'id', 
$id, PDO::PARAM_INT);
 
 1092            $id = 
$user->getResourceLink()->getRecordId();
 
 1094            $sql = 
'SELECT user_pk, resource_link_pk, lti_user_id, lti_result_sourcedid, created, updated ' .
 
 1096                   'WHERE (resource_link_pk = :id) AND (lti_user_id = :uid)';
 
 1097            $query = $this->db->prepare($sql);
 
 1098            $query->bindValue(
'id', 
$id, PDO::PARAM_INT);
 
 1099            $query->bindValue(
'uid', $uid, PDO::PARAM_STR);
 
 1103            if (
$row !== 
false) {
 
 1104                $row = array_change_key_case(
$row);
 
 1105                $user->setRecordId(intval(
$row[
'user_pk']));
 
 1106                $user->setResourceLinkId(intval(
$row[
'resource_link_pk']));
 
 1108                $user->ltiResultSourcedId = 
$row[
'lti_result_sourcedid'];
 
 1109                $user->created = strtotime(
$row[
'created']);
 
 1110                $user->updated = strtotime(
$row[
'updated']);
 
 1130        $now = date(
"{$this->dateFormat} {$this->timeFormat}", 
$time);
 
 1131        if (is_null(
$user->created)) {
 
 1133                   'lti_user_id, lti_result_sourcedid, created, updated) ' .
 
 1134                   'VALUES (:rlid, :uid, :sourcedid, :created, :updated)';
 
 1135            $query = $this->db->prepare($sql);
 
 1136            $query->bindValue(
'rlid', 
$user->getResourceLink()->getRecordId(), PDO::PARAM_INT);
 
 1138            $query->bindValue(
'sourcedid', 
$user->ltiResultSourcedId, PDO::PARAM_STR);
 
 1139            $query->bindValue(
'created', $now, PDO::PARAM_STR);
 
 1140            $query->bindValue(
'updated', $now, PDO::PARAM_STR);
 
 1143                   'SET lti_result_sourcedid = :sourcedid, updated = :updated ' .
 
 1144                   'WHERE (user_pk = :id)';
 
 1145            $query = $this->db->prepare($sql);
 
 1146            $query->bindValue(
'sourcedid', 
$user->ltiResultSourcedId, PDO::PARAM_STR);
 
 1147            $query->bindValue(
'updated', $now, PDO::PARAM_STR);
 
 1148            $query->bindValue(
'id', 
$user->getRecordId(), PDO::PARAM_INT);
 
 1152            if (is_null(
$user->created)) {
 
 1153                $user->setRecordId(intval($this->db->lastInsertId()));
 
 1174               'WHERE (user_pk = :id)';
 
 1175        $query = $this->db->prepare($sql);
 
 1176        $query->bindValue(
'id', 
$user->getRecordId(), PDO::PARAM_INT);
 
 1180            $user->initialize();
 
An exception for terminatinating execution or to throw for unit testing.
Class to represent a tool consumer context.
if(!array_key_exists('StateId', $_REQUEST)) $id