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-04 20:46:09 +00:00
|
|
|
*/
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads information for specified schema.
|
|
|
|
*
|
|
|
|
* @param string $schema The schema name
|
2018-05-04 20:46:09 +00:00
|
|
|
*/
|
2018-05-23 10:14:20 +00:00
|
|
|
function loadInfo($schema) {
|
|
|
|
$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`
|
|
|
|
FROM imageCollection WHERE name = #schema'
|
2016-07-22 20:00:27 +00:00
|
|
|
,['schema' => $schema]
|
|
|
|
);
|
|
|
|
|
|
|
|
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
|
|
|
|