Added permissions to Order
This commit is contained in:
@@ -16,18 +16,87 @@ class OrderController extends mfBaseController {
|
||||
|
||||
protected function indexAction() {
|
||||
$this->layout()->setTemplate("Order/Index");
|
||||
$this->layout()->set("orders", OrderModel::getAll());
|
||||
//$this->layout()->set("orders", OrderModel::getAll());
|
||||
|
||||
if($this->me->is("Admin")) {
|
||||
$this->layout()->set("orders", OrderModel::getAll());
|
||||
} else {
|
||||
$orders = [];
|
||||
//var_dump($this->me->my_networks);exit;
|
||||
foreach($this->me->my_networks as $network) {
|
||||
foreach(OrderModel::byNetwork($network->id) as $order) {
|
||||
if(!array_key_exists($order->id, $orders)) {
|
||||
$orders[$order->id] = $order;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach(OrderModel::search(['create_by' => $this->me->id]) as $order) {
|
||||
if(!array_key_exists($order->id, $orders)) {
|
||||
$order[$order->id] = $order;
|
||||
}
|
||||
}
|
||||
|
||||
$this->layout()->set("orders", $orders);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function addAction() {
|
||||
// TODO: filter by network permissions
|
||||
$this->layout()->setTemplate("Order/Form");
|
||||
$this->layout()->set("addresses", AddressModel::search(['parents_only' => 1]));
|
||||
$this->layout()->set("products", ProductModel::getAll());
|
||||
$this->layout()->set("terminations", TerminationModel::getAll());
|
||||
if($this->me->is("Admin")) {
|
||||
$this->layout()->set("addresses", AddressModel::search(['parents_only' => 1]));
|
||||
$this->layout()->set("products", ProductModel::getAll());
|
||||
$this->layout()->set("terminations", TerminationModel::getAll());
|
||||
} else {
|
||||
// get all addresses of my networks
|
||||
$network_ids = [];
|
||||
$addresses = [];
|
||||
foreach($this->me->my_networks as $network) {
|
||||
$network_ids[] = $network->id;
|
||||
foreach(AddressModel::byNetwork($network->id, "salespartner") as $address) {
|
||||
if(!array_key_exists($address->id, $addresses)) {
|
||||
$addresses[] = $address;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$users = [];
|
||||
$user_ids = [];
|
||||
foreach($addresses as $address) {
|
||||
$address_id = $address->id;
|
||||
if($address->parent_id) {
|
||||
$address_id = $address->parent_id;
|
||||
}
|
||||
foreach(UserModel::search(['address_id' => $address_id]) as $user) {
|
||||
if(!array_key_exists($user, $users)) {
|
||||
$users[$user->id] = $user;
|
||||
$user_ids[] = $user->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$addresses = AddressModel::search(['create_by' => $user_ids]);
|
||||
$this->layout()->set("addresses", $addresses);
|
||||
|
||||
// get terminations in my networks
|
||||
$terms = TerminationModel::search(["network_id" => $network_ids]);
|
||||
$this->layout()->set("terminations", $nets);
|
||||
|
||||
|
||||
// get products assigned to my networks
|
||||
$products = [];
|
||||
foreach(ProductNetworkModel::search(["network_id" => $network_ids]) as $pn) {
|
||||
if(!array_key_exists($pn->product_id, $products))
|
||||
$products[$pn->product_id] = $pn->product;
|
||||
}
|
||||
$this->layout()->set("products", $products);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//var_dump(AddressModel::search(['parents_only' => 1]));exit;
|
||||
}
|
||||
|
||||
protected function editAction() {
|
||||
@@ -343,4 +412,5 @@ class OrderController extends mfBaseController {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user