public function index() { $f3 = \Base::instance(); $model = $this->getModel(); $roots = \Admin\Models\Navigation::roots(); $f3->set('roots', $roots); $id = $this->inputfilter->clean($f3->get('PARAMS.id'), 'alnum'); $f3->set('selected', $id); $f3->set('tree', $id); if ($id) { $item = (new \Admin\Models\Navigation())->emptyState()->setState('filter.root', true)->setState('filter.id', $id)->getItem(); $f3->set('item', $item); $paginated = $model->emptyState()->populateState()->setState('filter.root', false)->setState('filter.id', null)->setState('filter.tree', $id)->setState('list.sort', array('tree' => 1, 'lft' => 1))->paginate(); $f3->set('state', $model->getState()); $f3->set('paginated', $paginated); $all = $model->emptyState()->setState('filter.tree', $id)->setState('list.sort', array('tree' => 1, 'lft' => 1))->getList(); $this->app->set('all', $all); } $event = new \Dsc\Event\Event('onAdminNavigationGetQuickAddItems'); $event->addArgument('items', array()); $event->addArgument('tree', $id); $quickadd = \Dsc\System::instance()->getDispatcher()->triggerEvent($event); $f3->set('quickadd', $quickadd); $model = $this->getModel(); $roots = $model->roots(); $this->app->set('roots', $roots); $this->app->set('meta.title', 'Menus'); echo \Dsc\System::instance()->get('theme')->renderTheme('Admin/Views::menus/manage.php'); }
/** * Shortcut for triggering an event within a view * * @param unknown $eventName * @param unknown $arguments */ public function trigger($eventName, $arguments = array()) { $event = new \Dsc\Event\Event($eventName); foreach ($arguments as $key => $value) { $event->addArgument($key, $value); } return \Dsc\System::instance()->getDispatcher()->triggerEvent($event); }
/** * Submits a completed cart checkout processing * */ public function submit() { $cart = \Shop\Models\Carts::fetch(); if ($cart->quantity() <= 0) { $this->app->reroute('/shop/cart'); } $identity = $this->getIdentity(); if (empty($identity->id)) { $flash = \Dsc\Flash::instance(); \Base::instance()->set('flash', $flash); $this->app->set('meta.title', 'Login or Register | Checkout'); $view = \Dsc\System::instance()->get('theme'); echo $view->render('Shop/Site/Views::checkout/identity.php'); return; } $f3 = \Base::instance(); // Update the cart with checkout data from the form $checkout_inputs = $this->input->get('checkout', array(), 'array'); if (!empty($checkout_inputs['billing_address']['same_as_shipping'])) { $checkout_inputs['billing_address']['same_as_shipping'] = true; } else { $checkout_inputs['billing_address']['same_as_shipping'] = false; } $cart_checkout = array_merge((array) $cart->{'checkout'}, $checkout_inputs); $cart->checkout = $cart_checkout; $cart->save(); // Get \Shop\Models\Checkout // Bind the cart and payment data to the checkout model $checkout = \Shop\Models\Checkout::instance(); $checkout->addCart($cart)->addPaymentData($f3->get('POST')); // Fire a beforeShopCheckout event that allows Listeners to hijack the checkout process // Payment processing & authorization could occur at this event, and the Listener would update the checkout object // Add the checkout model to the event $event = new \Dsc\Event\Event('beforeShopCheckout'); $event->addArgument('checkout', $checkout); try { $event = \Dsc\System::instance()->getDispatcher()->triggerEvent($event); } catch (\Exception $e) { $checkout->setError($e->getMessage()); $event->setArgument('checkout', $checkout); } $checkout = $event->getArgument('checkout'); // option 1: ERRORS in checkout from beforeShopCheckout if (!empty($checkout->getErrors())) { // Add the errors to the stack and redirect foreach ($checkout->getErrors() as $exception) { \Dsc\System::addMessage($exception->getMessage(), 'error'); } // redirect to the ./shop/checkout/payment page unless a failure redirect has been set in the session (site.shop.checkout.redirect.fail) $redirect = '/shop/checkout/payment'; if ($custom_redirect = \Dsc\System::instance()->get('session')->get('site.shop.checkout.redirect.fail')) { $redirect = $custom_redirect; } \Dsc\System::instance()->get('session')->set('site.shop.checkout.redirect.fail', null); $f3->reroute($redirect); return; } // option 2: NO ERROR in checkout from beforeShopCheckout // If checkout is not completed, do the standard checkout process // If checkout was completed by a Listener during the beforeShopCheckout process, skip the standard checkout process and go to the afterShopCheckout event if (!$checkout->orderAccepted()) { // the standard checkout process try { // failed payment processing should throw an exception $checkout->processPayment(); } catch (\Exception $e) { \Dsc\System::addMessage($e->getMessage(), 'error'); // redirect to the ./shop/checkout/payment page unless a failure redirect has been set in the session (site.shop.checkout.redirect.fail) $redirect = '/shop/checkout/payment'; if ($custom_redirect = \Dsc\System::instance()->get('session')->get('site.shop.checkout.redirect.fail')) { $redirect = $custom_redirect; } \Dsc\System::instance()->get('session')->set('site.shop.checkout.redirect.fail', null); $this->app->reroute($redirect); return; } try { $checkout->acceptOrder(); } catch (\Exception $e) { $checkout->setError($e->getMessage()); } if (!$checkout->orderAccepted() || !empty($checkout->getErrors())) { \Dsc\System::addMessage('Checkout could not be completed. Please try again or contact us if you have further difficulty.', 'error'); // Add the errors to the stack and redirect foreach ($checkout->getErrors() as $exception) { \Dsc\System::addMessage($exception->getMessage(), 'error'); } // redirect to the ./shop/checkout/payment page unless a failure redirect has been set in the session (site.shop.checkout.redirect.fail) $redirect = '/shop/checkout/payment'; if ($custom_redirect = \Dsc\System::instance()->get('session')->get('site.shop.checkout.redirect.fail')) { $redirect = $custom_redirect; } \Dsc\System::instance()->get('session')->set('site.shop.checkout.redirect.fail', null); $f3->reroute($redirect); return; } } // the order WAS accepted // Fire an afterShopCheckout event $event_after = new \Dsc\Event\Event('afterShopCheckout'); $event_after->addArgument('checkout', $checkout); try { $event_after = \Dsc\System::instance()->getDispatcher()->triggerEvent($event_after); } catch (\Exception $e) { \Dsc\System::addMessage($e->getMessage(), 'warning'); } // Redirect to ./shop/checkout/confirmation unless a site.shop.checkout.redirect has been set $redirect = '/shop/checkout/confirmation'; if ($custom_redirect = \Dsc\System::instance()->get('session')->get('site.shop.checkout.redirect')) { $redirect = $custom_redirect; } \Dsc\System::instance()->get('session')->set('site.shop.checkout.redirect', null); $f3->reroute($redirect); return; }
/** * Perform logout actions (e.g. trigger Listeners, etc) * and logout the user * */ public function logout($destroy = false) { $global_app_name = \Base::instance()->get('APP_NAME'); $identity = $this->getIdentity(); // Trigger plugin event for before logout $event = new \Dsc\Event\Event('beforeUserLogout'); $event->addArgument('identity', $identity)->addArgument('global_app', $global_app_name); \Dsc\System::instance()->getDispatcher()->triggerEvent($event); // actually logout the user if (!empty($destroy)) { // completely kill the session \Dsc\System::instance()->get('session')->destroy(); } else { $this->remove(); \Dsc\System::instance()->get('session')->removeAppSpace(); } //forget the remember me cookie \Dsc\Cookie::forget('remember'); // Trigger plugin event for after logout $event = new \Dsc\Event\Event('afterUserLogout'); $event->addArgument('identity', $identity)->addArgument('global_app', $global_app_name); \Dsc\System::instance()->getDispatcher()->triggerEvent($event); }