<commit_before><?php

use Scholarship\Forms\RecommendationForm;

class RecommendationController extends \BaseController {
  /**
   * @var recommendationForm
   */
  protected $recommendationForm;

  function __construct(RecommendationForm $recommendationForm)
  {
    $this->recommendationForm = $recommendationForm;

    // Check that the current user doesn't create many applications
    $this->beforeFilter('createdRec', ['only' => ['create']]);
  }

  /**
   * Display a listing of the resource.
   * GET /recommendation
   *
   * @return Response
   */
  public function index()
  {
    //
  }

  /**
   * Show the form for creating a new resource.
   * GET /recommendation/create
   *
   * @return Response
   */
  public function create()
  {
    // This will be seen by applicants only.
    $num_recs = Scholarship::getCurrentScholarship()->select('num_recommendations_max', 'num_recommendations_min')->firstOrFail()->toArray();

    $help_text = Setting::getSpecifiedSettingsVars(['recommendation_create_help_text']);
    $page_vars = Setting::getPageSettingsVars();

    $vars = (object) array_merge($page_vars, $help_text);

    return View::make('recommendation.create', compact('num_recs', 'vars'));
  }

  /**
   * Store a newly created resource in storage.
   * POST /recommendation
   *
   * @return Response
   */
  public function store()
  {

    $input = Input::all();

    // These aren't the real rules, it's just needed to call the array validation class
    $rules = ['first_name' => 'required|TextFieldArray'];
    $data = ['first_name' => $input['rec']];
    // Calls the class that goes through and checks the real rules.
    $v = Validator::make($data, $rules);

    if ($v->fails()) {
      return  Redirect::back()->with('flash_message', ['text' => 'All fields are required.', 'class' => '-error'])->withInput();
    }
    else {
      foreach($input['rec'] as $input)
      {
        $recommendation = new Recommendation;

        foreach ($input as $key => $field) {
            $recommendation->$key = $field;
        }
        $application = Auth::user()->application;
        $recommendation->application()->associate($application);
        $recommendation->save();

        $token = $recommendation->generateRecToken($recommendation);
        $this->prepareRecRequestConfirmationEmail();
        $this->prepareRecRequestEmail($recommendation, $token);
      }
      return Redirect::route('status')->with('flash_message', ['text' => 'Your recommendation request has been submitted!', 'class' => '-success']);
    }
  }<commit_msg>Only create new recs when email is set. Fixes #455<commit_after><?php

use Scholarship\Forms\RecommendationForm;

class RecommendationController extends \BaseController {
  /**
   * @var recommendationForm
   */
  protected $recommendationForm;

  function __construct(RecommendationForm $recommendationForm)
  {
    $this->recommendationForm = $recommendationForm;

    // Check that the current user doesn't create many applications
    $this->beforeFilter('createdRec', ['only' => ['create']]);
  }

  /**
   * Display a listing of the resource.
   * GET /recommendation
   *
   * @return Response
   */
  public function index()
  {
    //
  }

  /**
   * Show the form for creating a new resource.
   * GET /recommendation/create
   *
   * @return Response
   */
  public function create()
  {
    // This will be seen by applicants only.
    $num_recs = Scholarship::getCurrentScholarship()->select('num_recommendations_max', 'num_recommendations_min')->firstOrFail()->toArray();

    $help_text = Setting::getSpecifiedSettingsVars(['recommendation_create_help_text']);
    $page_vars = Setting::getPageSettingsVars();

    $vars = (object) array_merge($page_vars, $help_text);

    return View::make('recommendation.create', compact('num_recs', 'vars'));
  }

  /**
   * Store a newly created resource in storage.
   * POST /recommendation
   *
   * @return Response
   */
  public function store()
  {

    $input = Input::all();

    // These aren't the real rules, it's just needed to call the array validation class
    $rules = ['first_name' => 'required|TextFieldArray'];
    $data = ['first_name' => $input['rec']];
    // Calls the class that goes through and checks the real rules.
    $v = Validator::make($data, $rules);

    if ($v->fails()) {
      return  Redirect::back()->with('flash_message', ['text' => 'All fields are required.', 'class' => '-error'])->withInput();
    }
    else {
      foreach($input['rec'] as $input)
      {
        if (!empty($input['email'])) {
          $recommendation = new Recommendation;

          foreach ($input as $key => $field) {
              $recommendation->$key = $field;
          }
          $application = Auth::user()->application;
          $recommendation->application()->associate($application);
          $recommendation->save();

          $token = $recommendation->generateRecToken($recommendation);
          $this->prepareRecRequestConfirmationEmail();
          $this->prepareRecRequestEmail($recommendation, $token);
        }
      }
      return Redirect::route('status')->with('flash_message', ['text' => 'Your recommendation request has been submitted!', 'class' => '-success']);
    }
  }
{'fraction_non_alphanumeric': 0.14738449789996183, 'fraction_numerical': 0.000572737686139748, 'mean_word_length': 3.3119341563786007, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 53, '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': '123367', 'n_tokens_mistral': 1576, 'n_tokens_neox': 1490, 'n_words': 357}