/**
  * @param $promo_code_value
  * @param ISummit $summit
  * @return ISpeakerSummitRegistrationPromoCode
  * @throws EntityValidationException
  * @throws ValidationException
  */
 public function registerSummitPromoCodeByValue($promo_code_value, ISummit $summit)
 {
     // check if we have an assigned one already
     $old_code = SpeakerSummitRegistrationPromoCode::get()->filter(['SummitID' => $summit->getIdentifier(), 'SpeakerID' => $this->ID])->first();
     // we are trying to update the promo code with another one ....
     if ($old_code && $promo_code_value !== $old_code->Code) {
         throw new EntityValidationException(sprintf('speaker has already assigned to another registration code (%s)', $old_code->Code));
     }
     //we already have the same code ...
     if ($old_code) {
         return $old_code;
     }
     // check if the promo code already exists and assigned to another user
     $existent_code = SpeakerSummitRegistrationPromoCode::get()->filter(['Code' => $promo_code_value, 'SummitID' => $summit->getIdentifier(), 'SpeakerID:ExactMatch:not' => 0])->first();
     if ($existent_code) {
         throw new EntityValidationException(sprintf('there is another speaker with that code for this summit (%s)', $promo_code_value));
     }
     // check if promo code exists and its not assigned ...
     $code = SpeakerSummitRegistrationPromoCode::get()->filter(['Code' => $promo_code_value, 'SummitID' => $summit->getIdentifier(), 'SpeakerID' => 0])->first();
     if (!$code) {
         //create it
         $code = SpeakerSummitRegistrationPromoCode::create();
         $code->SummitID = $summit->getIdentifier();
         $code->Code = $promo_code_value;
         $code->write();
     }
     $this->registerSummitPromoCode($code);
     $code->write();
     return $code;
 }