Source of file AccountControllerExtension.php
Size: 4,986 Bytes - Last Modified: 2021-12-23T10:24:32+00:00
/var/www/docs.ssmods.com/process/src/src/extensions/AccountControllerExtension.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 | <?php namespace SilverCommerce\OrdersAdmin\Extensions; use SilverStripe\i18n\i18n; use SilverStripe\Forms\Form; use SilverStripe\Core\Extension; use SilverStripe\View\ArrayData; use SilverStripe\Forms\TextField; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\FormAction; use SilverStripe\ORM\PaginatedList; use SilverStripe\Forms\HeaderField; use SilverStripe\Forms\HiddenField; use SilverStripe\Security\Security; use SilverStripe\Forms\LiteralField; use SilverStripe\Forms\CheckboxField; use SilverStripe\Forms\DropdownField; use SilverStripe\Forms\CompositeField; use SilverStripe\Forms\RequiredFields; use SilverStripe\ORM\ValidationResult; use SilverCommerce\ContactAdmin\Model\ContactLocation; use ilateral\SilverStripe\Users\Control\AccountController; /** * Add extra fields to a user account (if the users module is * installed) to allow logged in users to see their invoices. * * @package orders */ class AccountControllerExtension extends Extension { /** * Add extra URL endpoints * * @var array */ private static $allowed_actions = [ "history", "outstanding" ]; public function updateIndexSections($sections) { $member = Security::getCurrentUser(); $outstanding = $member->OutstandingInvoices()->limit(5); $sections->push(ArrayData::create([ "Title" => _t('Orders.OutstandingOrders', 'Outstanding Orders'), "Content" => $this->owner->renderWith( "SilverCommerce\\OrdersAdmin\\Includes\\OrdersList", ["List" => $outstanding] ) ])); $historic = $member->HistoricInvoices()->limit(5); $sections->push(ArrayData::create([ "Title" => _t('Orders.OrderHistory', 'Order History'), "Content" => $this->owner->renderWith( "SilverCommerce\\OrdersAdmin\\Includes\\OrdersList", ["List" => $historic] ) ])); } /** * Display all historic orders for the current user * * @return HTMLText */ public function history() { $member = Security::getCurrentUser(); $list = PaginatedList::create( $member->HistoricInvoices(), $this->owner->getRequest() ); $this ->owner ->customise([ "Title" => _t('Orders.OrderHistory', 'Order History'), "MenuTitle" => _t('Orders.OrderHistory', 'Order History'), "Content" => $this->owner->renderWith( "SilverCommerce\\OrdersAdmin\\Includes\\OrdersList", ["List" => $list] ) ]); $this->owner->extend("updateHistoricOrders", $orders); return $this ->owner ->renderWith([ 'AccountController_history', AccountController::class . '_history', 'AccountController', AccountController::class, 'Page' ]); } /** * Display all outstanding orders for the current user * * @return HTMLText */ public function outstanding() { $member = Security::getCurrentUser(); $list = PaginatedList::create( $member->OutstandingInvoices(), $this->owner->getRequest() ); $this->owner->customise([ "Title" => _t('Orders.OutstandingOrders', 'Outstanding Orders'), "MenuTitle" => _t('Orders.OutstandingOrders', 'Outstanding Orders'), "Content" => $this->owner->renderWith( "SilverCommerce\\OrdersAdmin\\Includes\\OrdersList", ["List" => $list] ) ]); $this->owner->extend("updateOutstandingOrders", $orders); return $this ->owner ->renderWith([ 'AccountController_outstanding', AccountController::class . '_outstanding', 'AccountController', AccountController::class, 'Page' ]); } /** * Add commerce specific links to account menu * * @param ArrayList $menu */ public function updateAccountMenu($menu) { $curr_action = $this ->owner ->getRequest() ->param("Action"); $menu->add(ArrayData::create([ "ID" => 1, "Title" => _t('Orders.OutstandingOrders', 'Outstanding Orders'), "Link" => $this->owner->Link("outstanding"), "LinkingMode" => ($curr_action == "outstanding") ? "current" : "link" ])); $menu->add(ArrayData::create([ "ID" => 2, "Title" => _t('Orders.OrderHistory', "Order history"), "Link" => $this->owner->Link("history"), "LinkingMode" => ($curr_action == "history") ? "current" : "link" ])); } } |