<commit_before><?php

class Doctrine_Template_Listener_DmSortable extends Doctrine_Record_Listener
{

  public function __construct($options = array())
  {
    $this->_options = array_merge(array('new' => 'first'), $this->_options, $options);
    
    if (!in_array($this->_options['new'], array('first', 'last')))
    {
      throw new dmException($this->_options['new'].' is not a valid new record insertion method ( first, last )');
    }
  }

  public function postInsert(Doctrine_Event $event)
  {
    if ('first' === $this->_options['new'])
    {
      $position = $event->getInvoker()->getTable()->createQuery('r')
      ->select('MIN(r.position)')
      ->fetchValue()
      - 1;
    }
    else
    {
      $position = $event->getInvoker()->get('id');
    }
    
    $event->getInvoker()->set('position', $position);
    $event->getInvoker()->save();
  }
}<commit_msg>Improved extension Doctrine for the position: when the object is new and the value position was already valued, this value was not recorded into the database. This is not the case, now ;)<commit_after><?php

class Doctrine_Template_Listener_DmSortable extends Doctrine_Record_Listener
{

  public function __construct($options = array())
  {
    $this->_options = array_merge(array('new' => 'first'), $this->_options, $options);
    
    if (!in_array($this->_options['new'], array('first', 'last')))
    {
      throw new dmException($this->_options['new'].' is not a valid new record insertion method ( first, last )');
    }
  }

  public function postInsert(Doctrine_Event $event)
  {
    if (is_null($event->getInvoker()->get('position')))
    {
      if ('first' === $this->_options['new'])
      {
        $position = $event->getInvoker()->getTable()->createQuery('r')
        ->select('MIN(r.position)')
        ->fetchValue()
        - 1;
      }
      else
      {
        $position = $event->getInvoker()->get('id');
      }
    }
    else
    {
      $position = $event->getInvoker()->get('position');
    }
    
    $event->getInvoker()->set('position', $position);
    $event->getInvoker()->save();
  }
}
{'fraction_non_alphanumeric': 0.1781279847182426, 'fraction_numerical': 0.0009551098376313276, 'mean_word_length': 3.2408906882591095, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 41, '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': '2405714', 'n_tokens_mistral': 647, 'n_tokens_neox': 635, 'n_words': 135}