Skip to content

Commit

Permalink
Ticket #2754 - Move between albums.
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonLV committed Sep 10, 2021
1 parent a20c926 commit 6e23bdb
Show file tree
Hide file tree
Showing 11 changed files with 186 additions and 38 deletions.
5 changes: 4 additions & 1 deletion inc/classes/BxDolStorageQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ public function getFiles($mixedProfileId, $isGhostsOnly = false, $iContentId = f

$sWhere = '';
$sJoin = '';
$sOrder = '';
if ($isGhostsOnly) {
$aBindings['object'] = $this->_aObject['object'];

Expand All @@ -333,6 +334,8 @@ public function getFiles($mixedProfileId, $isGhostsOnly = false, $iContentId = f
}

$sJoin .= ')';

$sOrder = ' ORDER BY `g`.`order` ASC';
}
else {
if (is_array($mixedProfileId) && $mixedProfileId) {
Expand All @@ -345,7 +348,7 @@ public function getFiles($mixedProfileId, $isGhostsOnly = false, $iContentId = f
}
}

$sQuery = "SELECT `f`.* FROM " . $this->_sTableFiles . " AS `f` " . $sJoin . $sWhere . " ORDER BY `g`.`order` ASC";
$sQuery = "SELECT `f`.* FROM " . $this->_sTableFiles . " AS `f` " . $sJoin . $sWhere . $sOrder;
return $this->getAll($sQuery, $aBindings);
}

Expand Down
3 changes: 1 addition & 2 deletions modules/base/text/classes/BxBaseModTextTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -786,8 +786,7 @@ protected function _getHeaderImage($aData)

function mediaExif ($aMediaInfo, $iProfileId = false, $sFuncAuthorDesc = '', $sTemplateName = 'media-exif.html')
{

if (!$aMediaInfo['exif'])
if (empty($aMediaInfo['exif']))
return '';

$a = unserialize($aMediaInfo['exif']);
Expand Down
1 change: 1 addition & 0 deletions modules/boonex/albums/classes/BxAlbumsConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ function __construct($aModule)
'OBJECT_FORM_ENTRY_DISPLAY_DELETE' => 'bx_albums_entry_delete',
'OBJECT_FORM_MEDIA' => 'bx_albums_media',
'OBJECT_FORM_MEDIA_DISPLAY_EDIT' => 'bx_albums_media_edit',
'OBJECT_FORM_MEDIA_DISPLAY_MOVE' => 'bx_albums_media_move',
'OBJECT_MENU_ACTIONS_VIEW_ENTRY' => 'bx_albums_view', // actions menu on view entry page
'OBJECT_MENU_ACTIONS_VIEW_ENTRY_ALL' => 'bx_albums_view_actions', // all actions menu on view entry page
'OBJECT_MENU_ACTIONS_VIEW_MEDIA' => 'bx_albums_view_media', // actions menu on view media page
Expand Down
72 changes: 72 additions & 0 deletions modules/boonex/albums/classes/BxAlbumsFormMedia.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php defined('BX_DOL') or die('hack attempt');
/**
* Copyright (c) UNA, Inc - https://una.io
* MIT License - https://opensource.org/licenses/MIT
*
* @defgroup Albums Albums
* @ingroup UnaModules
*
* @{
*/

/**
* Create/Edit entry form
*/
class BxAlbumsFormMedia extends BxTemplFormView
{
protected $_sModule;
protected $_oModule;

protected $_iMediaId;
protected $_aMediaInfo;

public function __construct($aInfo, $oTemplate = false)
{
$this->_sModule = 'bx_albums';
$this->_oModule = BxDolModule::getInstance($this->_sModule);

parent::__construct($aInfo, $oTemplate);
}

public function initChecker($aValues = array (), $aSpecificValues = array())
{
if(!empty($this->_aMediaInfo) && is_array($this->_aMediaInfo))
$aValues = $this->_aMediaInfo;

parent::initChecker($aValues, $aSpecificValues);
}

public function initForm($aAction, $iMediaId)
{
$CNF = &$this->_oModule->_oConfig->CNF;

$this->_iMediaId = $iMediaId;
$this->_aMediaInfo = $this->_oModule->_oDb->getMediaInfoById($iMediaId);

$this->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oModule->_oConfig->getBaseUri() . $aAction . '_media/' . $iMediaId;

if(isset($this->aInputs['content_id'])) {
$aAlbums = $this->_oModule->_oDb->getEntriesBy(array('type' => 'author', 'author' => $this->_aMediaInfo['author']));
foreach($aAlbums as $aAlbum)
$this->aInputs['content_id']['values'][] = ['key' => $aAlbum[$CNF['FIELD_ID']], 'value' => $aAlbum[$CNF['FIELD_TITLE']]];
}
}

public function update($val, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null)
{
$CNF = &$this->_oModule->_oConfig->CNF;

$sField = 'content_id';
if(isset($this->aInputs[$sField])) {
$iContentId = $this->getCleanValue($sField);

$oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
if(!$oStorage->updateGhostsContentId($this->_aMediaInfo['file_id'], $this->_aMediaInfo['author'], $iContentId))
return false;
}

return parent::update($val, $aValsToAdd, $aTrackTextFieldsChanges);
}
}

/** @} */
11 changes: 10 additions & 1 deletion modules/boonex/albums/classes/BxAlbumsMenuViewActionsMedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,16 @@ protected function _getMenuItemEditImage($aItem)
));
}

