Example #1
0
 /**
  * @covers Phramework\LogJSONAPI\Models\SystemLog::get
  */
 public function testGet()
 {
     SystemLogAdapter::prepare();
     $page = (object) ['limit' => 2, 'offset' => 1];
     $sort = (object) ['attribute' => 'id', 'table' => SystemLogAdapter::getTable(), 'ascending' => false];
     $data = SystemLog::get($page, null, $sort);
     $this->assertNotEmpty($data);
     $this->assertLessThanOrEqual($page->limit, count($data));
     $this->assertInternalType('array', $data);
     $this->assertInternalType('object', $data[0]);
     $this->assertObjectHasAttribute('id', $data[0]);
     $this->assertObjectHasAttribute('type', $data[0]);
     $this->assertObjectHasAttribute('attributes', $data[0]);
     return $data[0]->id;
 }
Example #2
0
 /**
  * Return only ids
  * @param  string $queryLogId Foreign key
  * @return string[]
  */
 public static function getRelationshipByQueryLog($queryLogId)
 {
     //Access QueryLog object by this id to get the request_id
     $queryLogObject = QueryLog::getById($queryLogId);
     if (!$queryLogObject) {
         return [];
     }
     $requestId = $queryLogObject->attributes->request_id;
     SystemLogAdapter::prepare();
     $table = static::$table = SystemLogAdapter::getTable();
     $schema = SystemLogAdapter::getSchema();
     //Include schema if is set
     $schema = $schema ? sprintf('"%s".', $schema) : '';
     $ids = SystemLogAdapter::executeAndFetchAllArray(sprintf('SELECT "id"
             FROM %s"%s"
             WHERE "request_id" = ?', $schema, $table), [$requestId]);
     return array_map('strval', $ids);
 }