public function checkUserExist($id)
 {
     $user = $this->userDAO->getById($id);
     if (empty($user)) {
         PhException::throwErrors(['User_IdNotFound' => 1]);
     }
 }
 public function update($product)
 {
     $validationErrors = $this->validateProduct($product);
     if (!empty($validationErrors)) {
         PhException::throwErrors($validationErrors);
     }
     $product = $this->prepareForSaving($product);
     return $this->productDAO->update($product);
 }
 private function getUserByLoginAndPassword($login, $password)
 {
     $password = SecurityUtil::encrypt($password);
     $user = $this->userDAO->getByLoginAndPassword($login, $password);
     if (empty($user)) {
         PhException::throwErrors(['User_IdNotFound' => 1]);
     }
     return $user;
 }
 public function destroy($userId)
 {
     if (!$this->isPostRequest()) {
         exit;
     }
     try {
         if ($userId === AuthModel::getInstance()->getLoggedInUserId()) {
             PhException::throwErrors(['User_DeleteCurrentUser' => 1]);
         }
         $user = UserModel::getInstance()->getById($userId);
         UserModel::getInstance()->delete($userId);
         messages::add('User_Deleted', ['login' => $user['login']], 'success');
         $this->systemRedirect('/user');
     } catch (PhException $e) {
         messages::addGroup('error', $e->getErrors());
         $this->systemRedirect('/user');
     }
 }
Example #5
0
 public function checkCatalogExist($id)
 {
     $catalog = $this->catalogDAO->getById($id);
     if (empty($catalog)) {
         PhException::throwErrors(['Catalog_IdNotFound' => 1]);
     }
     return $catalog;
 }
 public function destroy($catalogId)
 {
     if (!$this->isPostRequest()) {
         exit;
     }
     try {
         $catalog = CatalogModel::getInstance()->getById($catalogId);
         if (empty($catalog)) {
             PhException::throwErrors(['Catalog_IdNotFound' => 1]);
         }
         FileUtil::deleteDir(ProductModel::getInstance()->getImagesDir($catalogId));
         if (CatalogModel::getInstance()->imageExist($catalogId)) {
             CatalogModel::getInstance()->deleteImage($catalogId);
         }
         ProductModel::getInstance()->deleteProductsTable($catalogId);
         CatalogModel::getInstance()->delete($catalogId);
         messages::add('Catalog_Deleted', ['name' => $catalog['name']], 'success');
         $this->systemRedirect('/catalog');
     } catch (PhException $e) {
         messages::addGroup('error', $e->getErrors());
         $this->systemRedirect('/catalog');
     }
 }