protected function _getMenuItemDeleteImage($aItem)
protected function _getMenuItemDeleteImage($aItem)
{
$CNF = &$this->_oModule->_oConfig->CNF;

return $this->_getMenuItemByNameActions($aItem, array(
'object_menu' => $CNF['OBJECT_MENU_ACTIONS_VIEW_MEDIA']
));
}

protected function _getMenuItemMoveImage($aItem)
{
$CNF = &$this->_oModule->_oConfig->CNF;

Expand Down
39 changes: 32 additions & 7 deletions modules/boonex/albums/classes/BxAlbumsModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -715,11 +715,10 @@ public function actionEditMedia($iMediaId)
$CNF = &$this->_oConfig->CNF;

$iMediaId = (int)$iMediaId;
$aMediaInfo = $this->_oDb->getMediaInfoById($iMediaId);

$oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_MEDIA'], $CNF['OBJECT_FORM_MEDIA_DISPLAY_EDIT']);
$oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'edit_media/' . $iMediaId;
$oForm->initChecker($aMediaInfo);
$oForm->initForm('edit', $iMediaId);
$oForm->initChecker();

if($oForm->isSubmittedAndValid()) {
if($oForm->update($iMediaId) !== false)
Expand All @@ -738,18 +737,44 @@ public function actionEditMedia($iMediaId)
echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))));
}


public function actionDeleteMedia($iMediaId)
public function actionDeleteMedia($iMediaId)
{
$CNF = &$this->_oConfig->CNF;

$aMediaInfo = $this->_oDb->getMediaInfoById($iMediaId);
$oUploader = BxDolUploader::getObjectInstance($CNF['OBJECT_UPLOADERS'][0], $CNF['OBJECT_STORAGE'], '');
$aMediaInfo = $this->_oDb->getMediaInfoById($iMediaId);
$oUploader = BxDolUploader::getObjectInstance($CNF['OBJECT_UPLOADERS'][0], $CNF['OBJECT_STORAGE'], '');
$oUploader->deleteGhost($aMediaInfo['file_id'], bx_get_logged_profile_id());

echoJson(['redirect' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aMediaInfo['content_id'])]);
}

