Code (PHP) pasted on 2019-01-13, 19:39 Raw Source
- <?php
- // Method in the ImportService, called during CSV import
- $categoryId = null;
- foreach ($importRules as $rule) {
- if ($rule->appliesToPosition($position)) {
- $categoryId = $rule->getCategoryId();
- break;
- }
- }
- return $categoryId;
- }
- // ImportRule as returned by the ImportRuleService
- class ImportRule {
- /** @var int */
- private $categoryId;
- /** @var string */
- private $categoryName;
- /** @var array */
- private $rules;
- $this->categoryId = $categoryId;
- $this->categoryName = $categoryName;
- $this->rules = $rules;
- }
- public function getCategoryId(): int {
- return $this->categoryId;
- }
- public function getCategoryName(): string {
- return $this->categoryName;
- }
- return $this->rules;
- }
- $this->rules = $rules;
- }
- foreach ($this->rules as $rule) {
- return false;
- return false;
- }
- } else {
- // Field does not exist, so we skip this rule
- return false;
- }
- }
- return true;
- }
- }