61 lines
1.8 KiB
PHP
61 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Cells;
|
|
|
|
use App\Cells\BaseCell;
|
|
use App\Models\DeviceModel;
|
|
use App\Models\ProductDeviceModel;
|
|
|
|
class ProductCell extends BaseCell
|
|
{
|
|
private $_deviceModel = null;
|
|
private $_productDeviceModel = null;
|
|
|
|
final protected function getDeviceModel(): DeviceModel
|
|
{
|
|
return $this->_deviceModel = $this->_deviceModel ?: new DeviceModel();
|
|
}
|
|
final protected function getProductDeviceModel(): ProductDeviceModel
|
|
{
|
|
return $this->_productDeviceModel = $this->_productDeviceModel ?: new ProductDeviceModel();
|
|
}
|
|
|
|
public function device(array $cellDatas = [])
|
|
{
|
|
$cellDatas['deviceEntitys'] = [];
|
|
foreach ($this->getDeviceModel()->getEntitys() as $deviceEntity) {
|
|
$cellDatas['deviceEntitys'][$deviceEntity->getPrimaryKey()] = $deviceEntity;
|
|
}
|
|
$cellDatas['categorys'] = DEVICE['CATEGORYS'];
|
|
$cellDatas['selecteds'] = [];
|
|
foreach ($cellDatas['categorys'] as $category) {
|
|
$cellDatas['selecteds'][$category] = [];
|
|
}
|
|
if (array_key_exists('entity', $cellDatas)) {
|
|
foreach ($this->getProductDeviceModel()->getEntitys(
|
|
['product_uid' => $cellDatas['entity']->getPrimaryKey()]
|
|
) as $productDevieceEntity) {
|
|
$cellDatas['selecteds'][$cellDatas['deviceEntitys'][$productDevieceEntity->device_uid]->getCategory()][$productDevieceEntity->getPrimaryKey()] = $productDevieceEntity;
|
|
}
|
|
}
|
|
$cellDatas['device'] = [];
|
|
$cellDatas['device']['options'] = $this->getDeviceModel()->getOptions();
|
|
//dd($cellDatas);
|
|
return view(
|
|
'Views/cells/product/' . __FUNCTION__,
|
|
['cellDatas' => $cellDatas]
|
|
);
|
|
}
|
|
|
|
public function device_calulator(array $cellDatas = []): string
|
|
{
|
|
$cellDatas['categorys'] = DEVICE['CATEGORYS'];
|
|
$cellDatas['device'] = [];
|
|
$cellDatas['device']['options'] = $this->getDeviceModel()->getOptions();
|
|
return view(
|
|
'Views/cells/product/' . __FUNCTION__,
|
|
['cellDatas' => $cellDatas]
|
|
);
|
|
}
|
|
}
|