<commit_before><?php


class dmDoctrineFormGenerator extends sfDoctrineFormGenerator
{
  protected
  $moduleManager;
  
  /**
   * Initializes the current sfGenerator instance.
   *
   * @param sfGeneratorManager $generatorManager A sfGeneratorManager instance
   */
  public function initialize(sfGeneratorManager $generatorManager)
  {
    parent::initialize($generatorManager);
    
    if (!dmContext::hasInstance())
    {
      dmContext::createInstance($generatorManager->getConfiguration());
    }
    
    $this->moduleManager = dmContext::getInstance()->getModuleManager();
    
    $this->setGeneratorClass('dmDoctrineForm');
  }

  public function generate($params = array())
  {
    $this->generateBaseClasses();
    
    $this->params = $params;

    if (!isset($this->params['model_dir_name']))
    {
      $this->params['model_dir_name'] = 'model';
    }

    if (!isset($this->params['form_dir_name']))
    {
      $this->params['form_dir_name'] = 'form';
    }

    $models = $this->loadModels();

    $pluginPaths = $this->generatorManager->getConfiguration()->getAllPluginPaths();

    // create a form class for every Doctrine class
    foreach ($models as $model)
    {
      $this->table = Doctrine_Core::getTable($model);
      $this->modelName = $model;

      if(!$useDmForm = $this->moduleManager->getModuleByModel($model))
      {
        foreach((array) $this->table->getOption('subclasses') as $subClass)
        {
          if($this->moduleManager->getModuleByModel($subClass))
          {
            $useDmForm = true;
            break;
          }
        }
      }

      $this->setGeneratorClass($useDmForm ? 'dmDoctrineForm' : 'sfDoctrineForm');
      
      $baseDir = sfConfig::get('sf_lib_dir') . '/form/doctrine';

      $isPluginModel = $this->isPluginModel($model);
      
      if ($isPluginModel)
      {
        $pluginName = $this->getPluginNameForModel($model);
        $baseDir .= '/' . $pluginName;
      }

      if (!is_dir($baseDir.'/base'))
      {
        mkdir($baseDir.'/base', 0777, true);
      }

      file_put_contents($baseDir.'/base/Base'.$model.'Form.class.php', $this->evalTemplate(null === $this->getParentModel() ? 'sfDoctrineFormGeneratedTemplate.php' : 'sfDoctrineFormGeneratedInheritanceTemplate.php'));

      if ($isPluginModel)
      {
        $pluginBaseDir = $pluginPaths[$pluginName].'/lib/form/doctrine';
        if (!file_exists($classFile = $pluginBaseDir.'/Plugin'.$model.'Form.class.php'))
        {
            if (!is_dir($pluginBaseDir))
            {
              mkdir($pluginBaseDir, 0777, true);
            }
            file_put_contents($classFile, $this->evalTemplate('sfDoctrineFormPluginTemplate.php'));
        }
      }
      if (!file_exists($classFile = $baseDir.'/'.$model.'Form.class.php'))
      {
        if ($isPluginModel)
        {
           file_put_contents($classFile, $this->evalTemplate('sfDoctrinePluginFormTemplate.php'));
        } else {
           file_put_contents($classFile, $this->evalTemplate('sfDoctrineFormTemplate.php'));
        }
      }
    }
  }
  <commit_msg>Fix form generation using Diem features when Doctrine concrete inheritance is used - Close #210<commit_after><?php


class dmDoctrineFormGenerator extends sfDoctrineFormGenerator
{
  protected
  $moduleManager;
  
  /**
   * Initializes the current sfGenerator instance.
   *
   * @param sfGeneratorManager $generatorManager A sfGeneratorManager instance
   */
  public function initialize(sfGeneratorManager $generatorManager)
  {
    parent::initialize($generatorManager);
    
    if (!dmContext::hasInstance())
    {
      dmContext::createInstance($generatorManager->getConfiguration());
    }
    
    $this->moduleManager = dmContext::getInstance()->getModuleManager();
    
    $this->setGeneratorClass('dmDoctrineForm');
  }

  public function generate($params = array())
  {
    $this->generateBaseClasses();
    
    $this->params = $params;

    if (!isset($this->params['model_dir_name']))
    {
      $this->params['model_dir_name'] = 'model';
    }

    if (!isset($this->params['form_dir_name']))
    {
      $this->params['form_dir_name'] = 'form';
    }

    $models = $this->loadModels();

    $pluginPaths = $this->generatorManager->getConfiguration()->getAllPluginPaths();

    // create a form class for every Doctrine class
    foreach ($models as $model)
    {
      $this->table = Doctrine_Core::getTable($model);
      $this->modelName = $model;

      if(!$useDmForm = $this->moduleManager->getModuleByModel($model))
      {
        /// find column_aggregation inheritance superclass
        foreach((array) $this->table->getOption('subclasses') as $subClass)
        {
          if($this->moduleManager->getModuleByModel($subClass))
          {
            $useDmForm = true;
            break;
          }
        }
        /// find concrete inheritance superclass
        if(!$useDmForm)
        {
          foreach($this->moduleManager->getModulesWithModel() as $module)
          {
            $r = new ReflectionClass($module->getModel());
            if ($r->isSubclassOf($model))
            {
              $useDmForm = true;
              break;
            }
          }
        }
      }

      $this->setGeneratorClass($useDmForm ? 'dmDoctrineForm' : 'sfDoctrineForm');
      
      $baseDir = sfConfig::get('sf_lib_dir') . '/form/doctrine';

      $isPluginModel = $this->isPluginModel($model);
      
      if ($isPluginModel)
      {
        $pluginName = $this->getPluginNameForModel($model);
        $baseDir .= '/' . $pluginName;
      }

      if (!is_dir($baseDir.'/base'))
      {
        mkdir($baseDir.'/base', 0777, true);
      }

      file_put_contents($baseDir.'/base/Base'.$model.'Form.class.php', $this->evalTemplate(null === $this->getParentModel() ? 'sfDoctrineFormGeneratedTemplate.php' : 'sfDoctrineFormGeneratedInheritanceTemplate.php'));

      if ($isPluginModel)
      {
        $pluginBaseDir = $pluginPaths[$pluginName].'/lib/form/doctrine';
        if (!file_exists($classFile = $pluginBaseDir.'/Plugin'.$model.'Form.class.php'))
        {
          if (!is_dir($pluginBaseDir))
          {
            mkdir($pluginBaseDir, 0777, true);
          }
          file_put_contents($classFile, $this->evalTemplate('sfDoctrineFormPluginTemplate.php'));
        }
      }
      if (!file_exists($classFile = $baseDir.'/'.$model.'Form.class.php'))
      {
        if ($isPluginModel)
        {
          file_put_contents($classFile, $this->evalTemplate('sfDoctrinePluginFormTemplate.php'));
        }
        else
        {
          file_put_contents($classFile, $this->evalTemplate('sfDoctrineFormTemplate.php'));
        }
      }
    }
  }
  
{'fraction_non_alphanumeric': 0.148380355276907, 'fraction_numerical': 0.0028362442155545602, 'mean_word_length': 2.633405639913232, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2558840', 'n_tokens_mistral': 1996, 'n_tokens_neox': 1947, 'n_words': 277}