Source of file OrderStepField.php
Size: 3,924 Bytes - Last Modified: 2021-12-23T10:39:35+00:00
/var/www/docs.ssmods.com/process/src/src/Forms/Fields/OrderStepField.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 | <?php namespace Sunnysideup\Ecommerce\Forms\Fields; use SilverStripe\Core\Convert; use SilverStripe\Forms\DatalessField; use SilverStripe\Security\Member; use SilverStripe\View\Requirements; use Sunnysideup\Ecommerce\Model\Order; use Sunnysideup\Ecommerce\Model\Process\OrderStep; /** * This field shows the admin (and maybe the customer) where the Order is at (which orderstep). * * @authors: Nicolaas [at] Sunny Side Up .co.nz * @package: ecommerce * @sub-package: forms */ class OrderStepField extends DatalessField { /** * @var string */ protected $content; /** * @param string $name */ public function __construct($name, Order $order, Member $member = null) { if (! $member) { $member = $order->Member(); } if (! $member) { $member = new Member(); } $orderSteps = OrderStep::get(); // $where = '"HideStepFromCustomer" = 0'; $currentStep = $order->CurrentStepVisibleToCustomer(); if ($member->IsShopAdmin()) { $currentStep = $order->MyStep(); } else { $currentStep = $order->CurrentStepVisibleToCustomer(); $orderSteps = $orderSteps ->filter(['HideStepFromCustomer' => 0]) ; } $future = false; $html = ' <div class="orderStepField"> <ol>'; if ($orderSteps->exists()) { foreach ($orderSteps as $orderStep) { if ($orderStep->HideFromEveryone()) { continue; } $description = ''; if ($member->IsShopAdmin()) { if ($orderStep->Description) { $description = ' title="' . Convert::raw2att($orderStep->Description) . '" '; } } $class = ''; if ($orderStep->ID === $currentStep->ID) { $future = true; $class .= ' current'; } elseif ($future) { $class .= ' todo'; } else { $class .= ' done'; } $html .= '<li class="' . $class . '" ' . $description . '><a href="' . $orderStep->CMSEditLink() . '">' . $orderStep->Title . '</a></li>'; } } else { $html .= 'no steps'; } $html .= '</ol><div class="clear"></div></div>'; $this->content = $html; Requirements::themedCSS('client/css/OrderStepField'); parent::__construct($name); } /** * standard SS method. * * @param array $properties * * @return string */ public function FieldHolder($properties = []) { return is_object($this->content) ? $this->content->forTemplate() : $this->content; } /** * standard SS method. * * @param array $properties * * @return string */ public function Field($properties = []) { return $this->FieldHolder(); } /** * Sets the content of this field to a new value. */ public function setContent(string $content): self { $this->content = $content; return $this; } /** * @return string */ public function getContent() { return $this->content; } /** * Synonym of {@link setContent()} so that LiteralField is more compatible with other field types. * * @param mixed $value * @param null|mixed $data */ public function setValue($value, $data = null): self { return $this->setContent($value); } /** * standard SS method. * * @return OrderStepField */ public function performReadonlyTransformation() { $clone = clone $this; $clone->setReadonly(true); return $clone; } } |