ltsecurityinc安防产品在线商城代码
This commit is contained in:
+158
@@ -0,0 +1,158 @@
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* Copyright (c) 2021
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Olegnax\Carousel\Model\Slide;
|
||||
|
||||
use Magento\Catalog\Model\Category\FileInfo;
|
||||
use Magento\Framework\App\ObjectManager;
|
||||
use Magento\Framework\App\Request\DataPersistorInterface;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Magento\Ui\DataProvider\AbstractDataProvider;
|
||||
use Olegnax\Carousel\Api\Data\SlideInterface;
|
||||
use Olegnax\Carousel\Model\ResourceModel\Slide\CollectionFactory;
|
||||
use Olegnax\Carousel\Model\Slide;
|
||||
|
||||
|
||||
class DataProvider extends AbstractDataProvider
|
||||
{
|
||||
|
||||
protected $dataPersistor;
|
||||
|
||||
protected $collection;
|
||||
|
||||
protected $loadedData;
|
||||
protected $fileInfo;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $primaryFieldName
|
||||
* @param string $requestFieldName
|
||||
* @param CollectionFactory $collectionFactory
|
||||
* @param DataPersistorInterface $dataPersistor
|
||||
* @param array $meta
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(
|
||||
$name,
|
||||
$primaryFieldName,
|
||||
$requestFieldName,
|
||||
CollectionFactory $collectionFactory,
|
||||
DataPersistorInterface $dataPersistor,
|
||||
array $meta = [],
|
||||
array $data = []
|
||||
) {
|
||||
$this->collection = $collectionFactory->create();
|
||||
$this->dataPersistor = $dataPersistor;
|
||||
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getData()
|
||||
{
|
||||
if (isset($this->loadedData)) {
|
||||
return $this->loadedData;
|
||||
}
|
||||
$items = $this->collection->getItems();
|
||||
foreach ($items as $model) {
|
||||
$data = $model->getData();
|
||||
$data = $this->convertValues($data, $model);
|
||||
$this->loadedData[$model->getId()] = $data;
|
||||
}
|
||||
$data = $this->dataPersistor->get('olegnax_carousel_slide');
|
||||
|
||||
if (!empty($data)) {
|
||||
$model = $this->collection->getNewEmptyItem();
|
||||
$model->setData($data);
|
||||
$this->loadedData[$model->getId()] = $model->getData();
|
||||
$this->dataPersistor->clear('olegnax_carousel_slide');
|
||||
}
|
||||
|
||||
return $this->loadedData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param Slide $model
|
||||
* @return mixed
|
||||
*/
|
||||
protected function convertValues($data, $model)
|
||||
{
|
||||
$data = $this->convertImage($data, $model, SlideInterface::IMAGE);
|
||||
$data = $this->convertImage($data, $model, SlideInterface::MOBILE_IMAGE);
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param Slide $model
|
||||
* @param string $attributeCode
|
||||
* @return mixed
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
private function convertImage($data, $model, $attributeCode){
|
||||
if (isset($data[$attributeCode]) && !empty($data[$attributeCode])) {
|
||||
unset($data[$attributeCode]);
|
||||
$fileName = $model->getData($attributeCode);
|
||||
$fileInfo = $this->getFileInfo();
|
||||
if ($fileInfo->isExist($fileName)) {
|
||||
$stat = $fileInfo->getStat($fileName);
|
||||
$mime = $fileInfo->getMimeType($fileName);
|
||||
|
||||
// phpcs:ignore Magento2.Functions.DiscouragedFunction
|
||||
$data[$attributeCode][0]['name'] = basename($fileName);
|
||||
|
||||
if ($fileInfo->isBeginsWithMediaDirectoryPath($fileName)) {
|
||||
$data[$attributeCode][0]['url'] = $fileName;
|
||||
} else {
|
||||
$data[$attributeCode][0]['url'] = $model->getImageUrl($attributeCode);
|
||||
}
|
||||
|
||||
$data[$attributeCode][0]['size'] = isset($stat) ? $stat['size'] : 0;
|
||||
$data[$attributeCode][0]['type'] = $mime;
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get FileInfo instance
|
||||
*
|
||||
* @return FileInfo
|
||||
*
|
||||
* @deprecated 102.0.0
|
||||
*/
|
||||
private function getFileInfo(): FileInfo
|
||||
{
|
||||
if ($this->fileInfo === null) {
|
||||
$this->fileInfo = ObjectManager::getInstance()->get(FileInfo::class);
|
||||
}
|
||||
return $this->fileInfo;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Olegnax\Carousel\Model\Slide\Source;
|
||||
|
||||
use Magento\Framework\Option\ArrayInterface;
|
||||
|
||||
class ButtonStyle implements ArrayInterface
|
||||
{
|
||||
|
||||
public function toOptionArray() {
|
||||
return [
|
||||
[
|
||||
'value' => '',
|
||||
'label' => __('Theme')
|
||||
],
|
||||
[
|
||||
'value' => 'simple',
|
||||
'label' => __('Simple')
|
||||
],
|
||||
[
|
||||
'value' => 'naked',
|
||||
'label' => __('Naked')
|
||||
],
|
||||
[
|
||||
'value' => 'outline',
|
||||
'label' => __('OutLine')
|
||||
],
|
||||
[
|
||||
'value' => 'underline',
|
||||
'label' => __('Underlined')
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Olegnax\Carousel\Model\Slide\Source;
|
||||
|
||||
use Magento\Framework\Data\Collection;
|
||||
use Magento\Framework\Option\ArrayInterface;
|
||||
use Olegnax\Carousel\Model\ResourceModel\Carousel\CollectionFactory;
|
||||
|
||||
class Carousel implements ArrayInterface
|
||||
{
|
||||
|
||||
protected $collection;
|
||||
|
||||
public function __construct(
|
||||
CollectionFactory $collection
|
||||
) {
|
||||
$this->collection = $collection->create()->addFieldToSelect('*')->setOrder('title', Collection::SORT_ORDER_ASC);
|
||||
}
|
||||
|
||||
public function toArray()
|
||||
{
|
||||
$array = [];
|
||||
foreach ($this->toOptionArray() as $item) {
|
||||
$array[$item['value']] = $item['label'];
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
|
||||
public function toOptionArray()
|
||||
{
|
||||
|
||||
$options = [];
|
||||
foreach ($this->collection as $carousel) {
|
||||
$options[] = [
|
||||
'value' => $carousel->getIdentifier(),
|
||||
'label' => $carousel->getTitle()
|
||||
];
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Olegnax\Carousel\Model\Slide\Source;
|
||||
|
||||
use Magento\Framework\Option\ArrayInterface;
|
||||
|
||||
class Layout implements ArrayInterface
|
||||
{
|
||||
|
||||
public function toOptionArray() {
|
||||
return [
|
||||
[
|
||||
'value' => 'left',
|
||||
'label' => __('Left')
|
||||
],
|
||||
[
|
||||
'value' => 'right',
|
||||
'label' => __('Right')
|
||||
],
|
||||
[
|
||||
'value' => 'center',
|
||||
'label' => __('Center')
|
||||
],
|
||||
[
|
||||
'value' => '2-col',
|
||||
'label' => __('2 Columns')
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Olegnax\Carousel\Model\Slide\Source;
|
||||
|
||||
use Magento\Framework\Option\ArrayInterface;
|
||||
|
||||
class Margins implements ArrayInterface
|
||||
{
|
||||
|
||||
public function toOptionArray() {
|
||||
return [
|
||||
[
|
||||
'value' => 'normal',
|
||||
'label' => __('Normal')
|
||||
],
|
||||
[
|
||||
'value' => 'big',
|
||||
'label' => __('Big')
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Olegnax\Carousel\Model\Slide\Source;
|
||||
|
||||
use Magento\Framework\Option\ArrayInterface;
|
||||
|
||||
class MobileAlign implements ArrayInterface
|
||||
{
|
||||
|
||||
public function toOptionArray() {
|
||||
return [
|
||||
[
|
||||
'value' => 'left',
|
||||
'label' => __('Left')
|
||||
],
|
||||
[
|
||||
'value' => 'right',
|
||||
'label' => __('Right')
|
||||
],
|
||||
[
|
||||
'value' => 'center',
|
||||
'label' => __('Center')
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Olegnax\Carousel\Model\Slide\Source;
|
||||
|
||||
use Magento\Framework\Option\ArrayInterface;
|
||||
|
||||
class TitleSize implements ArrayInterface
|
||||
{
|
||||
|
||||
public function toOptionArray() {
|
||||
return [
|
||||
[
|
||||
'value' => '',
|
||||
'label' => __('Normal')
|
||||
],
|
||||
[
|
||||
'value' => 'big',
|
||||
'label' => __('Medium')
|
||||
],
|
||||
[
|
||||
'value' => 'huge',
|
||||
'label' => __('Big')
|
||||
],
|
||||
[
|
||||
'value' => 'huge-6vw',
|
||||
'label' => __('Huge')
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Olegnax\Carousel\Model\Slide\Source;
|
||||
|
||||
use Magento\Framework\Option\ArrayInterface;
|
||||
|
||||
class Wrappers implements ArrayInterface
|
||||
{
|
||||
|
||||
public function toOptionArray() {
|
||||
return [
|
||||
[
|
||||
'value' => 'container',
|
||||
'label' => __('Container')
|
||||
],
|
||||
[
|
||||
'value' => 'no-container',
|
||||
'label' => __('No Container')
|
||||
],
|
||||
[
|
||||
'value' => 'raw',
|
||||
'label' => __('Raw')
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user