123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- <?php
- /* For licensing terms, see /license.txt */
- namespace Application\Migrations;
- use Chamilo\CoreBundle\Entity\SettingsCurrent;
- use Chamilo\CoreBundle\Entity\SettingsOptions;
- use Doctrine\DBAL\Migrations\AbstractMigration;
- use Doctrine\ORM\EntityManager;
- /**
- * Class AbstractMigrationChamilo
- *
- * @package Chamilo\CoreBundle\Migrations
- */
- abstract class AbstractMigrationChamilo extends AbstractMigration
- {
- private $manager;
- /**
- * @param EntityManager $manager
- */
- public function setEntityManager(EntityManager $manager)
- {
- $this->manager = $manager;
- }
- /**
- * @return EntityManager
- */
- public function getEntityManager()
- {
- if (empty($this->manager)) {
- $dbParams = array(
- 'driver' => 'pdo_mysql',
- 'host' => $this->connection->getHost(),
- 'user' => $this->connection->getUsername(),
- 'password' => $this->connection->getPassword(),
- 'dbname' => $this->connection->getDatabase(),
- 'port' => $this->connection->getPort()
- );
- $database = new \Database();
- $database->connect(
- $dbParams,
- __DIR__.'/../../',
- __DIR__.'/../../'
- );
- $this->manager = $database->getManager();
- }
- return $this->manager;
- }
- /**
- * Speeds up SettingsCurrent creation
- * @param string $variable The variable itself
- * @param string $subKey The subkey
- * @param string $type The type of setting (text, radio, select, etc)
- * @param string $category The category (Platform, User, etc)
- * @param string $selectedValue The default value
- * @param string $title The setting title string name
- * @param string $comment The setting comment string name
- * @param string $scope The scope
- * @param string $subKeyText Text if there is a subKey
- * @param int $accessUrl What URL it is for
- * @param bool $accessUrlChangeable Whether it can be changed on each url
- * @param bool $accessUrlLocked Whether the setting for the current URL is
- * locked to the current value
- * @param array $options Optional array in case of a radio-type field,
- * to insert options
- */
- public function addSettingCurrent(
- $variable,
- $subKey,
- $type,
- $category,
- $selectedValue,
- $title,
- $comment,
- $scope = '',
- $subKeyText = '',
- $accessUrl = 1,
- $accessUrlChangeable = false,
- $accessUrlLocked = true,
- $options = array()
- ) {
- $setting = new SettingsCurrent();
- $setting
- ->setVariable($variable)
- ->setSubkey($subKey)
- ->setType($type)
- ->setCategory($category)
- ->setSelectedValue($selectedValue)
- ->setTitle($title)
- ->setComment($comment)
- ->setScope($scope)
- ->setSubkeytext($subKeyText)
- ->setAccessUrl($accessUrl)
- ->setAccessUrlChangeable($accessUrlChangeable)
- ->setAccessUrlLocked($accessUrlLocked);
- $this->getEntityManager()->persist($setting);
- if (count($options) > 0) {
- foreach ($options as $option) {
- if (empty($option['text'])) {
- if ($option['value'] == 'true') {
- $option['text'] = 'Yes';
- } else {
- $option['text'] = 'No';
- }
- }
- $settingOption = new SettingsOptions();
- $settingOption
- ->setVariable($variable)
- ->setValue($option['value'])
- ->setDisplayText($option['text']);
- $this->getEntityManager()->persist($settingOption);
- }
- }
- $this->getEntityManager()->flush();
- }
- /**
- * @param string $variable
- * @return mixed
- */
- public function getConfigurationValue($variable)
- {
- global $_configuration;
- if (isset($_configuration[$variable])) {
- return $_configuration[$variable];
- }
- return false;
- }
- /**
- * Remove a setting completely
- * @param string $variable The setting variable name
- * @return void
- */
- public function removeSettingCurrent($variable)
- {
- //to be implemented
- }
- }
|