WIP ChamiloApi adding "ChamiloApi::getConfigurationValue()" function

remotes/angel/1.11.x
jmontoyaa 8 years ago
parent a3279f9217
commit d9d1869ce2
  1. 9
      app/AppKernel.php
  2. 63
      main/admin/configure_extensions.php
  3. 12
      main/inc/global.inc.php
  4. 33
      src/Chamilo/CoreBundle/Component/Utils/ChamiloApi.php

@ -3,6 +3,7 @@
use Symfony\Component\HttpKernel\Kernel; use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface; use Symfony\Component\Config\Loader\LoaderInterface;
use Chamilo\CoreBundle\Component\Utils\ChamiloApi;
/** /**
* Class AppKernel * Class AppKernel
@ -203,5 +204,13 @@ class AppKernel extends Kernel
{ {
return $this->getRealRootDir().'app/config/configuration.php'; return $this->getRealRootDir().'app/config/configuration.php';
} }
/**
* @param array $configuration
*/
public function setApi(array $configuration)
{
new ChamiloApi($configuration);
}
} }

@ -31,7 +31,8 @@ if (isset($_POST['activeExtension'])) {
while($row = Database::fetch_array($rs)){ while($row = Database::fetch_array($rs)){
if(!empty($_POST['visio_host'])) { if(!empty($_POST['visio_host'])) {
$tool_table = Database::get_course_table(TABLE_TOOL_LIST); $tool_table = Database::get_course_table(TABLE_TOOL_LIST);
$select = "SELECT id FROM $tool_table WHERE c_id =".$row['id']." AND name='".TOOL_VISIO_CONFERENCE."'"; $select = "SELECT id FROM $tool_table
WHERE c_id =".$row['id']." AND name='".TOOL_VISIO_CONFERENCE."'";
$selectres = Database::query($select); $selectres = Database::query($select);
if (Database::num_rows($selectres)<1) { if (Database::num_rows($selectres)<1) {
$sql = 'INSERT INTO '.$tool_table.' SET $sql = 'INSERT INTO '.$tool_table.' SET
@ -46,9 +47,10 @@ if (isset($_POST['activeExtension'])) {
category="interaction"'; category="interaction"';
Database::query($sql); Database::query($sql);
} }
$select = "SELECT id FROM $tool_table WHERE c_id =".$row['id']." AND name='".TOOL_VISIO_CLASSROOM."'"; $select = "SELECT id FROM $tool_table
WHERE c_id =".$row['id']." AND name='".TOOL_VISIO_CLASSROOM."'";
$selectres = Database::query($select); $selectres = Database::query($select);
if(Database::num_rows($selectres)<1) { if (Database::num_rows($selectres) < 1) {
$sql = 'INSERT INTO '.$tool_table.' SET $sql = 'INSERT INTO '.$tool_table.' SET
c_id = '.$row['id'].', c_id = '.$row['id'].',
name="'.TOOL_VISIO_CLASSROOM.'", name="'.TOOL_VISIO_CLASSROOM.'",
@ -90,12 +92,12 @@ if (isset($_POST['activeExtension'])) {
AND subkey="visio_use_rtmpt"'; AND subkey="visio_use_rtmpt"';
$rs = Database::query($sql); $rs = Database::query($sql);
if(empty($message)) { if (empty($message)) {
$message = get_lang('ServiceReconfigured'); $message = get_lang('ServiceReconfigured');
} }
break; break;
case 'ppt2lp' : case 'ppt2lp':
$sql = 'UPDATE '.$tbl_settings_current.' SET $sql = 'UPDATE '.$tbl_settings_current.' SET
selected_value="true" selected_value="true"
WHERE variable="service_ppt2lp" WHERE variable="service_ppt2lp"
@ -142,13 +144,10 @@ if (isset($_POST['activeExtension'])) {
WHERE variable="service_ppt2lp" WHERE variable="service_ppt2lp"
AND subkey="size"'; AND subkey="size"';
Database::query($sql); Database::query($sql);
break; break;
} }
} }
$listActiveServices = array(); $listActiveServices = array();
// get the list of active services // get the list of active services
@ -163,14 +162,11 @@ while($row = Database::fetch_array($rs)){
// javascript to handle accordion behaviour // javascript to handle accordion behaviour
$javascript_message = ''; $javascript_message = '';
if(!empty($message)){ if(!empty($message)){
$javascript_message = $javascript_message = '
'
document.getElementById("message").style.display = "block"; document.getElementById("message").style.display = "block";
var timer = setTimeout(hideMessage,5000); var timer = setTimeout(hideMessage, 5000);';
';
} }
$htmlHeadXtra[]= ' $htmlHeadXtra[]= '<script>
<script type="text/javascript">
var listeDiv; var listeDiv;
var extensionsHeader = new Array(); var extensionsHeader = new Array();
var extensionsContent = new Array(); var extensionsContent = new Array();
@ -305,56 +301,50 @@ Display::display_header($nameTool);
<div class="col-md-7"> <div class="col-md-7">
<form method="POST" class="form-horizontal" action="<?php echo api_get_self(); ?>"> <form method="POST" class="form-horizontal" action="<?php echo api_get_self(); ?>">
<?php <?php
$form = new FormValidator('ppt2lp'); $form = new FormValidator('ppt2lp');
$form -> addElement('text', 'host', get_lang('Host')); $form->addElement('text', 'host', get_lang('Host'));
//$form -> addElement('html','<br /><br />'); //$form -> addElement('html','<br /><br />');
$form -> addElement('text', 'port', get_lang('Port')); $form->addElement('text', 'port', get_lang('Port'));
//$form -> addElement('html','<br /><br />'); //$form -> addElement('html','<br /><br />');
$form -> addElement('text', 'user', get_lang('UserOnHost')); $form->addElement('text', 'user', get_lang('UserOnHost'));
//$form -> addElement('html','<br /><br />'); //$form -> addElement('html','<br /><br />');
$form -> addElement('text', 'ftp_password', get_lang('FtpPassword')); $form->addElement('text', 'ftp_password', get_lang('FtpPassword'));
//$form -> addElement('html','<br /><br />'); //$form -> addElement('html','<br /><br />');
$form -> addElement('text', 'path_to_lzx', get_lang('PathToLzx')); $form->addElement('text', 'path_to_lzx', get_lang('PathToLzx'));
//$form -> addElement('html','<br /><br />'); //$form -> addElement('html','<br /><br />');
$options = ChamiloApi::getDocumentConversionSizes(); $options = ChamiloApi::getDocumentConversionSizes();
$form -> addElement('select', 'size', get_lang('SlideSize'), $options); $form->addElement('select', 'size', get_lang('SlideSize'), $options);
$form->addElement('hidden', 'extension_code', 'ppt2lp');
$form -> addElement('hidden', 'extension_code', 'ppt2lp');
$defaults = array(); $defaults = array();
$renderer = $form -> defaultRenderer(); $renderer = $form->defaultRenderer();
$renderer -> setElementTemplate('<div style="text-align:left">{label}</div><div style="text-align:left">{element}</div>'); $renderer->setElementTemplate(
//$form -> addElement('html','<br /><br />'); '<div style="text-align:left">{label}</div><div style="text-align:left">{element}</div>'
if(in_array('service_ppt2lp',$listActiveServices)) );
{ if (in_array('service_ppt2lp', $listActiveServices)) {
$sql = 'SELECT subkey, selected_value FROM '.$tbl_settings_current.' $sql = 'SELECT subkey, selected_value FROM '.$tbl_settings_current.'
WHERE variable = "service_ppt2lp" WHERE variable = "service_ppt2lp"
AND subkey <> "active"'; AND subkey <> "active"';
$rs = Database::query($sql); $rs = Database::query($sql);
while($row = Database::fetch_array($rs,'ASSOC')) while ($row = Database::fetch_array($rs, 'ASSOC')) {
{
$defaults[$row['subkey']] = $row['selected_value']; $defaults[$row['subkey']] = $row['selected_value'];
} }
$form->addButtonSave(get_lang('ReconfigureExtension'), 'activeExtension'); $form->addButtonSave(get_lang('ReconfigureExtension'), 'activeExtension');
} } else {
else {
$defaults['host'] = 'localhost'; $defaults['host'] = 'localhost';
$defaults['port'] = '2002'; $defaults['port'] = '2002';
$defaults['size'] = '720x540'; $defaults['size'] = '720x540';
$form->addButtonSave(get_lang('ActivateExtension'), 'activeExtension'); $form->addButtonSave(get_lang('ActivateExtension'), 'activeExtension');
} }
$form -> setDefaults($defaults); $form->setDefaults($defaults);
$form -> display(); $form->display();
echo '<br />'; echo '<br />';
?> ?>
</form> </form>
</div> </div>
</div> </div>
</div> </div>
<?php <?php
/* /*
<!-- EPHORUS --> <!-- EPHORUS -->
@ -497,6 +487,5 @@ Display::display_header($nameTool);
*/ ?> */ ?>
</div><!-- /content --> </div><!-- /content -->
<?php <?php
Display::display_footer(); Display::display_footer();

@ -4,20 +4,14 @@
/** /**
* It is recommended that ALL Chamilo scripts include this important file. * It is recommended that ALL Chamilo scripts include this important file.
* This script manages * This script manages
* - http get, post, post_files, session, server-vars extraction into global namespace; * - include of /app/config/configuration.php;
* (which doesn't occur anymore when servertype config setting is set to test, * - include of several libraries: api, database, display, text, security;
* and which will disappear completely in Dokeos 1.6.1)
* - include of /conf/configuration.php;
* - include of several libraries: main_api, database, display, text, security;
* - selecting the main database; * - selecting the main database;
* - include of language files. * - include of language files.
* *
* @package chamilo.include * @package chamilo.include
* @todo isn't configuration.php renamed to configuration.inc.php yet?
* @todo use the $_configuration array for all the needed variables
* @todo remove the code that displays the button that links to the install page * @todo remove the code that displays the button that links to the install page
* but use a redirect immediately. By doing so the $alreadyInstalled variable can be removed. * but use a redirect immediately. By doing so the $alreadyInstalled variable can be removed.
* @todo make it possible to enable / disable the tracking through the Chamilo config page.
* *
*/ */
@ -53,6 +47,8 @@ if (file_exists($kernel->getConfigurationFile())) {
} }
} }
$kernel->setApi($_configuration);
// Ensure that _configuration is in the global scope before loading // Ensure that _configuration is in the global scope before loading
// main_api.lib.php. This is particularly helpful for unit tests // main_api.lib.php. This is particularly helpful for unit tests
if (!isset($GLOBALS['_configuration'])) { if (!isset($GLOBALS['_configuration'])) {

@ -9,26 +9,40 @@ namespace Chamilo\CoreBundle\Component\Utils;
*/ */
class ChamiloApi class ChamiloApi
{ {
private $configuration; private static $configuration;
private static $instance = null;
protected function __construct($configuration) /**
* ChamiloApi constructor.
* @param $configuration
*/
public function __construct(array $configuration)
{
self::$configuration = $configuration;
}
/**
* @return array
*/
public static function getConfigurationArray()
{ {
$this->configuration = $configuration; return self::$configuration;
} }
/** /**
* @return ChamiloApi|null * @param string $variable
* @return bool|string
*/ */
public function getInstance($configuration = null) public static function getConfigurationValue($variable)
{ {
if (is_null(self::$instance)) { $configuration = self::getConfigurationArray();
self::$instance = new ChamiloApi($configuration); if (array_key_exists($variable, $configuration)) {
return $configuration[$variable];
} }
return self::$instance; return false;
} }
/** /**
* Returns an array of resolutions that can be used for the conversion of documents to images * Returns an array of resolutions that can be used for the conversion of documents to images
* @return array * @return array
@ -49,5 +63,4 @@ class ChamiloApi
); );
} }
} }

Loading…
Cancel
Save