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 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');
 }
Esempio n. 3
0
    echo $c['username'];
    ?>
</a></h4>
                                <h4><?php 
    echo $c['posted_on'];
    ?>
</h4>
                                <div>
                                    <p><?php 
    echo $c['content'];
    ?>
</p>
                                </div>
                            </div>
                            <?php 
    if (Auth::getUserId() == $c['user_id'] || $isAdmin) {
        ?>
                                <a href="<?php 
        echo Common::getBaseURL();
        ?>
/comment/delete/<?php 
        echo $c['id'];
        ?>
" class="btn btn-danger">Delete</a>
                            <?php 
    }
    ?>
                        </div>
                    <?php 
}
?>
 /**
  * @return array
  */
 public function setUserFavorites()
 {
     $userFavorites = array();
     if (Auth::isAuth()) {
         $favorites = $this->user->getFavourites(Auth::getUserId());
         foreach ($favorites as $f) {
             $userFavorites[] = $f['estate_id'];
         }
     } else {
         $userFavorites = Session::get('favourites');
     }
     return is_array($userFavorites) ? $userFavorites : array();
 }
 public function getFavourites()
 {
     $result['title'] = 'User Favorites';
     $userFavourite = array();
     if (Auth::isAuth()) {
         $favorites = $this->user->getFavourites(Auth::getUserId());
         foreach ($favorites as $f) {
             $userFavourite[] = $f['estate_id'];
         }
         View::appendTemplateToLayout('topBar', 'top_bar/user');
     } else {
         $userFavourite = Session::get('favourites');
         View::appendTemplateToLayout('topBar', 'top_bar/guest');
     }
     /* @var $estates \Models\ViewModels\EstateBasicViewModel[] */
     if (!empty($userFavourite)) {
         $estates = $this->estate->getFavoritesEstates($userFavourite);
         foreach ($estates as $estate) {
             $estate->image = EstateController::setEstateMainImage($estate);
             $estate->thumbnailName = EstateController::setImageThumb($estate->image);
         }
         $result['estates'] = $estates;
     } else {
         $result['estates'] = array();
     }
     View::make('user.favorites', $result);
     View::appendTemplateToLayout('header', 'includes/header')->appendTemplateToLayout('footer', 'includes/footer')->render();
 }
Esempio n. 6
0
echo Common::getBaseURL();
?>
/user/logout">Logout</a>
        </li>
        <li>
            <a href="<?php 
echo Common::getBaseURL();
?>
/user/cart">Cart</a>
        </li>
        <li>
            <a href="<?php 
echo Common::getBaseURL();
?>
/user/<?php 
echo Auth::getUserId();
?>
/products">Your Products</a>
        </li>
        <?php 
if ($isEditor) {
    ?>
            <li>
                <a href="<?php 
    echo Common::getBaseURL();
    ?>
/promotion">Promotions</a>
            </li>
        <?php 
}
?>
 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');
 }