function up() { echo "Starting Migration Proc ...<BR>"; //check if migration already had ran ... $migration = Migration::get()->filter('Name', $this->title)->first(); $promo_code_type = isset($_REQUEST['promo_code_type']) ? intval($_REQUEST['promo_code_type']) : null; $promo_code_file = isset($_REQUEST['promo_code_file']) ? $_REQUEST['promo_code_file'] : null; if (is_null($promo_code_type)) { echo 'ERROR - promo_code_type param missing!'; exit; } if (is_null($promo_code_file)) { echo 'ERROR - promo_code_file param missing!'; exit; } $base_path = ASSETS_PATH; $file_path = $base_path . '/' . $promo_code_file; $type = explode(".", $file_path); if (!strtolower(end($type)) == 'csv') { echo 'ERROR - file hast not a csv extension!'; exit; } if (!file_exists($file_path)) { echo sprintf('ERROR - %s file does not exists!', $file_path); exit; } $reader = new CSVReader($file_path); $row = 0; do { $line = $reader->getLine(); if ($line) { ++$row; if ($row === 1) { continue; } // skip header ... switch ($promo_code_type) { case 1: $type = 'ACCEPTED'; break; case 2: $type = 'ALTERNATE'; break; } $code = new SpeakerSummitRegistrationPromoCode(); $code->Code = $line[0]; $code->Type = $type; $code->SummitID = Summit::get_active()->ID; try { $code->write(); } catch (Exception $ex) { SS_Log::log($ex->getMessage(), SS_Log::ERR); } } } while ($line); echo "Ending Migration Proc ...<BR>"; }
public function getRegistrationCodeByTerm(SS_HTTPRequest $request) { try { $term = Convert::raw2sql($request->param('REG_CODE')); $summit_id = intval($request->param('SUMMIT_ID')); $summit = Summit::get_by_id('Summit', $summit_id); if (is_null($summit)) { throw new NotFoundEntityException('Summit', sprintf(' id %s', $summit_id)); } $codes = SpeakerSummitRegistrationPromoCode::get()->filter(array('SummitID' => $summit_id, 'OwnerID' => 0, 'SpeakerID' => 0))->where(" Code LIKE '{$term}%' ")->limit(25, 0); $data = array(); foreach ($codes as $code) { $data[] = array('code' => trim($code->Code), 'name' => sprintf('%s (%s)', $code->Code, $code->Type)); } return $this->ok($data, false); } catch (NotFoundEntityException $ex2) { SS_Log::log($ex2->getMessage(), SS_Log::WARN); return $this->notFound($ex2->getMessage()); } catch (Exception $ex) { SS_Log::log($ex->getMessage(), SS_Log::ERR); return $this->serverError(); } }
/** * @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; }
/** * @param int $summit_id * @param int $speaker_id * @return ISummitRegistrationPromoCode */ public function getBySpeaker($summit_id, $speaker_id) { $promo_codes = SpeakerSummitRegistrationPromoCode::get()->where("SummitID = {$summit_id} AND SpeakerID = {$speaker_id}"); return $promo_codes; }