<commit_before><?php
/**
 * Change the a users current program and defautl program
 * @author <NAME> <<EMAIL>>
 * @package jazzee
 * @subpackage admin
 */
class AdminChangeprogramController extends \Jazzee\AdminController {
  const MENU = 'My Account';
  const TITLE = 'Change Program';
  const PATH = 'changeprogram';
  const REQUIRE_AUTHORIZATION = true;
  const REQUIRE_APPLICATION = false;
  
//  const ACTION_INDEX = 'Change to Authorized Program'; dont display this as a role option any user can do it
  const ACTION_ANYPROGRAM = 'Change to any Program';
  
  /**
   * Display index
   */
  public function actionIndex(){
    $form = new \Foundation\Form();
    $form->setAction($this->path('changeprogram'));
    $field = $form->newField();
    $field->setLegend('Select Program');
    $element = $field->newElement('SelectList','program');
    $element->setLabel('Program');
    $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element));
    $programs = $this->_em->getRepository('\Jazzee\Entity\Program')->findBy(array('isExpired' => false), array('name' => 'ASC'));
    $userPrograms = $this->_user->getPrograms();
    foreach($programs as $program){
      if($this->checkIsAllowed($this->controllerName, 'anyProgram') or in_array($program->getId(), $userPrograms)) $element->newItem($program->getId(), $program->getName());
    }
    if($this->_program) $element->setValue($this->_program->getId());
    //only ask if the user already has a default cycle
    if($this->_user->getDefaultProgram()){
      $element = $field->newElement('RadioList','default');
      $element->setLabel('Set as your default');
      $element->newItem(0, 'No');
      $element->newItem(1, 'Yes');
      $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element));
    }
    $form->newButton('submit', 'Change Program');
    
    if($input = $form->processInput($this->post)){
      $this->_program = $this->_em->getRepository('\Jazzee\Entity\Program')->find($input->get('program'));

      //if they wish it, or if the user has no default cycle
      if(!$this->_user->getDefaultProgram() OR $input->get('default')){
        $this->_user->setDefaultProgram($this->_program);
        $this->_em->persist($this->_user);
        $this->addMessage('success', 'Default program changed to ' . $this->_program->getName());
      }
      unset($this->_store->AdminControllerGetNavigation);
      $this->addMessage('success', 'Program changed to ' . $this->_program->getName());
      $this->redirectPath('welcome');
    }
    
    $this->setVar('form', $form);
  }
  
  /**
   * Change to any program
   * This method doesn't actually do anything it is just here to trigger an authorization lookup
   */
  public function actionAnyProgram(){
    throw new \Jazzee\Exception('adminChangeProgram::actionAnyProgram was called.  It should not have been.');
  }
  
  /**
   * Only allow change program if the user is in at least one program
   * At this top level always return false so nothing is allowed by default
   * @param string $controller
   * @param string $action
   * @param \Jazzee\Entity\User $user
   * @param \Jazzee\Entity\Program $program
   * @return bool
   */
  public static function isAllowed($controller, $action, \Jazzee\Entity\User $user = null, \Jazzee\Entity\Program $program = null, \Jazzee\Entity\Application $application = null){
    if($user and $action=='index'){
      $userPrograms = $user->getPrograms();
      return (parent::isAllowed($controller, 'anyProgram') or !empty($userPrograms));
    }
    return parent::isAllowed($controller, $action, $user, $program, $application);
  }
}
?><commit_msg>fix change program not working for anyprogram authorized users<commit_after><?php
/**
 * Change the a users current program and defautl program
 * @author <NAME> <<EMAIL>>
 * @package jazzee
 * @subpackage admin
 */
class AdminChangeprogramController extends \Jazzee\AdminController {
  const MENU = 'My Account';
  const TITLE = 'Change Program';
  const PATH = 'changeprogram';
  const REQUIRE_AUTHORIZATION = true;
  const REQUIRE_APPLICATION = false;
  
//  const ACTION_INDEX = 'Change to Authorized Program'; dont display this as a role option any user can do it
  const ACTION_ANYPROGRAM = 'Change to any Program';
  
  /**
   * Display index
   */
  public function actionIndex(){
    $form = new \Foundation\Form();
    $form->setAction($this->path('changeprogram'));
    $field = $form->newField();
    $field->setLegend('Select Program');
    $element = $field->newElement('SelectList','program');
    $element->setLabel('Program');
    $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element));
    $programs = $this->_em->getRepository('\Jazzee\Entity\Program')->findBy(array('isExpired' => false), array('name' => 'ASC'));
    $userPrograms = $this->_user->getPrograms();
    foreach($programs as $program){
      if($this->checkIsAllowed($this->controllerName, 'anyProgram') or in_array($program->getId(), $userPrograms)) $element->newItem($program->getId(), $program->getName());
    }
    if($this->_program) $element->setValue($this->_program->getId());
    //only ask if the user already has a default cycle
    if($this->_user->getDefaultProgram()){
      $element = $field->newElement('RadioList','default');
      $element->setLabel('Set as your default');
      $element->newItem(0, 'No');
      $element->newItem(1, 'Yes');
      $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element));
    }
    $form->newButton('submit', 'Change Program');
    
    if($input = $form->processInput($this->post)){
      $this->_program = $this->_em->getRepository('\Jazzee\Entity\Program')->find($input->get('program'));

      //if they wish it, or if the user has no default cycle
      if(!$this->_user->getDefaultProgram() OR $input->get('default')){
        $this->_user->setDefaultProgram($this->_program);
        $this->_em->persist($this->_user);
        $this->addMessage('success', 'Default program changed to ' . $this->_program->getName());
      }
      unset($this->_store->AdminControllerGetNavigation);
      $this->addMessage('success', 'Program changed to ' . $this->_program->getName());
      $this->redirectPath('welcome');
    }
    
    $this->setVar('form', $form);
  }
  
  /**
   * Change to any program
   * This method doesn't actually do anything it is just here to trigger an authorization lookup
   */
  public function actionAnyProgram(){
    throw new \Jazzee\Exception('adminChangeProgram::actionAnyProgram was called.  It should not have been.');
  }
  
  /**
   * Only allow change program if the user is in at least one program
   * At this top level always return false so nothing is allowed by default
   * @param string $controller
   * @param string $action
   * @param \Jazzee\Entity\User $user
   * @param \Jazzee\Entity\Program $program
   * @return bool
   */
  public static function isAllowed($controller, $action, \Jazzee\Entity\User $user = null, \Jazzee\Entity\Program $program = null, \Jazzee\Entity\Application $application = null){
    if($user and $action=='index'){
      $userPrograms = $user->getPrograms();
      return (parent::isAllowed($controller, 'anyprogram', $user) or !empty($userPrograms));
    }
    return parent::isAllowed($controller, $action, $user, $program, $application);
  }
}
?>
{'fraction_non_alphanumeric': 0.1609915554344865, 'fraction_numerical': 0.0005448106782892945, 'mean_word_length': 3.954790823211876, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 129, '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': '666019', 'n_tokens_mistral': 2143, 'n_tokens_neox': 2130, 'n_words': 535}