vhost/app/Cells/ProductCell.php
2024-05-20 19:18:29 +09:00

55 lines
1.6 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['defaults'] = [];
if (array_key_exists('entity', $cellDatas)) {
foreach ($this->getProductDeviceModel()->getEntitys(
['product_uid' => $cellDatas['entity']->getPrimaryKey()]
) as $productDevieceEntity) {
$cellDatas['defaults'][$productDevieceEntity->device_uid] = $productDevieceEntity;
}
}
$cellDatas['device'] = [];
$cellDatas['device']['categorys'] = ['server', 'cpu', 'memory', 'disk', 'nic', 'publicip', 'os'];
$cellDatas['device']['options'] = $this->getDeviceModel()->getOptions();
//dd($cellDatas);
return view(
'Views/cells/product/' . __FUNCTION__,
['cellDatas' => $cellDatas]
);
}
public function device_calulator(array $cellDatas = []): string
{
$cellDatas['device'] = [];
$cellDatas['device']['categorys'] = ['server', 'cpu', 'memory', 'disk', 'nic', 'publicip', 'os'];
$cellDatas['device']['options'] = $this->getDeviceModel()->getOptions();
return view(
'Views/cells/product/' . __FUNCTION__,
['cellDatas' => $cellDatas]
);
}
}