Пример #1
0
 /**
  * Returns the absolute file path.
  * @param \Cms\Classes\ComponentBase $component Specifies a component the file belongs to.
  * @param string$fileName Specifies the file name to return the path to.
  * @return string
  */
 public static function getFilePath($component, $fileName)
 {
     $path = $component->getPath() . '/' . $fileName;
     /*
      * Check the shared "/partials" directory for the partial
      */
     if (!File::isFile($path)) {
         $sharedDir = dirname($component->getPath()) . '/partials';
         $sharedPath = $sharedDir . '/' . $fileName;
         if (File::isFile($sharedPath)) {
             return $sharedPath;
         }
     }
     return $path;
 }
Пример #2
0
 /**
  * {@inheritDoc}
  */
 public function __construct($cmsObject, $properties, $errorMessage)
 {
     $this->errorMessage = $errorMessage;
     $this->componentCssClass = 'error-component';
     $this->inspectorEnabled = false;
     parent::__construct($cmsObject, $properties);
 }
Пример #3
0
 public function __call($method, $parameters)
 {
     if (array_key_exists($method, $this->properties) && !method_exists($this, $method)) {
         return $this->properties[$method];
     }
     return parent::__call($method, $parameters);
 }
 /**
  * RandomImages constructor.
  *
  * Get an MediaLibrary instance to work with.
  *
  * @param CodeBase|null $cmsObject
  * @param array         $properties
  */
 public function __construct(CodeBase $cmsObject = null, $properties = [], $mediaLibrary = null)
 {
     parent::__construct($cmsObject, $properties);
     $this->mediaLibrary = $mediaLibrary ?: MediaLibrary::instance();
     $storagePath = rtrim(Config::get('cms.storage.media.path', '/storage/app/media'), '/');
     $this->storagePath = str_replace('/storage', '', $storagePath);
 }
Пример #5
0
 public function __construct(CodeBase $cmsObject = null, $properties = [])
 {
     parent::__construct($cmsObject, $properties);
     // Remove extra component from end
     if (ends_with($this->dirName, 'component')) {
         $this->dirName = substr($this->dirName, 0, -9);
     }
 }
Пример #6
0
 public function onRun()
 {
     $categories = ProductAttributes::select('value')->where('key', 'category')->groupBy('value')->get();
     // @see https://octobercms.com/docs/database/collection
     $orderBy = $this->property('orderBy');
     if ($orderBy == 'slug:orderBy') {
         $orderBy = $this->param('orderBy');
     }
     switch ($orderBy) {
         case 'name':
             $categories = $categories->sort(function ($c1, $c2) {
                 return strcmp($c1->value, $c2->value);
             });
             break;
     }
     $this->categories = $categories;
     $this->addCss("styles/index.css");
     return parent::onRun();
 }
Пример #7
0
 /**
  * Sets component property values from partial parameters.
  * The property values should be defined as {{ param }}.
  * @param ComponentBase $component The component object.
  * @param array $parameters Specifies the partial parameters.
  * @return Returns updated properties.
  */
 protected function setComponentPropertiesFromParams($component, $parameters = [])
 {
     $properties = $component->getProperties();
     $routerParameters = $this->router->getParameters();
     foreach ($properties as $propertyName => $propertyValue) {
         $matches = [];
         if (preg_match('/^\\{\\{([^\\}]+)\\}\\}$/', $propertyValue, $matches)) {
             $paramName = trim($matches[1]);
             if (substr($paramName, 0, 1) == ':') {
                 $routeParamName = substr($paramName, 1);
                 $newPropertyValue = array_key_exists($routeParamName, $routerParameters) ? $routerParameters[$routeParamName] : null;
             } else {
                 $newPropertyValue = array_key_exists($paramName, $parameters) ? $parameters[$paramName] : null;
             }
             $component->setProperty($propertyName, $newPropertyValue);
             $component->setExternalPropertyName($propertyName, $paramName);
         }
     }
 }
Пример #8
0
 public function onRun()
 {
     $this->product = Product::findOrFail($this->param('id'));
     // $this->addCss("styles/index.css");
     return parent::onRun();
 }
Пример #9
0
 /**
  * TicketForm constructor.
  *
  * @param \Cms\Classes\CodeBase $cmsObject
  * @param array                 $properties
  */
 public function __construct(\Cms\Classes\CodeBase $cmsObject = null, array $properties = [])
 {
     parent::__construct($cmsObject, $properties);
     $this->helpers = new SupportHelpers();
 }
