Skip to content

Commit

Permalink
1.0.12 complete
Browse files Browse the repository at this point in the history
  • Loading branch information
Praesidiarius committed Feb 3, 2020
1 parent 939f6bb commit 3d72fce
Show file tree
Hide file tree
Showing 11 changed files with 280 additions and 14 deletions.
16 changes: 15 additions & 1 deletion module/Application/config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,24 @@
],
],
],
'quicksearch' => [
'type' => Literal::class,
'options' => [
'route' => '/quicksearch',
'defaults' => [
'controller' => Controller\IndexController::class,
'action' => 'quicksearch',
],
],
],
'application' => [
'type' => Segment::class,
'options' => [
'route' => '/application[/:action]',
'route' => '/application[/:action[/:id]]',
'constraints' => [
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
],
'defaults' => [
'controller' => Controller\IndexController::class,
'action' => 'index',
Expand Down
5 changes: 4 additions & 1 deletion module/Application/data/data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ INSERT INTO `permission` (`permission_key`, `module`, `label`, `nav_label`, `nav
('addtheme', 'Application\\Controller\\IndexController', 'Upload Theme', '', '/application/addtheme', 0),
('themes', 'Application\\Controller\\IndexController', 'Theme Selection', '', '/application/themes', 0),
('filepond', 'Application\\Controller\\IndexController', 'Upload Featured Image', '', '', 0),
('uppy', 'Application\\Controller\\IndexController', 'Gallery Upload', '', '', 0);
('uppy', 'Application\\Controller\\IndexController', 'Gallery Upload', '', '', 0),
('togglemediapub', 'Application\\Controller\\IndexController', 'Gallery Upload', '', '', 0),
('updateuppysort', 'Application\\Controller\\IndexController', 'Gallery Upload', '', '', 0),
('quicksearch', 'Application\\Controller\\IndexController', 'Quick Search', '', '', 0);

--
-- Default Widgets
Expand Down
22 changes: 22 additions & 0 deletions module/Application/data/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,28 @@ ALTER TABLE `core_api_key`
ALTER TABLE `core_api_key`
MODIFY `Apikey_ID` int(11) NOT NULL AUTO_INCREMENT;

--
-- Gallery Media
--
CREATE TABLE `core_gallery_media` (
`Media_ID` int(11) NOT NULL,
`filename` varchar(255) NOT NULL,
`entity_idfs` int(11) NOT NULL,
`entity_type` varchar(50) NOT NULL,
`is_public` tinyint(1) NOT NULL,
`created_by` int(11) NOT NULL,
`created_date` datetime NOT NULL,
`modified_by` int(11) NOT NULL,
`modified_date` datetime NOT NULL,
`sort_id` int(4) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

ALTER TABLE `core_gallery_media`
ADD PRIMARY KEY (`Media_ID`);

ALTER TABLE `core_gallery_media`
MODIFY `Media_ID` int(11) NOT NULL AUTO_INCREMENT;

--
-- Save
--
Expand Down
Binary file modified module/Application/language/de_DE.mo
Binary file not shown.
12 changes: 12 additions & 0 deletions module/Application/language/de_DE.po
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,15 @@ msgstr "Kontakt"

msgid "Terms & Conditions"
msgstr "AGB"

msgid "Is showed"
msgstr "Wird angezeigt"

msgid "Show"
msgstr "Anzeigen"

msgid "Hide"
msgstr "Verstecken"

msgid "Not showed"
msgstr "Wird nicht angezeigt"
1 change: 1 addition & 0 deletions module/Application/src/Controller/CoreController.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public function __construct(AdapterInterface $oDbAdapter,$oTableGateway = false,
CoreController::$aCoreTables['core-widget'] = new TableGateway('core_widget',CoreController::$oDbAdapter);
CoreController::$aCoreTables['user-widget'] = new TableGateway('core_widget_user',CoreController::$oDbAdapter);
CoreController::$aCoreTables['core-statistic'] = new TableGateway('core_statistic',CoreController::$oDbAdapter);
CoreController::$aCoreTables['core-gallery-media'] = new TableGateway('core_gallery_media',CoreController::$oDbAdapter);

$this->loadSettings();
}
Expand Down
150 changes: 138 additions & 12 deletions module/Application/src/Controller/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,20 @@ public function updateAction() {
}
}

/**
* Add new theme to oneplace
*
* @return \Laminas\Http\Response|ViewModel
*/
public function addthemeAction() {
$this->setThemeBasedLayout('application');

# Check if zip extension is loaded
if(!extension_loaded('zip')) {
$this->flashMessenger()->addErrorMessage('You need php-zip extension enabled on your webserver to add new themes');
$this->redirect()->toRoute('application',['action'=>'themes']);
}

$oRequest = $this->getRequest();

if(!$oRequest->isPost()) {
Expand Down Expand Up @@ -214,6 +225,12 @@ private function parseSQLInstallFile($sFile,$oAdapter) {
}
}

/**
* Server-Side for Filepond Upload
*
* @return bool
* @since 1.0.7
*/
public function filepondAction() {
$this->layout('layout/json');

Expand Down Expand Up @@ -282,6 +299,12 @@ public function filepondAction() {
}
}

/**
* Server Side for UPPY Fileupload
*
* @return bool
* @since 1.0.7
*/
public function uppyAction() {
$this->layout('layout/json');

Expand All @@ -290,16 +313,7 @@ public function uppyAction() {
$sPath = '';
$oEntityTbl = false;

var_dump($sEntityType);

switch($sEntityType) {
case 'skeleton':
$oEntityTbl = CoreController::$oServiceManager->get(\OnePlace\Skeleton\Model\SkeletonTable::class);
$oEntity = $oEntityTbl->getSingle($iEntityID);
if($oEntity) {
$sPath = $_SERVER['DOCUMENT_ROOT'].'/data/'.$sEntityType.'/'.$oEntity->getID().'/';
}
break;
default:
$oForm = CoreController::$aCoreTables['core-form']->select(['form_key'=>$sEntityType.'-single']);
if(count($oForm) > 0) {
Expand All @@ -309,14 +323,126 @@ public function uppyAction() {
if($oEntity) {
$sPath = $_SERVER['DOCUMENT_ROOT'].'/data/'.$sEntityType.'/'.$oEntity->getID().'/';
}
if(!is_dir($sPath)) {
mkdir($sPath);
}
}
$aFile = $_FILES['files'];
if(move_uploaded_file($aFile['tmp_name'][0],$sPath.'/'.trim($aFile['name'][0]))) {
if(isset($oForm)) {
CoreController::$aCoreTables['core-gallery-media']->insert([
'filename'=>trim($aFile['name'][0]),
'entity_idfs'=>$iEntityID,
'entity_type'=>$sEntityType,
'is_public'=>0,
'created_by'=>CoreController::$oSession->oUser->getID(),
'created_date'=>date('Y-m-d H:i:s',time()),
'modified_by'=>CoreController::$oSession->oUser->getID(),
'modified_date'=>date('Y-m-d H:i:s',time()),
'sort_id'=>0,
]);
}
}
break;
}
$aFile = $_FILES['files'];
if(move_uploaded_file($aFile['tmp_name'][0],$sPath.'/'.trim($aFile['name'][0]))) {
echo 'done';

return false;
}

/**
* Sorting for uppy galleries
*
* @return bool no viewfile. echo json
* @since 1.0.12
*/
public function updateuppysortAction() {
$this->layout('layout/json');


$oRequest = $this->getRequest();
$aImagesToSort = $oRequest->getPost('images');

$oGalleryTbl = CoreController::$aCoreTables['core-gallery-media'];

$iSortID = 0;
# Loop over all columns provided
foreach($aImagesToSort as $sImgInfo) {
$iMediaID = substr($sImgInfo,strlen('gallery-media-'));
$oGalleryTbl->update(['sort_id'=>$iSortID],'Media_ID = '.$iMediaID);
$iSortID++;
}

$aReturn = ['state'=>'success','message'=>'gallery successfully updated'];

echo json_encode($aReturn);

return false;
}

/**
* Toggle Media Public Status
*
* @return \Laminas\Http\Response
* @since 1.0.12
*/
public function togglemediapubAction() {
$this->layout('layout/json');

$iMediaID = $this->params()->fromRoute('id',0);

if($iMediaID != 0) {
$oGalleryTbl = CoreController::$aCoreTables['core-gallery-media'];
$oMedia = $oGalleryTbl->select(['Media_ID'=>$iMediaID]);
if(count($oMedia) > 0) {
$oMedia = $oMedia->current();
$bPublic = ($oMedia->is_public == 1) ? 0 : 1;
$oGalleryTbl->update(['is_public'=>$bPublic],'Media_ID = '.$iMediaID);

return $this->redirect()->toRoute($oMedia->entity_type,['action'=>'view','id'=>$oMedia->entity_idfs]);

}
}

return $this->redirect()->toRoute('home');
}

/**
* Quicksearch across all registered entities
*
* @return bool
* @since 1.0.12
*/
public function quicksearchAction() {
$this->layout('layout/json');

$aResponse = [
'results' => [],
];

/**
* Example DATA
$aResponse = [
'results' => [
[
'text' => 'Articles',
'children' => [
['id' => 1,'text' => 'Test Skel','view_link'=>'/article/view/##ID##'],
['id' => 2,'text' => 'Test Skel 2','view_link'=>'/article/view/##ID##'],
]
],
[
'text' => 'Users',
'children' => [
['id' => 1,'text' => 'Admin','view_link'=>'/user/view/##ID##'],
]
]
],
];
* */

echo json_encode($aResponse);

return false;
}
}
24 changes: 24 additions & 0 deletions module/Application/view/partial/quicksearch.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

use Application\Controller\CoreController;

?>
<select id="plcQuickSearch" class="form-control" style="min-width:450px;"></select>

<script>
$('#plcQuickSearch').select2({
ajax: {
url: '/quicksearch',
dataType: 'json'
},
placeholder: 'Quicksearch for any data'
});

$('#plcQuickSearch').on('select2:select',function(e) {
var sRawLink = e.params.data.view_link;
var iResultID = e.params.data.id;
var sFinalLink = sRawLink.replace('##ID##',iResultID);

window.location = sFinalLink;
});
</script>
1 change: 1 addition & 0 deletions module/Application/view/partial/webgallery-add.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
1 change: 1 addition & 0 deletions module/Application/view/partial/webgallery-edit.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
62 changes: 62 additions & 0 deletions module/Application/view/partial/webgallery-view.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

use Application\Controller\CoreController;
use Laminas\Db\Sql\Select;

$sEntityType = explode('-',$sFormName)[0];

$oImgSel = new Select(CoreController::$aCoreTables['core-gallery-media']->getTable());
$oImgSel->where([
'entity_idfs'=>$oItem->getID(),
'entity_type'=>$sEntityType,
]);
$oImgSel->order('sort_id ASC');

$aImages = CoreController::$aCoreTables['core-gallery-media']->selectWith($oImgSel);
?>
<ul class="list-group plc-webgallery-list">
<?php
if(count($aImages) > 0) {
foreach($aImages as $oImg) { ?>
<li class="list-group-item" id="gallery-media-<?=$oImg->Media_ID?>">
<div class="row">
<div class="col-md-1">
<i class="fas fa-arrows-alt-v plc-list-sort"></i>
</div>
<div class="col-md-2">
<img src="/data/<?=$sEntityType?>/<?=$oItem->getID()?>/<?=$oImg->filename?>" style="max-width:150px; height:60px;" />
</div>
<div class="col-md-5">
<?=$oImg->filename?>
</div>
<div class="col-md-2">
<?=($oImg->is_public == 1) ? '<i class="fas fa-eye"></i> '.$this->translate('Is showed') : '<i class="fas fa-eye-slash"></i> '.$this->translate('Not showed')?>
<br/><?=($oImg->is_public == 1) ? '<a class="btn btn-dark" href="/application/togglemediapub/'.$oImg->Media_ID.'">'.$this->translate('Hide').'</a>' : '<a class="btn btn-dark" href="/application/togglemediapub/'.$oImg->Media_ID.'">'.$this->translate('Show').'</a>'?>
</div>
</div>
</li>
<?php
}
}
?>
</ul>
<script>
$(function() {
$( "ul.plc-webgallery-list" ).sortable({
handle: '.plc-list-sort',
axis: "y",
update: function( event, ui ) {
var sortedIDs = $( "ul.plc-webgallery-list" ).sortable( "toArray" );
$.post('/application/updateuppysort',{entity_idfs:'<?=$oItem->getID()?>',entity_type:'<?=$sEntityType?>',images:sortedIDs},function(retVal) {
console.log(retVal);
var oJson = $.parseJSON(retVal);
if(oJson.state == 'success') {
$.printMessage('Update successful','Sorting was updated successfully','success');
} else {
alert('Fehler: '+oJson.message);
}
});
}
});
});
</script>

0 comments on commit 3d72fce

Please sign in to comment.