Add view and hsset link parameters

Signed-off-by: Justin Georgi <justin.georgi@gmail.com>
This commit is contained in:
2024-10-30 11:53:02 -07:00
parent 64140b7cd9
commit d59958f110
4 changed files with 80 additions and 35 deletions

View File

@@ -20,6 +20,8 @@ class GlModelTransformOutput extends MediaTransformOutput {
$this->parameters = $parameters;
$this->width = $parameters['width'];
$this->height = $parameters['height'];
$this->view = (isset($parameters['view'])) ? $parameters['view'] : 'default';
$this->hsset = (isset($parameters['hsset'])) ? $parameters['hsset'] : 'all';
$this->url = $file->getFullUrl();
$this->thumb = isset($parameters['isFilePageThumb']) && $parameters['isFilePageThumb'];
}
@@ -79,15 +81,15 @@ class GlModelTransformOutput extends MediaTransformOutput {
//Gather basic data
preg_match('/<pre>([\S\s]*?)<\/pre>/',$inText,$modelDescript);
$metadata = json_decode($modelDescript[1], true);
$viewClass = self::extractClassParams('view',$viewParams['class']);
$hsSetClass = self::extractClassParams('hsset',$viewParams['class']);
$hsSet = (isset($metadata['annotationSets']) && isset($metadata['annotationSets'][$this->hsset])) ? $this->hsset : 'default';
$view = (isset($metadata['viewerConfig']) && isset($metadata['viewerConfig'][$this->view])) ? $this->view : 'default';
//Handle annotations and annotation sets
if (isset($metadata['annotations'])) {
$hotspots = [];
$annotations = [];
if ($hsSetClass != 'default' && isset($metadata['annotationSets'])) {
foreach($metadata['annotationSets'][$hsSetClass] as $includeAn) {
if ($hsSet != 'default') {
foreach($metadata['annotationSets'][$hsSet] as $includeAn) {
if (isset($metadata['annotations'][$includeAn])) {
$annotations[$includeAn] = $metadata['annotations'][$includeAn];
}
@@ -114,8 +116,8 @@ class GlModelTransformOutput extends MediaTransformOutput {
}
//Set viewer configurations or use basic default if none defined
if (isset($metadata['viewerConfig']) && isset($metadata['viewerConfig'][$viewClass])) {
$attrModelView = $metadata['viewerConfig'][$viewClass];
if (isset($metadata['viewerConfig']) && isset($metadata['viewerConfig'][$view])) {
$attrModelView = $metadata['viewerConfig'][$view];
} else {
$attrModelView = array('camera-controls' => true);
}
@@ -139,32 +141,6 @@ class GlModelTransformOutput extends MediaTransformOutput {
return Html::rawElement('div', $attrContainer, $elModel . $elMenu);
}
/**
* Detect and return model user params from link classes
*
* The best way to send information in a file link is by adding classes to the
* link. This function parses the array of those classes and returns the information
* or 'default'
*
* @param string $paramType the type of parameter to be extracted 'view'|'hsset'
* @param string $classList a string of class names
* @return string parameter value or 'default'
*/
private static function extractClassParams(string $paramType, ? string $classList) {
if (!in_array($paramType, ['view', 'hsset'])) {
return 'default';
}
if (!isset($classList)) {
return 'default';
}
$searchString = '/' . $paramType . '-(\S*)/';
preg_match($searchString,$classList,$extractInfo);
return ($extractInfo[1]) ? $extractInfo[1] : 'default';
}
/**
* Build the button menu used for viewer actions
*