Пример #10
0
 public function __construct(CodeBase $cmsObject = null, $properties = [])
 {
     parent::__construct($cmsObject, $properties);
 }
Пример #11
0
 /**
  * Returns the absolute file path.
  * @param \Cms\Classes\ComponentBase $component Specifies a component the file belongs to.
  * @param string$fileName Specifies the file name to return the path to.
  * @return string
  */
 public static function getFilePath($component, $fileName)
 {
     return $component->getPath() . '/' . $fileName;
 }
Пример #12
0
 public function __construct(CodeBase $cmsObject = null, $properties = [], Users $users)
 {
     parent::__construct($cmsObject, $properties);
     $this->users = $users;
 }
Пример #13
0
 public function onRun()
 {
     // $products = Product::where('active', true)->orderBy('url', 'ASC')->get();
     $products = Product::all();
     // @see https://octobercms.com/docs/database/collection
     // remove items without a log
     $products = $products->filter(function ($product) {
         return $product->lastLog();
     });
     if ($this->property('active') !== '' && $this->property('active') !== null) {
         $filter = (int) $this->property('active');
         if ($filter == 'slug:active') {
             $filter = (int) $this->param('active');
         }
         $products = $products->filter(function ($product) use($filter) {
             return $product->active == $filter;
         });
     }
     if ($this->property('category')) {
         $filter = $this->property('category');
         if ($filter == 'slug:category') {
             $filter = $this->param('category');
         }
         if ($filter == ':all') {
             $products = $products->filter(function ($product) use($filter) {
                 return 1;
             });
         } elseif ($filter == ':uncategorized') {
             $products = $products->filter(function ($product) use($filter) {
                 $hasCtg = $product->productAttributes() && $product->productAttributes()['category'] && $product->productAttributes()['category']->value;
                 return !$hasCtg;
             });
         } else {
             $products = $products->filter(function ($product) use($filter) {
                 return $product->productAttributes() && $product->productAttributes()['category'] && $product->productAttributes()['category']->value == $filter;
             });
         }
     }
     if ($this->property('spider')) {
         $filter = $this->property('spider');
         if ($filter == 'slug:spider') {
             $filter = $this->param('spider');
         }
         $products = $products->filter(function ($product) use($filter) {
             return $product->spider == $filter;
         });
     }
     if ($this->property('showOnlyWithPrice')) {
         $filter = $this->property('showOnlyWithPrice');
         if ($filter == 'slug:showOnlyWithPrice') {
             $filter = $this->param('showOnlyWithPrice');
         }
         $products = $products->filter(function ($product) use($filter) {
             switch ($filter) {
                 case 'min':
                     return $product->lastLog()->price == $product->minPrice();
                     break;
                 case 'max':
                     return $product->lastLog()->price == $product->maxPrice();
                     break;
                 case 'min:10%':
                     $diff = $product->maxPrice() - $product->minPrice();
                     return $product->lastLog()->price <= $product->minPrice() + $diff * 0.1;
                     break;
                 case 'min:25%':
                     $diff = $product->maxPrice() - $product->minPrice();
                     return $product->lastLog()->price <= $product->minPrice() + $diff * 0.25;
                     break;
                 case 'min:50%':
                     $diff = $product->maxPrice() - $product->minPrice();
                     return $product->lastLog()->price <= $product->minPrice() + $diff * 0.5;
                     break;
                 default:
                     throw new \Exception("Invalid value for showOnlyWithPrice");
             }
         });
     }
     $orderBy = $this->property('orderBy');
     if ($orderBy == 'slug:orderBy') {
         $orderBy = $this->param('orderBy');
     }
     switch ($orderBy) {
         case 'name':
             $products = $products->sort(function ($p1, $p2) {
                 return strcmp($p1->name, $p2->name);
             });
             break;
         case 'price':
             $products = $products->sort(function ($p1, $p2) {
                 return $p1->lastLog()->price - $p2->lastLog()->price;
             });
             break;
         case 'quantity':
             $products = $products->sort(function ($p1, $p2) {
                 if ($p1->productAttributes() && $p1->productAttributes()['quantity']) {
                     return (double) $p1->productAttributes()['quantity']->value - (double) $p2->productAttributes()['quantity']->value;
                 }
                 return 0;
             });
             break;
         case 'pricePerUnit':
             $products = $products->sort(function ($p1, $p2) {
                 $ret = 0;
                 if ($ret == 0 && $p1->productAttributes() && isset($p1->productAttributes()['quantity']) && $p1->productAttributes()['quantity']->value && $p2->productAttributes() && isset($p2->productAttributes()['quantity']) && $p2->productAttributes()['quantity']->value && $p1->lastLog()->price && $p2->lastLog()->price) {
                     $pu1 = (double) $p1->lastLog()->price / (double) $p1->productAttributes()['quantity']->value;
                     $pu2 = (double) $p2->lastLog()->price / (double) $p2->productAttributes()['quantity']->value;
                     return ($pu1 - $pu2) * 100;
                     // usort should return integer numbers, so that 1.99 != 1.01
                 }
                 if ($ret == 0) {
                     if ($p1->lastLog() && $p2->lastLog()) {
                         $ret = $p1->lastLog()->price - $p2->lastLog()->price;
                     }
                 }
                 return $ret;
             });
             break;
         case 'category,pricePerUnit':
             $products = $products->sort(function ($p1, $p2) {
                 $ret = 0;
                 if ($ret == 0) {
                     if ($p1->productAttributes() && $p1->productAttributes()['category'] && $p1->productAttributes()['category']->value && $p2->productAttributes() && $p2->productAttributes()['category'] && $p2->productAttributes()['category']->value) {
                         $ret = strcmp($p1->productAttributes()['category']->value, $p2->productAttributes()['category']->value);
                     }
                 }
                 if ($ret == 0 && $p1->productAttributes() && isset($p1->productAttributes()['quantity']) && $p1->productAttributes()['quantity']->value && $p2->productAttributes() && isset($p2->productAttributes()['quantity']) && $p2->productAttributes()['quantity']->value && $p1->lastLog()->price && $p2->lastLog()->price) {
                     $pu1 = (double) $p1->lastLog()->price / (double) $p1->productAttributes()['quantity']->value;
                     $pu2 = (double) $p2->lastLog()->price / (double) $p2->productAttributes()['quantity']->value;
                     return ($pu1 - $pu2) * 100;
                     // usort should return integer numbers, so that 1.99 != 1.01
                 }
                 if ($ret == 0) {
                     if ($p1->lastLog() && $p2->lastLog()) {
                         $ret = $p1->lastLog()->price - $p2->lastLog()->price;
                     }
                 }
                 return $ret;
             });
             break;
         case 'quantity,price':
             $products = $products->sort(function ($p1, $p2) {
                 $ret = 0;
                 if ($ret == 0 && $p1->productAttributes() && isset($p1->productAttributes()['category']) && $p1->productAttributes()['category']->value && $p2->productAttributes() && isset($p2->productAttributes()['category']) && $p2->productAttributes()['category']->value) {
                     $ret = strcmp($p1->productAttributes()['category']->value, $p2->productAttributes()['category']->value);
                 }
                 if ($ret == 0 && $p1->productAttributes() && isset($p1->productAttributes()['quantity']) && $p1->productAttributes()['quantity']->value && $p2->productAttributes() && isset($p2->productAttributes()['quantity']) && $p2->productAttributes()['quantity']->value) {
                     $ret = (double) $p1->productAttributes()['quantity']->value - (double) $p2->productAttributes()['quantity']->value;
                 }
                 if ($ret == 0) {
                     if ($p1->lastLog() && $p2->lastLog()) {
                         $ret = $p1->lastLog()->price - $p2->lastLog()->price;
                     }
                 }
                 return $ret;
             });
             $stats = array();
             foreach ($products as $p1) {
                 if ($p1->productAttributes() && isset($p1->productAttributes()['quantity']) && $p1->productAttributes()['quantity']->value) {
                     $stats[$p1->productAttributes()['quantity']->value]['price'][] = $p1->lastLog()->price;
                 }
             }
             foreach ($products as $p1) {
                 if ($p1->productAttributes() && isset($p1->productAttributes()['quantity']) && $p1->productAttributes()['quantity']->value) {
                     $this->markedElements[$p1->id] = array('priceMin' => min($stats[$p1->productAttributes()['quantity']->value]['price']) == $p1->lastLog()->price, 'priceMax' => max($stats[$p1->productAttributes()['quantity']->value]['price']) == $p1->lastLog()->price);
                 }
             }
             break;
     }
     #var_dump($products);die();
     $this->products = $products;
     $this->addCss("styles/index.css");
     return parent::onRun();
 }