/** * Add user * * @param Repository $repo * @param UserEntity $entity * @return integer * @throws \RuntimeException */ public function add(Repository $repo, UserEntity $entity) { $repo->add($this, $entity); if (!$repo->commit()) { throw new ValidateException($repo->getErrorEntity()->getErrors()); } return $entity->id; }
/** * Add news category * * @param Repository $repo * @param NewsCategoryEntity $entity * @return integer * @throws \RuntimeException */ public function add(Repository $repo, NewsCategoryEntity $entity) { $repo->add($this, $entity); if (!$repo->commit()) { $mess = print_r($repo->getErrorEntity()->getErrors()->all(), 1); throw new \RuntimeException("Error add news. Error: {$mess}."); } return $entity->id; }
/** * Add user group member * * @param Repository $repo * @param UserGroupMemberEntity $entity * @return boolean * @throws \RuntimeException */ public function add(Repository $repo, UserGroupMemberEntity $entity) { $repo->add($this, $entity); if (!$repo->commit()) { $mess = print_r($repo->getErrorEntity()->getErrors()->all(), 1); throw new \RuntimeException("Error add user group member. Error: {$mess}."); } return $entity->id; }
/** * Create access token * * @param AccessEntity $entity * @return boolean * @throws \RuntimeException */ public function add(AccessEntity $entity) { $this->clear($entity->user_id); $repo = new Repository($this->repository_name); $repo->add($this, $entity); if (!$repo->commit()) { $mess = print_r($repo->getErrorEntity()->getErrors()->all(), 1); throw new \RuntimeException("Error create access token. Error: {$mess}."); } return true; }
/** * Add news * * @param Repository $repo * @return NewsEntity $entity * @throws \RuntimeException */ public function add(Repository $repo, NewsEntity $entity) { $repo->add($this, $entity); $picture = $entity->picture; if (!$repo->commit()) { $mess = print_r($repo->getErrorEntity()->getErrors()->all(), 1); throw new \RuntimeException("Error add news. Error: {$mess}."); } if ($picture !== null) { $picture->saveFile(); } return $entity->id; }
/** * Increment counter * @param string $entity * @param string $entity_id * @throws \RuntimeException * @return integer */ public function inc($entity, $entity_id) { $repo = new Repository('counter'); $counter = $this->get($entity, $entity_id); if ($counter === false) { $counter = new CounterEntity(); $counter->entity = $entity; $counter->entity_id = $entity_id; $repo->add($this, $counter); $return = 1; } else { $counter->counter++; $repo->update($this, $counter); $return = $counter->counter; } if (!$repo->commit()) { $mess = print_r($repo->getErrorEntity()->getErrors()->all(), 1); throw new \RuntimeException('Error increment counter. Message: ' . $mess); } return $return; }
/** * Create captcha * @return \BX\Captcha\Entity\CaptchaEntity * @throws \RuntimeException */ public function create() { $entity = new CaptchaEntity(); $repo = new \BX\DB\UnitOfWork\Repository('captcha'); $repo->add($this, $entity); if (!$repo->commit()) { $mess = print_r($repo->getErrorEntity()->getErrors()->all(), 1); throw new \RuntimeException("Error create captcha. Error: {$mess}."); } return $entity; }
/** * Add row in db table * @param string $func */ private function add($func) { $this->found = true; $class = $this->package . '\\' . $this->service . '\\Migration'; if (!class_exists($class)) { throw new \LogicException("Class `{$class}` is not found"); } $instance = new $class(); call_user_func_array([$instance, $func], [true]); $entity = new MigrationEntity(); $entity->package = $this->package; $entity->service = $this->service; $entity->function = $func; $entity->guid = $this->hash; $trans = new Repository(); $trans->add($this->table, $entity); if (!$trans->commit(false)) { throw new \RuntimeException('Add migration error'); } }