Source of file SecondHandProductController.php
Size: 2,083 Bytes - Last Modified: 2021-12-23T10:41:14+00:00
/var/www/docs.ssmods.com/process/src/src/SecondHandProductController.php
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 | <?php namespace Sunnysideup\EcommerceSecondHandProduct; use SilverStripe\ORM\ArrayList; use SilverStripe\ORM\FieldType\DBField; use SilverStripe\Security\Permission; use SilverStripe\Security\Security; use SilverStripe\View\ArrayData; use Sunnysideup\Ecommerce\Pages\ProductController; class SecondHandProductController extends ProductController { private static $fields_to_remove_from_print = []; private static $allowed_actions = [ 'printview' => true, ]; public function printview() { if (! Permission::check('CMS_ACCESS_SECOND_HAND_PRODUCTS')) { return Security::permissionFailure($this, 'You do not have access to this feature, please login first.'); } return $this->RenderWith('SecondHandProduct_printview'); } public function ListOfFieldsForPrinting() { $al = ArrayList::create(); $fieldsWeNeed = $this->dataRecord->stat('db'); $labels = $this->FieldLabels(); foreach (array_keys($fieldsWeNeed) as $fieldKey) { if (in_array($fieldKey, self::$fields_to_remove_from_print, true)) { unset($fieldsWeNeed[$fieldKey]); } else { $fieldsWeNeed[$fieldKey] = $labels[$fieldKey]; } } $fields = $this->dataRecord->Config()->get('db'); foreach ($fieldsWeNeed as $key => $description) { if (isset($fields[$key])) { $type = preg_replace('/\(.*\)/', '', $fields[$key]); $dbField = DBField::create_field($type, $this->{$key}); if ($dbField->hasMethod('Nice')) { $value = $dbField->Nice(); } else { $value = $dbField->Raw(); } } else { $value = ''; } $al->push( ArrayData::create( [ 'Key' => $description, 'Value' => $value, ] ) ); } return $al; } } |