hedera-web/rest/image/util.php

55 lines
1.0 KiB
PHP
Raw Permalink Normal View History

2016-07-22 20:00:27 +00:00
<?php
2018-05-23 10:14:20 +00:00
require_once(__DIR__.'/image.php');
2016-07-22 20:00:27 +00:00
/**
* Base class for image methods.
*/
2018-05-23 10:14:20 +00:00
class Util {
2016-08-25 10:47:09 +00:00
var $app;
var $dataDir;
2016-07-22 20:00:27 +00:00
2018-05-23 10:14:20 +00:00
function __construct($app) {
2016-08-25 10:47:09 +00:00
$this->app = $app;
2018-05-23 10:14:20 +00:00
$this->dataDir = _DATA_DIR .'/'. $app->getName() .'/image-db';
2016-07-22 20:00:27 +00:00
}
/**
2020-08-29 11:06:54 +00:00
* Loads information for specified collection.
2016-07-22 20:00:27 +00:00
*
2020-08-29 11:06:54 +00:00
* @param string $collection The schema name
*/
2020-08-29 11:06:54 +00:00
function loadInfo($collection) {
2018-05-23 10:14:20 +00:00
$db = $this->app->getSysConn();
2016-07-22 20:00:27 +00:00
2018-05-23 10:14:20 +00:00
$info = $db->getRow(
2017-12-20 11:34:04 +00:00
'SELECT id, maxWidth, maxHeight, `schema`, `table`, `column`
2020-08-29 11:06:54 +00:00
FROM imageCollection WHERE name = #collection'
,['collection' => $collection]
2016-07-22 20:00:27 +00:00
);
if (!$info)
return NULL;
2018-05-23 10:14:20 +00:00
$res = $db->query(
2016-07-22 20:00:27 +00:00
'SELECT width, height, crop
2017-12-20 11:34:04 +00:00
FROM imageCollectionSize WHERE collectionFk = #id'
2016-07-22 20:00:27 +00:00
,['id' => $info['id']]
);
$info['sizes'] = [];
2018-05-23 10:14:20 +00:00
while ($r = $res->fetch_assoc()) {
2016-07-22 20:00:27 +00:00
$size = "{$r['width']}x{$r['height']}";
$info['sizes'][$size] = [
'width' => $r['width'],
'height' => $r['height'],
'crop' => $r['crop']
];
}
return $info;
}
}
2016-10-11 14:45:10 +00:00