/**
  * {@inheritDoc}
  */
 public function getRewardOptions()
 {
     if (null === $this->_rewardOptions) {
         $rewardOptions = $this->_loaders->get('reward_option')->load($this);
         if (!$rewardOptions) {
             throw new \LogicException('Could not load reward options!');
         }
         foreach ($rewardOptions as $rewardOption) {
             $this->addRewardOption($rewardOption);
         }
     }
     return parent::getRewardOptions();
 }
 /**
  * Save the Config details to the database. Does not save entities.
  *
  * @param Config $config
  *
  * @return Config
  */
 public function save(Config $config)
 {
     $result = $this->_query->run("\n\t\t\tINSERT INTO\n\t\t\t\trefer_a_friend_reward_config\n\t\t\t\t(\n\t\t\t\t\t`name`,\n\t\t\t\t\t`type`,\n\t\t\t\t\tmessage,\n\t\t\t\t\tcreated_at,\n\t\t\t\t\tcreated_by\n\t\t\t\t)\n\t\t\tVALUES\n\t\t\t\t(\n\t\t\t\t\t:name?s,\n\t\t\t\t\t:type?s,\n\t\t\t\t\t:message?s,\n\t\t\t\t\t:createdAt?d,\n\t\t\t\t\t:createdBy?i\n\t\t\t\t)\n\t\t\t;\n\t\t", ['name' => $config->getName(), 'type' => $config->getType()->getName(), 'message' => $config->getMessage(), 'createdAt' => new \DateTime(), 'createdBy' => $this->_currentUser->id]);
     $config->setID($result->id());
     return $config;
 }
 /**
  * Add the query to delete a configuration to the database transaction
  *
  * @param Config $config
  */
 private function _addToTransaction(Config $config)
 {
     $this->_transaction->add("\n\t\t\tUPDATE\n\t\t\t\trefer_a_friend_reward_config\n\t\t\tSET\n\t\t\t\tdeleted_at    = :deletedAt?d,\n\t\t\t\tdeleted_by    = :deletedBy?i\n\t\t\tWHERE\n\t\t\t\treward_config_id = :id?i\n\t\t", ['id' => $config->getID(), 'deletedAt' => new \DateTime(), 'deletedBy' => $this->_currentUser->id]);
 }
 /**
  * Load and populate reward options and add them to the Config
  *
  * @param Config $config
  *
  * @param array $formData
  */
 private function _addRewardOptions(Config $config, array $formData)
 {
     if (empty($formData['reward_options'])) {
         return;
     }
     $rewardOptionsData = $formData['reward_options'];
     if (!is_array($rewardOptionsData)) {
         $type = gettype($rewardOptionsData) === 'object' ? get_class($rewardOptionsData) : gettype($rewardOptionsData);
         throw new \LogicException('Reward option form data must be an array, ' . $type . ' given');
     }
     foreach ($rewardOptionsData as $name => $value) {
         if (null === $value) {
             continue;
         }
         $rewardOption = clone $this->_rewardOptions->get($name);
         $rewardOption->setValue($value);
         $config->addRewardOption($rewardOption);
     }
 }