BxAlbumsFormMedia.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup Albums Albums
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Create/Edit entry form
  13. */
  14. class BxAlbumsFormMedia extends BxTemplFormView
  15. {
  16. protected $_sModule;
  17. protected $_oModule;
  18. protected $_iMediaId;
  19. protected $_aMediaInfo;
  20. public function __construct($aInfo, $oTemplate = false)
  21. {
  22. $this->_sModule = 'bx_albums';
  23. $this->_oModule = BxDolModule::getInstance($this->_sModule);
  24. parent::__construct($aInfo, $oTemplate);
  25. }
  26. public function initChecker($aValues = array (), $aSpecificValues = array())
  27. {
  28. if(!empty($this->_aMediaInfo) && is_array($this->_aMediaInfo))
  29. $aValues = $this->_aMediaInfo;
  30. parent::initChecker($aValues, $aSpecificValues);
  31. }
  32. public function initForm($aAction, $iMediaId)
  33. {
  34. $CNF = &$this->_oModule->_oConfig->CNF;
  35. $this->_iMediaId = $iMediaId;
  36. $this->_aMediaInfo = $this->_oModule->_oDb->getMediaInfoById($iMediaId);
  37. if(bx_is_dynamic_request())
  38. $this->aFormAttrs['action'] = $this->_oModule->_oConfig->getBaseUri() . $aAction . '_media/' . $iMediaId;
  39. else
  40. $this->aFormAttrs['action'] = BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_' . strtoupper($aAction) . '_MEDIA'] . '&id=' . $iMediaId);
  41. $this->aFormAttrs['action'] = bx_absolute_url($this->aFormAttrs['action']);
  42. if(isset($this->aInputs['content_id'])) {
  43. $aAlbums = $this->_oModule->_oDb->getEntriesBy(array('type' => 'author', 'author' => $this->_aMediaInfo['author']));
  44. foreach($aAlbums as $aAlbum)
  45. $this->aInputs['content_id']['values'][] = ['key' => $aAlbum[$CNF['FIELD_ID']], 'value' => $aAlbum[$CNF['FIELD_TITLE']]];
  46. }
  47. }
  48. public function update($val, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null)
  49. {
  50. $CNF = &$this->_oModule->_oConfig->CNF;
  51. $sField = 'content_id';
  52. if(isset($this->aInputs[$sField])) {
  53. $iContentId = $this->getCleanValue($sField);
  54. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  55. if(!$oStorage->updateGhostsContentId($this->_aMediaInfo['file_id'], $this->_aMediaInfo['author'], $iContentId))
  56. return false;
  57. }
  58. return parent::update($val, $aValsToAdd, $aTrackTextFieldsChanges);
  59. }
  60. }
  61. /** @} */