88 lines
3.1 KiB
PHP
88 lines
3.1 KiB
PHP
<?
|
|
|
|
namespace controller\shop\item\value;
|
|
|
|
use shop\core\structure\shopControllerTable;
|
|
use shop\Item;
|
|
use shop\item\Value;
|
|
use shop\Property;
|
|
use shop\property\structure\ePropertyType;
|
|
use ui\Form;
|
|
use ui\form\structure\eInputType;
|
|
use core\lang\structure\LangVariable as V;
|
|
use ui\input\Input;
|
|
use shop\property\Value as PropertyValue;
|
|
|
|
|
|
class Api extends shopControllerTable {
|
|
|
|
static $class = 'shop\item\Value';
|
|
|
|
static function getValues(){
|
|
if($C = Property::isMy($_POST['id']) and $ITEM = Item::isMy($_POST['item_id'])) {
|
|
$ID = $C[Property::$ID];
|
|
$ITEM_ID = $ITEM[Item::$ID];
|
|
$item_values = Value::getByItemPropertyID($ITEM_ID,$ID);
|
|
$property_values = PropertyValue::getByPropertyID($ID);
|
|
|
|
$inputs = [];
|
|
$type = intval($C[Property::$TYPE]);
|
|
switch ($type) {
|
|
case ePropertyType::VALUES_ONE:
|
|
case ePropertyType::VALUES_MANY:
|
|
|
|
$isCheckbox = $type==ePropertyType::VALUES_MANY;
|
|
|
|
$checked = [];
|
|
foreach ($item_values as $v){
|
|
$checked[] = $v[Value::$VALUE];
|
|
}
|
|
foreach ($property_values as $v) {
|
|
$inputs[] =
|
|
[
|
|
Form::VIEW =>Form::INPUT,
|
|
Form::COL_CLASSES =>'c',
|
|
Form::TYPE => $isCheckbox ? eInputType::CHECKBOX : eInputType::RADIO,
|
|
Form::INPUT_OPT => [
|
|
Input::PLACEHOLDER => $c = PropertyValue::getName($v),
|
|
Input::LABEL => $c,
|
|
Input::VALUE => $v[PropertyValue::$ID],
|
|
Input::NAME => Value::$VALUE,
|
|
Input::CHECKED => in_array($v[PropertyValue::$ID],$checked),
|
|
],
|
|
];
|
|
}
|
|
break;
|
|
case ePropertyType::TEXT:
|
|
case ePropertyType::NUMBER:
|
|
$value = array_pop($item_values);
|
|
$inputs = [
|
|
[
|
|
Form::VIEW =>Form::INPUT,
|
|
Form::COL_CLASSES =>'c c-1-3',
|
|
Form::TYPE =>eInputType::TEXT,
|
|
Form::INPUT_OPT => [
|
|
Input::PLACEHOLDER => $c = Property::getName($C),
|
|
Input::LABEL => $c,
|
|
Input::NAME => Value::$TEXT,
|
|
Input::VALUE => $value[Value::$TEXT],
|
|
],
|
|
]
|
|
];
|
|
break;
|
|
|
|
}
|
|
echo new Form([
|
|
Form::INPUTS=>$inputs,
|
|
Form::INPUT_ALL_THEME_FORCE => 'ms',
|
|
Form::FORM_WRAP => false,
|
|
]);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|