public function banUser($id) { if ($this->user->banUser($id) !== 1) { Session::setError('something went wrong'); Redirect::back(); } Session::setMessage('Done'); Redirect::to('/admin/users'); }
public function postAdd(MessageBindingModel $message) { $validator = $this->validateMessage(new Validation(), $message); if (!$validator->validate()) { Session::setError($validator->getErrors()); Redirect::back(); } $this->message->add($message->first_name, $message->last_name, $message->email, $message->phone, $message->content, $message->about, date("Y-m-d H:i:s"), false); Session::setMessage('Message is sent successfully'); Redirect::to(''); }
public function delete($id) { /* @var $image \Models\ViewModels\ImageViewModel */ $image = $this->image->getById($id); if ($this->image->delete($id) !== 1) { Session::setError('something went wrong. Try again'); Redirect::back(); } $this->unlinkImage($image->name); Session::setMessage('The image has been deleted'); Redirect::back(); }
public function delete($id) { if (Auth::isUserInRole(array('admin')) || $this->comment->getComment($id)['user_id'] == Auth::getUserId()) { if ($this->comment->delete($id) !== 1) { Session::setError('something went wrong'); Redirect::back(); } Session::setMessage('Done'); Redirect::back(); } Redirect::back(); }
public function setRole($id, $role) { if (!in_array($role, array('admin', 'editor', 'user'))) { Session::setError('incorrect role'); Redirect::back(); } if ($role == 'user') { if ($this->user->deleteUserRole($id) === 0) { Session::setError('something went wrong'); Redirect::back(); } Session::setMessage('Done'); Redirect::to('/admin/users'); } if ($this->user->setRole($id, $role) !== 1) { Session::setError('something went wrong'); Redirect::back(); } Session::setMessage('Done'); Redirect::to('/admin/users'); }
public function sellProduct($id, $quantity, $upid) { $this->user->startTran(); if ($this->user->changeProductQuantity(Auth::getUserId(), $id, $quantity, $upid) !== 1) { Session::setError('not enough products'); $this->user->rollback(); Redirect::back(); } $userProduct = $this->user->getProduct(Auth::getUserId(), $id, $upid); if ($userProduct['quantity'] < 1) { if ($this->user->deleteProduct(Auth::getUserId(), $id, $upid) !== 1) { Session::setError('something went wrong'); $this->user->rollback(); Redirect::back(); } } $soldProducts = $this->product->getProduct($id); if ($this->product->addQuantity($soldProducts['id'], $quantity) !== 1) { Session::setError('something went wrong'); $this->user->rollback(); Redirect::back(); } if ($this->user->addCash(Auth::getUserId(), $soldProducts['price'] * $quantity) !== 1) { Session::setError('something went wrong'); $this->user->rollback(); Redirect::back(); } $this->user->commit(); Session::setMessage('You sold ' . $quantity . ' of ' . $userProduct['name']); Redirect::to('/user/' . Auth::getUserId() . '/products'); }
public function postEdit($id, $name) { $validator = new Validation(); $validator->setRule('required', $name, null, 'Name'); if (!$validator->validate()) { Session::setError($validator->getErrors()); Redirect::back(); } $this->city->edit($id, $name); Session::setMessage('The city is edited'); Redirect::to(''); }
public function delete($id) { if ($this->product->delete($id) !== 1) { Session::setError('can not delete this product'); Redirect::back(); } Session::setMessage('done'); Redirect::to(''); }
public function delete($id) { /* @var $estate \Models\ViewModels\EstateViewModel */ $estate = $this->estate->getEstate($id); /* @var $images \Models\ViewModels\ImageViewModel[] */ $images = $this->image->getImagesByEstate($id); if ($this->estate->delete($id) !== 1) { Session::setError('something went wrong. try again'); Redirect::back(); } /* @var $imageController \Controllers\ImageController */ $imageController = DependencyProvider::injectDependenciesToController(new ImageController()); if (isset($estate->main_image_id)) { $mainImg = new ImageViewModel(); $mainImg->id = $estate->main_image_id; $mainImg->name = $estate->image; $images[] = $mainImg; } $imageController->removeMultiple($images); Session::setMessage('The estate is deleted'); Redirect::to(''); }
public function removeFromFavourites($id) { if (Auth::isAuth()) { $this->user->delteEstateFromFavourites(Auth::getUserId(), $id); } else { $favourites = Session::get('favourites') ? Session::get('favourites') : array(); if (($key = array_search($id, $favourites)) !== false) { unset($favourites[$key]); } Session::set('favourites', $favourites); } Session::setMessage('Deleted successfully'); Redirect::back(); }
public function postAdd(PromotionModel $promotion) { $validator = new Validation(); $validator->setRule('required', $promotion->discount, null, 'discount'); $validator->setRule('required', $promotion->date, null, 'date'); $validator->setRule('date', $promotion->date, null, 'date'); if (!$validator->validate()) { Session::setError($validator->getErrors()[0]); Redirect::back(); } if ($this->promotion->add($promotion->discount, $promotion->date, $promotion->category_id == 0 ? null : $promotion->category_id, $promotion->product_id == 0 ? null : $promotion->product_id) !== 1) { Session::setError('something went wrong'); Redirect::back(); } Session::setMessage('done'); Redirect::to(''); }
public function postEdit($id, $name) { if ($this->category->edit($id, $name) !== 1) { Session::setError('something went wrong'); Redirect::back(); } Session::setMessage('done'); Redirect::to(''); }
public function buy() { $totalSum = 0; $cart = Session::get('cart'); $this->product->startTran(); $productsFromCart = $this->getProductsFromCart($cart); foreach ($productsFromCart as $item) { if ($this->product->changeQuantity($item['id'], $item['cart_quantity']) !== 1) { $this->product->rollback(); Session::setError('not enough available product'); Redirect::back(); } $totalSum += $item['price'] * $item['cart_quantity']; } $user = new User(); if ($user->changeUserCash(Auth::getUserId(), $totalSum) !== 1) { $this->product->rollback(); Session::setError('not enough money'); Redirect::back(); } foreach ($productsFromCart as $item) { if ($user->addProduct(Auth::getUserId(), $item['id'], $item['cart_quantity'], $item['price']) !== 1) { $this->product->rollback(); Session::setError('something went wrong'); Redirect::back(); } } $this->product->commit(); Session::remove('cart'); Session::setMessage('Done'); Redirect::to('user/cart'); }