/** * Update news category * * @param Repository $repo * @param NewsCategoryEntity $entity * @return boolean * @throws \RuntimeException */ public function update(Repository $repo, NewsCategoryEntity $entity) { $repo->update($this, $entity); if (!$repo->commit()) { $mess = print_r($repo->getErrorEntity()->getErrors()->all(), 1); throw new \RuntimeException("Error update category news. Error: {$mess}."); } return true; }
/** * Update news * * @param Repository $repo * @return NewsEntity $entity * @return boolean * @throws \RuntimeException */ public function update(Repository $repo, NewsEntity $entity) { $repo->update($this, $entity); $picture = $entity->picture; if (!$repo->commit()) { $mess = print_r($repo->getErrorEntity()->getErrors()->all(), 1); throw new \RuntimeException("Error update news. Error: {$mess}."); } if ($picture !== null) { $picture->saveFile(); } return true; }
/** * Reload captcha * @param string $guid * @return CaptchaEntity[] * @throws \RuntimeException */ public function reload($guid) { $repo = new Repository('captcha'); $captches = $this->getByGuid($guid); if ($captches->count() === 0) { throw new \RuntimeException('Captcha not found'); } foreach ($captches as $captcha) { $repo->update($this, $captcha); } if (!$repo->commit()) { throw new \RuntimeException('Error reload captcha'); } $captches->rewind(); return $captches; }
/** * 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; }
/** * Update user * * @param Repository $repo * @param UserEntity $entity * @return boolean * @throws \RuntimeException */ public function update(Repository $repo, UserEntity $entity) { $repo->update($this, $entity); if (!$repo->commit()) { throw new ValidateException($repo->getErrorEntity()->getErrors()); } return true; }