123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <?php
- namespace Application\Migrations;
- use Chamilo\CoreBundle\Entity\SettingsCurrent;
- use Chamilo\CoreBundle\Entity\SettingsOptions;
- use Doctrine\DBAL\Migrations\AbstractMigration;
- use Doctrine\ORM\EntityManager;
- abstract class AbstractMigrationChamilo extends AbstractMigration
- {
- private $manager;
-
- public function setEntityManager(EntityManager $manager)
- {
- $this->manager = $manager;
- }
-
- public function getEntityManager()
- {
- if (empty($this->manager)) {
- $dbParams = array(
- 'driver' => 'pdo_mysql',
- 'host' => api_get_configuration_value('db_host'),
- 'user' => api_get_configuration_value('db_user'),
- 'password' => api_get_configuration_value('db_password'),
- 'dbname' => api_get_configuration_value('main_database')
- );
- $database = new \Database();
- $database->connect(
- $dbParams,
- __DIR__.'/../../',
- __DIR__.'/../../'
- );
- $this->manager = $database->getManager();
- }
- return $this->manager;
- }
-
- 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();
- }
- }
|