Skip to content

Commit

Permalink
Make video service settings form and video attachment form reflect th…
Browse files Browse the repository at this point in the history
…e service configurutaion in config file (closes: #15)
  • Loading branch information
mbohal committed Sep 2, 2020
1 parent 26635a8 commit a267ec4
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 40 deletions.
36 changes: 21 additions & 15 deletions application/models/Projects.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
<?php
/**
* Projects
* @author Markus Hackel
*
*/

class Model_Projects extends Dbjr_Db_Table_Abstract
{
protected $_name = 'proj';
Expand All @@ -13,7 +9,7 @@ class Model_Projects extends Dbjr_Db_Table_Abstract
* @var bool
*/
protected $videoServiceStatus;

/**
* Returns all entries from the proj table
*
Expand All @@ -29,18 +25,28 @@ public function getAll($order = '')

return $this->fetchAll($select);
}

/**
* @return bool
*/
public function getVideoServiceStatus()

public function getVideoServiceStatus(): bool
{
if ($this->videoServiceStatus === null) {
$project = (new Model_Projects())->find((new Zend_Registry())->get('systemconfig')->project)->current();
$this->videoServiceStatus = $project['video_facebook_enabled'] || $project['video_youtube_enabled']
|| $project['video_vimeo_enabled'];
$config = Zend_Registry::get('systemconfig');
$project = (new Model_Projects())->find(($config->project))->current();
$this->videoServiceStatus =
(
$project['video_facebook_enabled']
&& $config->webservice
&& $config->webservice->facebook
&& $config->webservice->facebook->appId
&& $config->webservice->facebook->appSecret
)
|| $project['video_youtube_enabled']
|| (
$project['video_vimeo_enabled']
&& $config->webservice
&& $config->webservice->vimeo
&& $config->webservice->vimeo->accessToken);
}

return $this->videoServiceStatus;
}
}
22 changes: 20 additions & 2 deletions application/modules/admin/controllers/InputController.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,26 @@ public function editAction()
} else {
$data = $inputRow;
if ($data['video_service'] !== null) {
$project = (new Model_Projects)->find((new Zend_Registry())->get('systemconfig')->project)->current();
if (!$project['video_' . $data['video_service'] . '_enabled']) {
$config = (new Zend_Registry())->get('systemconfig');
$project = (new Model_Projects)->find($config->project)->current();
$videoService = $data['video_service'];
if (!$project['video_' . $videoService . '_enabled']
|| (
$videoService === 'vimeo'
&& (!$config->webservice
|| !$config->webservice->vimeo
|| !$config->webservice->vimeo->accessToken
)
)
|| (
$videoService === 'facebook'
&& (!$config->webservice
|| !$config->webservice->facebook
|| !$config->webservice->facebook->appId
|| !$config->webservice->facebook->appSecret
)
)
) {
$data['video_service'] = null;
$data['video_id'] = null;
$this->_flashMessenger->addMessage(
Expand Down
48 changes: 32 additions & 16 deletions application/modules/admin/forms/Settings/Services.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,49 @@ public function init()
$this->videoServiceAccess = true;
$this->setAttrib('class', 'offset-bottom');

// Add Youtube video toggle
$youtube = $this->createElement('checkbox', 'video_youtube_enabled');
$youtube
->setLabel('YouTube')
->setRequired(false);
$this->addElement($youtube);

$systemConfig = (new Zend_Registry ())->get('systemconfig');
$webserviceConf = (new Zend_Registry ())->get('systemconfig')->webservice;

$vimeo = $this->createElement('checkbox', 'video_vimeo_enabled');
$vimeo
->setLabel('Vimeo')
->setRequired(false);
if (!isset($systemConfig->webservice) || !isset($systemConfig->webservice->vimeo)
|| !isset($systemConfig->webservice->vimeo->accessToken)) {
$vimeo->setAttrib('disabled', 'disabled');

// Add Vimeo video toggle
if ($webserviceConf
&& $webserviceConf->vimeo
&& $webserviceConf->vimeo->accessToken
) {
$vimeo = $this->createElement('checkbox', 'video_vimeo_enabled');
$vimeo
->setLabel('Vimeo')
->setRequired(false);
} else {
$vimeo = $this->createElement('checkbox', 'video_vimeo_enabled_placeholder');
$vimeo
->setLabel('Vimeo')
->setAttrib('disabled', 'disabled');
$this->videoServiceAccess = false;
}
$this->addElement($vimeo);

$facebook = $this->createElement('checkbox', 'video_facebook_enabled');
$facebook
->setLabel('Facebook')
->setRequired(false);
if (!isset($systemConfig->webservice) || !isset($systemConfig->webservice->facebook)
|| !isset($systemConfig->webservice->facebook->appId)
|| !isset($systemConfig->webservice->facebook->appSecret)) {
$facebook->setAttrib('disabled', 'disabled');
// Add Facebook video toggle
if ($webserviceConf
&& $webserviceConf->facebook
&& $webserviceConf->facebook->appId
&& $webserviceConf->facebook->appSecret
) {
$facebook = $this->createElement('checkbox', 'video_facebook_enabled');
$facebook
->setLabel('Facebook')
->setRequired(false);
} else {
$facebook = $this->createElement('checkbox', 'video_facebook_enabled_placeholder');
$facebook
->setLabel('Facebook')
->setAttrib('disabled', 'disabled');
$this->videoServiceAccess = false;
}
$this->addElement($facebook);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
<div class="content">

<h2><?=$this->translate('Services');?></h2>
<p class="alert alert-info">
<span class="glyphicon glyphicon-info-sign offset-right" aria-hidden="true"></span>
<?=$this->translate('Here you can specify available video services used for attaching of a video to contributions.');?>
</p>
<?php if (!$this->form->getVideosServiceAccess()) : ?>
<p class="alert alert-info">
<span class="glyphicon glyphicon-info-sign offset-right" aria-hidden="true"></span>
<?=$this->translate('In case one or more services are greyed out and cannot be activated, it is probably due to misconfiguration of service access applications in ePartool configuration files.');?>
</p>
<?php endif; ?>
<p class="alert alert-info">
<span class="glyphicon glyphicon-info-sign offset-right" aria-hidden="true"></span>
<?=$this->translate('Here you can specify available video services used for attaching of a video to contributions.');?>
</p>
<?=$this->form;?>
</div>
</div>
Expand Down
30 changes: 27 additions & 3 deletions library/Dbjr/Form/Element/VideoService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,38 @@

class Dbjr_Form_Element_VideoService extends Dbjr_Form_Element_Select
{
private function getVideoServices(): array
{
$webServiceConf = Zend_Registry::get('systemconfig')->webservice;
return [
'youtube' => [
'label' => 'YouTube',
'isActiveInConfig' => true, // does not need any configuration
],
'vimeo' => [
'label' => 'Vimeo',
'isActiveInConfig' => $webServiceConf
&& $webServiceConf->vimeo
&& $webServiceConf->vimeo->accessToken,
],
'facebook' => [
'label' => 'Facebook',
'isActiveInConfig' => $webServiceConf
&& $webServiceConf->facebook
&& $webServiceConf->facebook->appSecret
&& $webServiceConf->facebook->appId,
],
];
}

public function init()
{
$project = (new Model_Projects())->find((new Zend_Registry())->get('systemconfig')->project)->current();
$videoServiceOptions = [];
$urls = [];
foreach (['youtube' => 'YouTube', 'vimeo' => 'Vimeo', 'facebook' => 'Facebook'] as $service => $name) {
if ($project['video_' . $service . '_enabled']) {
$videoServiceOptions[$service] = $name;
foreach ($this->getVideoServices() as $service => $props) {
if ($project['video_' . $service . '_enabled'] && $props['isActiveInConfig']) {
$videoServiceOptions[$service] = $props['label'];
$urls[$service] = sprintf(Zend_Registry::get('systemconfig')->video->url->$service->format->link, '');
}
}
Expand Down

0 comments on commit a267ec4

Please sign in to comment.