public function actionMoveMedia($iMediaId)
{
$CNF = &$this->_oConfig->CNF;

$iMediaId = (int)$iMediaId;

$oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_MEDIA'], $CNF['OBJECT_FORM_MEDIA_DISPLAY_MOVE']);
$oForm->initForm('move', $iMediaId);
$oForm->initChecker();

if($oForm->isSubmittedAndValid()) {
if($oForm->update($iMediaId) !== false)
$aRes = array('reload' => 1);
else
$aRes = array('msg' => _t('_bx_albums_txt_err_cannot_perform_action'));

return echoJson($aRes);
}

$sContent = BxTemplStudioFunctions::getInstance()->transBox('bx-albums-move-media-popup', $this->_oTemplate->parseHtmlByName('media-edit.html', array(
'form_id' => $oForm->aFormAttrs['id'],
'form' => $oForm->getCode(true)
)));

echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))));
}

public function actionGetSiblingMedia($iMediaId, $mixedContext)
{
$aSiblings = false;
Expand Down
9 changes: 7 additions & 2 deletions modules/boonex/albums/install/langs/en.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@

<string name="_bx_albums_form_media"><![CDATA[Medias]]></string>
<string name="_bx_albums_form_media_display_edit"><![CDATA[Edit Media]]></string>
<string name="_bx_albums_form_media_display_move"><![CDATA[Move Media]]></string>
<string name="_bx_albums_form_media_input_sys_title"><![CDATA[Caption]]></string>
<string name="_bx_albums_form_media_input_title"><![CDATA[Caption]]></string>
<string name="_bx_albums_form_media_input_sys_content_id"><![CDATA[Album]]></string>
<string name="_bx_albums_form_media_input_content_id"><![CDATA[Album]]></string>
<string name="_bx_albums_form_media_input_sys_do_submit"><![CDATA[Submit]]></string>
<string name="_bx_albums_form_media_input_do_submit"><![CDATA[Submit]]></string>
<string name="_bx_albums_form_media_input_sys_do_cancel"><![CDATA[Cancel]]></string>
Expand Down Expand Up @@ -197,8 +200,10 @@
<string name="_bx_albums_menu_item_title_add_images"><![CDATA[Add/Edit Pictures]]></string>
<string name="_bx_albums_menu_item_title_system_edit_image"><![CDATA[Edit Image]]></string>
<string name="_bx_albums_menu_item_title_edit_image"><![CDATA[Edit Image]]></string>
<string name="_bx_albums_menu_item_title_system_delete_image"><![CDATA[Delete Image]]></string>
<string name="_bx_albums_menu_item_title_delete_image"><![CDATA[Delete Image]]></string>
<string name="_bx_albums_menu_item_title_system_delete_image"><![CDATA[Delete Image]]></string>
<string name="_bx_albums_menu_item_title_delete_image"><![CDATA[Delete Image]]></string>
<string name="_bx_albums_menu_item_title_system_move_image"><![CDATA[Move Image To]]></string>
<string name="_bx_albums_menu_item_title_move_image"><![CDATA[Move Image To]]></string>
<string name="_bx_albums_menu_item_title_system_delete_entry"><![CDATA[Delete]]></string>
<string name="_bx_albums_menu_item_title_delete_entry"><![CDATA[Delete]]></string>
<string name="_bx_albums_menu_item_title_system_view_entry"><![CDATA[View Album]]></string>
Expand Down
4 changes: 3 additions & 1 deletion modules/boonex/albums/install/sql/enable.sql
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@ INSERT INTO `sys_menu_items`(`set_name`, `module`, `name`, `title_system`, `titl
('bx_albums_view_media', 'bx_albums', 'add-images-to-album', '_bx_albums_menu_item_title_system_add_images', '_bx_albums_menu_item_title_add_images', 'page.php?i=add-images&id={content_id}', '', '', 'plus', '', 2147483647, 1, 0, 10),
('bx_albums_view_media', 'bx_albums', 'edit-album', '_bx_albums_menu_item_title_system_edit_album', '_bx_albums_menu_item_title_edit_album', 'page.php?i=edit-album&id={content_id}', '', '', 'pencil-alt', '', 2147483647, 1, 0, 20),
('bx_albums_view_media', 'bx_albums', 'edit-image', '_bx_albums_menu_item_title_system_edit_image', '_bx_albums_menu_item_title_edit_image', 'javascript:void(0)', 'javascript:{js_object}.editMedia(this, {media_id});', '', 'pencil-alt', '', 2147483647, 1, 0, 30),
('bx_albums_view_media', 'bx_albums', 'delete-image', '_bx_albums_menu_item_title_system_delete_image', '_bx_albums_menu_item_title_delete_image', 'javascript:void(0)', 'javascript:{js_object}.deleteMedia(this, {media_id});', '', 'remove', '', 2147483647, 1, 0, 40);
('bx_albums_view_media', 'bx_albums', 'delete-image', '_bx_albums_menu_item_title_system_delete_image', '_bx_albums_menu_item_title_delete_image', 'javascript:void(0)', 'javascript:{js_object}.deleteMedia(this, {media_id});', '', 'remove', '', 2147483647, 1, 0, 40),
('bx_albums_view_media', 'bx_albums', 'move-image', '_bx_albums_menu_item_title_system_move_image', '_bx_albums_menu_item_title_move_image', 'javascript:void(0)', 'javascript:{js_object}.moveMedia(this, {media_id});', '', 'exchange-alt', '', 2147483647, 1, 0, 50);


-- MENU: all actions menu for view media page
Expand All @@ -291,6 +292,7 @@ INSERT INTO `sys_menu_items`(`set_name`, `module`, `name`, `title_system`, `titl
('bx_albums_view_actions_media', 'bx_albums', 'edit-album', '_bx_albums_menu_item_title_system_edit_album', '', '', '', '', '', '', '', 0, 2147483647, 0, 0, 20),
('bx_albums_view_actions_media', 'bx_albums', 'edit-image', '_bx_albums_menu_item_title_system_edit_image', '', '', '', '', '', '', '', 0, 2147483647, 1, 0, 30),
('bx_albums_view_actions_media', 'bx_albums', 'delete-image', '_bx_albums_menu_item_title_system_delete_image', '', '', '', '', '', '', '', 0, 2147483647, 1, 0, 40),
('bx_albums_view_actions_media', 'bx_albums', 'move-image', '_bx_albums_menu_item_title_system_move_image', '', '', '', '', '', '', '', 0, 2147483647, 1, 0, 50),
('bx_albums_view_actions_media', 'bx_albums', 'comment', '_sys_menu_item_title_system_va_comment', '', '', '', '', '', '', '', 0, 2147483647, 0, 0, 200),
('bx_albums_view_actions_media', 'bx_albums', 'view', '_sys_menu_item_title_system_va_view', '', '', '', '', '', '', '', 0, 2147483647, 1, 0, 210),
('bx_albums_view_actions_media', 'bx_albums', 'vote', '_sys_menu_item_title_system_va_vote', '', '', '', '', '', '', '', 0, 2147483647, 1, 0, 220),
Expand Down
13 changes: 10 additions & 3 deletions modules/boonex/albums/install/sql/install.sql
Original file line number Diff line number Diff line change
Expand Up @@ -443,13 +443,15 @@ INSERT INTO `sys_form_display_inputs` (`display_name`, `input_name`, `visible_fo
('bx_albums_entry_delete', 'title', 2147483647, 0, 0);

INSERT INTO `sys_objects_form`(`object`, `module`, `title`, `action`, `form_attrs`, `table`, `key`, `uri`, `uri_title`, `submit_name`, `params`, `deletable`, `active`, `override_class_name`, `override_class_file`) VALUES
('bx_albums_media', 'bx_albums', '_bx_albums_form_media', '', 'a:1:{s:7:\"enctype\";s:19:\"multipart/form-data\";}', 'bx_albums_files2albums', 'id', '', '', 'do_submit', '', 0, 1, '', '');
('bx_albums_media', 'bx_albums', '_bx_albums_form_media', '', 'a:1:{s:7:\"enctype\";s:19:\"multipart/form-data\";}', 'bx_albums_files2albums', 'id', '', '', 'do_submit', '', 0, 1, 'BxAlbumsFormMedia', 'modules/boonex/albums/classes/BxAlbumsFormMedia.php');

INSERT INTO `sys_form_displays`(`object`, `display_name`, `module`, `view_mode`, `title`) VALUES
('bx_albums_media', 'bx_albums_media_edit', 'bx_albums', 0, '_bx_albums_form_media_display_edit');
('bx_albums_media', 'bx_albums_media_edit', 'bx_albums', 0, '_bx_albums_form_media_display_edit'),
('bx_albums_media', 'bx_albums_media_move', 'bx_albums', 0, '_bx_albums_form_media_display_move');

INSERT INTO `sys_form_inputs`(`object`, `module`, `name`, `value`, `values`, `checked`, `type`, `caption_system`, `caption`, `info`, `required`, `collapsed`, `html`, `attrs`, `attrs_tr`, `attrs_wrapper`, `checker_func`, `checker_params`, `checker_error`, `db_pass`, `db_params`, `editable`, `deletable`) VALUES
('bx_albums_media', 'bx_albums', 'title', '', '', 0, 'text', '_bx_albums_form_media_input_sys_title', '_bx_albums_form_media_input_title', '', 0, 0, 0, '', '', '', '', '', '', 'Xss', '', 1, 0),
('bx_albums_media', 'bx_albums', 'content_id', '', '', 0, 'select', '_bx_albums_form_media_input_sys_content_id', '_bx_albums_form_media_input_content_id', '', 0, 0, 0, '', '', '', '', '', '', 'Int', '', 1, 0),
('bx_albums_media', 'bx_albums', 'controls', '', 'do_submit,do_cancel', 0, 'input_set', '', '', '', 0, 0, 0, '', '', '', '', '', '', '', '', 0, 0),
('bx_albums_media', 'bx_albums', 'do_submit', '_bx_albums_form_media_input_do_submit', '', 0, 'submit', '_bx_albums_form_media_input_sys_do_submit', '', '', 0, 0, 0, '', '', '', '', '', '', '', '', 1, 0),
('bx_albums_media', 'bx_albums', 'do_cancel', '_bx_albums_form_media_input_do_cancel', '', 0, 'button', '_bx_albums_form_media_input_sys_do_cancel', '', '', 0, 0, 0, 'a:2:{s:7:"onclick";s:45:"$(''.bx-popup-applied:visible'').dolPopupHide()";s:5:"class";s:22:"bx-def-margin-sec-left";}', '', '', '', '', '', '', '', 0, 0);
Expand All @@ -458,7 +460,12 @@ INSERT INTO `sys_form_display_inputs` (`display_name`, `input_name`, `visible_fo
('bx_albums_media_edit', 'title', 2147483647, 1, 1),
('bx_albums_media_edit', 'controls', 2147483647, 1, 2),
('bx_albums_media_edit', 'do_submit', 2147483647, 1, 3),
('bx_albums_media_edit', 'do_cancel', 2147483647, 1, 4);
('bx_albums_media_edit', 'do_cancel', 2147483647, 1, 4),

('bx_albums_media_move', 'content_id', 2147483647, 1, 1),
('bx_albums_media_move', 'controls', 2147483647, 1, 2),
('bx_albums_media_move', 'do_submit', 2147483647, 1, 3),
('bx_albums_media_move', 'do_cancel', 2147483647, 1, 4);


-- COMMENTS
Expand Down
60 changes: 40 additions & 20 deletions modules/boonex/albums/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,31 +54,51 @@ BxAlbumsMain.prototype.editMedia = function(oButton, iId) {
);
};

BxAlbumsMain.prototype.onEditMedia = function(oData) {
if(oData && oData.content != undefined)
$('#' + this._oHtmlIds['subentry_votes'] + oData.content.subentry_id).html(oData.content.votes_formated);
};

BxAlbumsMain.prototype.deleteMedia = function(oButton, iId) {
var $this = this;

bx_confirm(_t('_Are_you_sure'), function() {
var oDate = new Date();
$this.loadingInButton(oButton, true);

$.get(
$this._sActionsUrl + 'delete_media/' + iId,
{
_t: oDate.getTime()
},
function(oData) {
$this.loadingInButton(oButton, false);

processJsonData(oData);
},
'json'
);
});
var oDate = new Date();
$this.loadingInButton(oButton, true);

$.get(
$this._sActionsUrl + 'delete_media/' + iId,
{
_t: oDate.getTime()
},
function(oData) {
$this.loadingInButton(oButton, false);

processJsonData(oData);
},
'json'
);
});
};

