<commit_before><?php

/**
 * igs actions.
 *
 * @package    darwin
 * @subpackage igs
 * @category   actions
 * @author     DB team <<EMAIL>>
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class igsActions extends DarwinActions
{
  protected $widgetCategory = 'catalogue_igs_widget';
  public function preExecute()
  {
    if (! strstr('view',$this->getActionName()) && ! strstr('index',$this->getActionName()) && ! strstr('search',$this->getActionName()) && ! strstr('searchForLimited',$this->getActionName()))
    {
      if(! $this->getUser()->isAtLeast(Users::ENCODER))
      {
        $this->forwardToSecureAction();
      }
    }
  }
  /**
    * Action executed when calling the expeditions from an other screen
    * @param sfWebRequest $request Request coming from browser
    */ 
  public function executeChoose(sfWebRequest $request)
  {
    // Initialization of the Search expedition form
    $this->form = new IgsFormFilter();
    // Remove surrounding layout
    $this->setLayout(false);
  }

  /**
    * Action executed when calling the expeditions directly
    * @param sfWebRequest $request Request coming from browser
    */ 
  public function executeIndex(sfWebRequest $request)
  {
    //  Initialization of the Search expedition form
    $this->form = new IgsFormFilter();    
  }

  public function executeNew(sfWebRequest $request)
  { 
    $igs = new igs() ;
    $igs = $this->getRecordIfDuplicate($request->getParameter('duplicate_id','0'), $igs);
    if($request->hasParameter('searchIg')) $igs->fromArray($request->getParameter('searchIg'));
    $this->form = new igsForm($igs);
  }

  public function executeCreate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST));

    $this->form = new igsForm();

    $this->processForm($request, $this->form);

    $this->setTemplate('new');
  }

  public function executeEdit(sfWebRequest $request)
  {
    $this->forward404Unless($igs = Doctrine::getTable('Igs')->find(array($request->getParameter('id'))), sprintf('Object I.G. does not exist (%s).', $request->getParameter('id')));
    $this->no_right_col = Doctrine::getTable('Igs')->testNoRightsCollections('ig_ref',$request->getParameter('id'), $this->getUser()->getId());
    $this->form = new igsForm($igs);
    $this->loadWidgets();
  }

  public function executeUpdate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST) || $request->isMethod(sfRequest::PUT));
    $this->forward404Unless($igs = Doctrine::getTable('igs')->find(array($request->getParameter('id'))), sprintf('Object I.G. does not exist (%s).', $request->getParameter('id')));
    $this->no_right_col = Doctrine::getTable('Igs')->testNoRightsCollections('ig_ref',$request->getParameter('id'), $this->getUser()->getId());    
    $this->form = new igsForm($igs);

    $this->processForm($request, $this->form);
    $this->loadWidgets();
    $this->setTemplate('edit');
  }

  public function executeDelete(sfWebRequest $request)
  {
    $request->checkCSRFProtection();
    $this->forward404Unless($igs = Doctrine::getTable('igs')->find(array($request->getParameter('id'))), sprintf('Object I.G. does not exist (%s).', $request->getParameter('id')));
    try
    {
      $igs->delete();
      $this->redirect('igs/index');
    }
    catch(Doctrine_Exception $ne)
    {
      $e = new DarwinPgErrorParser($ne);
      $error = new sfValidatorError(new savedValidator(),$e->getMessage());
      $this->form = new IgsForm($igs);
      $this->form->getErrorSchema()->addError($error); 
      $this->loadWidgets();
      $this->setTemplate('edit');
    }
  }
  public function executeSearch(sfWebRequest $request)
  {
    // Forward to a 404 page if the method used is not a post
    $this->forward404Unless($request->isMethod('post'));
    $this->setCommonValues('igs', 'ig_num', $request);
    // Instantiate a new expedition form
    $this->form = new IgsFormFilter();
    // Triggers the search result function
    $this->searchResults($this->form,$request);    
  }

  public function executeSearchFor(sfWebRequest $request)
  {
    // Forward to a 404 page if the method used is not a post
    $this->forward404Unless($request->isMethod('get'));
    // Triggers the search ID function
    if($request->getParameter('searchedCrit', '') !== '')
    {
      $igId = Doctrine::getTable('Igs')->findOneByIgNum($request->getParameter('searchedCrit'));
      if ($igId) 
        return $this->renderText($igId->getId());
      else
        return $this->renderText('not found');
    }
    return $this->renderText('');
  }

  public function executeSearchForLimited(sfWebRequest $request)
  {
    // Forward to a 404 page if the method used is not a post
    $this->forward404Unless($request->isMethod('get'));
    // Triggers the search ID function
    if($request->getParameter('q', '') !== '' && $request->getParameter('limit', '') !== '')
    {
      $igIds = Doctrine::getTable('Igs')->fetchByIgNumLimited($request->getParameter('q'), $request->getParameter('limit'));
      if ($igIds) 
      {
        $values=array();
        foreach($igIds as $key=>$value)
        {
          $values[$key]=$value->getIgNum();
        }
        return $this->renderText(implode("\n",$values));<commit_msg>Auto trim the ig on autocomplete<commit_after><?php

/**
 * igs actions.
 *
 * @package    darwin
 * @subpackage igs
 * @category   actions
 * @author     DB team <<EMAIL>>
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class igsActions extends DarwinActions
{
  protected $widgetCategory = 'catalogue_igs_widget';
  public function preExecute()
  {
    if (! strstr('view',$this->getActionName()) && ! strstr('index',$this->getActionName()) && ! strstr('search',$this->getActionName()) && ! strstr('searchForLimited',$this->getActionName()))
    {
      if(! $this->getUser()->isAtLeast(Users::ENCODER))
      {
        $this->forwardToSecureAction();
      }
    }
  }
  /**
    * Action executed when calling the expeditions from an other screen
    * @param sfWebRequest $request Request coming from browser
    */ 
  public function executeChoose(sfWebRequest $request)
  {
    // Initialization of the Search expedition form
    $this->form = new IgsFormFilter();
    // Remove surrounding layout
    $this->setLayout(false);
  }

  /**
    * Action executed when calling the expeditions directly
    * @param sfWebRequest $request Request coming from browser
    */ 
  public function executeIndex(sfWebRequest $request)
  {
    //  Initialization of the Search expedition form
    $this->form = new IgsFormFilter();    
  }

  public function executeNew(sfWebRequest $request)
  { 
    $igs = new igs() ;
    $igs = $this->getRecordIfDuplicate($request->getParameter('duplicate_id','0'), $igs);
    if($request->hasParameter('searchIg')) $igs->fromArray($request->getParameter('searchIg'));
    $this->form = new igsForm($igs);
  }

  public function executeCreate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST));

    $this->form = new igsForm();

    $this->processForm($request, $this->form);

    $this->setTemplate('new');
  }

  public function executeEdit(sfWebRequest $request)
  {
    $this->forward404Unless($igs = Doctrine::getTable('Igs')->find(array($request->getParameter('id'))), sprintf('Object I.G. does not exist (%s).', $request->getParameter('id')));
    $this->no_right_col = Doctrine::getTable('Igs')->testNoRightsCollections('ig_ref',$request->getParameter('id'), $this->getUser()->getId());
    $this->form = new igsForm($igs);
    $this->loadWidgets();
  }

  public function executeUpdate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST) || $request->isMethod(sfRequest::PUT));
    $this->forward404Unless($igs = Doctrine::getTable('igs')->find(array($request->getParameter('id'))), sprintf('Object I.G. does not exist (%s).', $request->getParameter('id')));
    $this->no_right_col = Doctrine::getTable('Igs')->testNoRightsCollections('ig_ref',$request->getParameter('id'), $this->getUser()->getId());    
    $this->form = new igsForm($igs);

    $this->processForm($request, $this->form);
    $this->loadWidgets();
    $this->setTemplate('edit');
  }

  public function executeDelete(sfWebRequest $request)
  {
    $request->checkCSRFProtection();
    $this->forward404Unless($igs = Doctrine::getTable('igs')->find(array($request->getParameter('id'))), sprintf('Object I.G. does not exist (%s).', $request->getParameter('id')));
    try
    {
      $igs->delete();
      $this->redirect('igs/index');
    }
    catch(Doctrine_Exception $ne)
    {
      $e = new DarwinPgErrorParser($ne);
      $error = new sfValidatorError(new savedValidator(),$e->getMessage());
      $this->form = new IgsForm($igs);
      $this->form->getErrorSchema()->addError($error); 
      $this->loadWidgets();
      $this->setTemplate('edit');
    }
  }
  public function executeSearch(sfWebRequest $request)
  {
    // Forward to a 404 page if the method used is not a post
    $this->forward404Unless($request->isMethod('post'));
    $this->setCommonValues('igs', 'ig_num', $request);
    // Instantiate a new expedition form
    $this->form = new IgsFormFilter();
    // Triggers the search result function
    $this->searchResults($this->form,$request);    
  }

  public function executeSearchFor(sfWebRequest $request)
  {
    // Forward to a 404 page if the method used is not a post
    $this->forward404Unless($request->isMethod('get'));
    $ig_num = trim($request->getParameter('searchedCrit', ''));
    // Triggers the search ID function
    if( $ig_num !== '')
    {
      $igId = Doctrine::getTable('Igs')->findOneByIgNum($ig_num);
      if ($igId) 
        return $this->renderText($igId->getId());
      else
        return $this->renderText('not found');
    }
    return $this->renderText('');
  }

  public function executeSearchForLimited(sfWebRequest $request)
  {
    // Forward to a 404 page if the method used is not a post
    $this->forward404Unless($request->isMethod('get'));
    // Triggers the search ID function
    if($request->getParameter('q', '') !== '' && $request->getParameter('limit', '') !== '')
    {
      $igIds = Doctrine::getTable('Igs')->fetchByIgNumLimited($request->getParameter('q'), $request->getParameter('limit'));
      if ($igIds) 
      {
        $values=array();
        foreach($igIds as $key=>$value)
        {
          $values[$key]=$value->getIgNum();
        }
        return $this->renderText(implode("\n",$values));
{'fraction_non_alphanumeric': 0.17463304478735417, 'fraction_numerical': 0.009973654497553632, 'mean_word_length': 3.8645308924485127, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 184, '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': '6196114', 'n_tokens_mistral': 3355, 'n_tokens_neox': 3220, 'n_words': 629}