Eshop-Laravel/app/Http/Controllers/CmsController.php

76 lines
2 KiB
PHP
Raw Permalink Normal View History

2019-10-18 09:25:37 +00:00
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\User;
use App\Order;
use App\Http\Requests\UpdateProfile;
class CmsController extends MainController
{
// public function dashboard(){
// self::$data['user'] = User::getUserInfo();
// return view('cms.cms-home' , self::$data);
// }
public function home(){
$users= self::$data['users'] = User::getAllUsers();
self::$data['totalOrders'] = self::filter(Order::getAllTotalOrders($users));
return view('cms.cms-home' , self::$data);
}
static public function filter($array){
$new = [];
foreach ($array as $value) {
$sum =0;
foreach ($value as $key) {
$sum = $sum + $key ->total;
}
$new[] = $sum;
}
return $new;
}
public function addLinks(){
return view('cms.cms-addLinks');
}
public function articles(){
return view('cms.articles');
}
public function charts(){
return view('cms.cms-charts' , self::$data);
}
public function usersInfo($uid){
$user = self::$data['user'] = User::getUserInfoCms($uid);
$orders = self::$data['userOrdes'] = Order::getUserOrders($user);
$total = Order::getAllTotalOrders($user);
self::$data['userTotalOrder'] = self::filter($total)[0];
return view('cms.cms-usersInfo' , self::$data);
}
static public function postUserInfo(UpdateProfile $request , $uid){
User::updateUserCms($request , $uid);
$users= self::$data['users'] = User::getAllUsers();
self::$data['totalOrders'] = self::filter(Order::getAllTotalOrders($users));
return view('cms.cms-home' , self::$data);
}
public function getUserOrders($uid){
self::$data['orders'] = Order::getUserOrders(User::getUserInfoCms($uid) );
return view('cms.showUserOrders' , self::$data);
}
public function getOrderById($oid){
self::$data['order'] = Order::getOrder($oid);
return view('cms.userOrder' , self::$data);
}
}