BxAlbumsMain.prototype.onEditMedia = function(oData) {
if(oData && oData.content != undefined)
$('#' + this._oHtmlIds['subentry_votes'] + oData.content.subentry_id).html(oData.content.votes_formated);
BxAlbumsMain.prototype.moveMedia = function(oButton, iId) {
var $this = this;
var oDate = new Date();

this.loadingInButton(oButton, true);

$.get(
this._sActionsUrl + 'move_media/' + iId,
{
_t: oDate.getTime()
},
function(oData) {
$this.loadingInButton(oButton, false);

processJsonData(oData);
},
'json'
);
};

BxAlbumsMain.prototype.loadingInButton = function(e, bShow) {
Expand Down
7 changes: 6 additions & 1 deletion modules/boonex/russian/data/langs/bx_albums/ru.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@

<string name="_bx_albums_form_media"><![CDATA[Изображения]]></string>
<string name="_bx_albums_form_media_display_edit"><![CDATA[Редактировать изображение]]></string>
<string name="_bx_albums_form_media_display_move"><![CDATA[Переместить изображение]]></string>
<string name="_bx_albums_form_media_input_sys_title"><![CDATA[Заголовок]]></string>
<string name="_bx_albums_form_media_input_title"><![CDATA[Заголовок]]></string>
<string name="_bx_albums_form_media_input_sys_content_id"><![CDATA[Альбом]]></string>
<string name="_bx_albums_form_media_input_content_id"><![CDATA[Альбом]]></string>
<string name="_bx_albums_form_media_input_sys_do_submit"><![CDATA[Опубликовать]]></string>
<string name="_bx_albums_form_media_input_do_submit"><![CDATA[Опубликовать]]></string>
<string name="_bx_albums_form_media_input_sys_do_cancel"><![CDATA[Отмена]]></string>
Expand Down Expand Up @@ -196,7 +199,9 @@
<string name="_bx_albums_menu_item_title_system_edit_image"><![CDATA[Изменить изображение]]></string>
<string name="_bx_albums_menu_item_title_edit_image"><![CDATA[Изменить изображение]]></string>
<string name="_bx_albums_menu_item_title_system_delete_image"><![CDATA[Удалить изображение]]></string>
<string name="_bx_albums_menu_item_title_delete_image"><![CDATA[Удалить изображение]]></string>
<string name="_bx_albums_menu_item_title_delete_image"><![CDATA[Удалить изображение]]></string>
<string name="_bx_albums_menu_item_title_system_move_image"><![CDATA[Переместить изображение в]]></string>
<string name="_bx_albums_menu_item_title_move_image"><![CDATA[Переместить изображение в]]></string>
<string name="_bx_albums_menu_item_title_system_delete_entry"><![CDATA[Удалить]]></string>
<string name="_bx_albums_menu_item_title_delete_entry"><![CDATA[Удалить]]></string>
<string name="_bx_albums_menu_item_title_system_view_entry"><![CDATA[Просмотреть альбом]]></string>
Expand Down

0 comments on commit 6e23bdb

Please sign in to comment.