Exemplo n.º 1
0
 /**
  * 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;
 }
Exemplo n.º 2
0
 /**
  * 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;
 }
Exemplo n.º 3
0
 /**
  * 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;
 }
Exemplo n.º 4
0
 /**
  * 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;
 }
Exemplo n.º 5
0
 /**
  * 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;
 }
Exemplo n.º 6
0
 /**
  * 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;
 }
Exemplo n.º 7
0
 /**
  * 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;
 }
Exemplo n.º 8
0
 /**
  * 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');
     }
 }