v1.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace zin;
  3. class thinkStep extends wg
  4. {
  5. /**
  6. * @var mixed[]
  7. */
  8. protected static $defineProps = array(
  9. 'item: object',
  10. 'action?: string="detail"',
  11. 'addType?: string',
  12. 'wizard: object',
  13. 'isRun?: bool=false', // 是否是分析活动
  14. 'quoteQuestions?: array', // 引用题目的下拉选项
  15. 'quotedQuestions?: array', // 被引用的题目
  16. 'modeClass?: string=""', // 弹窗样式名称
  17. );
  18. /**
  19. * @return \zin\wg|mixed[]
  20. */
  21. protected function buildBody()
  22. {
  23. global $config;
  24. list($item, $action, $addType, $isRun, $quoteQuestions, $quotedQuestions, $modeClass, $wizard) = $this->prop(array('item', 'action', 'addType', 'isRun', 'quoteQuestions', 'quotedQuestions', 'modeClass', 'wizard'));
  25. $step = $addType ? null : $item;
  26. $questionType = $addType ? $addType : ($item->options->questionType ?? '');
  27. if($addType === 'node' || !$addType && $item->type === 'node') return thinkNode(set::step($step), set::mode($action), set::isRun($isRun), set::wizard($wizard));
  28. if($addType === 'transition' || !$addType && $item->type === 'transition') return thinkTransition(set::step($step), set::mode($action), set::isRun($isRun), set::wizard($wizard));
  29. if($questionType === 'input') return thinkInput(set::step($step), set::questionType('input'), set::mode($action), set::isRun($isRun), set::quotedQuestions($quotedQuestions), set::wizard($wizard));
  30. if($questionType === 'radio') return thinkRadio(set::step($step), set::questionType('radio'), set::mode($action), set::isRun($isRun), set::quotedQuestions($quotedQuestions), set::wizard($wizard));
  31. if($questionType === 'checkbox') return thinkCheckbox(set::step($step), set::questionType('checkbox'), set::mode($action), set::isRun($isRun), set::quoteQuestions($quoteQuestions), set::quotedQuestions($quotedQuestions), set::wizard($wizard));
  32. if($questionType === 'tableInput') return thinkTableInput(set::step($step), set::questionType('tableInput'), set::mode($action), set::isRun($isRun), set::quoteQuestions($quoteQuestions), set::quotedQuestions($quotedQuestions), set::wizard($wizard));
  33. if($questionType === 'multicolumn') return thinkMulticolumn(set::step($step), set::questionType('multicolumn'), set::mode($action), set::isRun($isRun), set::quoteQuestions($quoteQuestions), set::quotedQuestions($quotedQuestions), set::modeClass($modeClass), set::wizard($wizard));
  34. if($questionType === 'score') return thinkScore(set::step($step), set::questionType('score'), set::mode($action), set::isRun($isRun), set::quoteQuestions($quoteQuestions), set::quotedQuestions($quotedQuestions), set::wizard($wizard));
  35. return array();
  36. }
  37. /**
  38. * @return \zin\wg|\zin\node|mixed[]
  39. */
  40. protected function build()
  41. {
  42. global $lang, $app, $config;
  43. $app->loadLang('thinkstep');
  44. list($item, $action, $wizard, $addType, $isRun, $quotedQuestions) = $this->prop(array('item', 'action', 'wizard', 'addType', 'isRun', 'quotedQuestions'));
  45. if(!$item && !$addType) return array();
  46. $hiddenModelType = in_array($wizard->model, $config->thinkwizard->hiddenMenuModel);
  47. $previewCanActions = !$hiddenModelType || ($hiddenModelType && !empty($item->type) && $item->type == 'transition');
  48. $marketID = data('marketID');
  49. $basicType = $item->type ?? '';
  50. $typeLang = $action . 'Step';
  51. $type = $addType ? $addType : ($basicType == 'question' ? $item->options->questionType : $basicType);
  52. $title = $action == 'detail' ? sprintf($lang->thinkstep->info, $lang->thinkstep->$basicType) : sprintf($lang->thinkstep->formTitle[$type], $lang->thinkstep->$typeLang);
  53. $canEdit = common::hasPriv('thinkstep', 'edit');
  54. $canDelete = common::hasPriv('thinkstep', 'delete') && $previewCanActions;
  55. $linkmodel = !$isRun && in_array($wizard->model, $config->thinkwizard->venn);
  56. $canLink = common::hasPriv('thinkstep', 'link') && $linkmodel && $basicType == 'question';
  57. $from = '';
  58. if($hiddenModelType)
  59. {
  60. $from = strtolower($wizard->type);
  61. if($wizard->model == 'appeals') $from = 'appeals';
  62. }
  63. return div
  64. (
  65. setClass('think-step relative h-full overflow-y-auto scrollbar-thin'),
  66. !$isRun ? array(
  67. div
  68. (
  69. setClass('flex items-center justify-between text-gray-950 h-12 step-header'),
  70. setStyle(array('padding-left' => '30px', 'padding-right' => '30px')),
  71. div(setClass('font-medium'), $title),
  72. ($action != 'detail') ? null : div
  73. (
  74. setClass('ml-2'),
  75. setStyle(array('min-width' => '48px')),
  76. btnGroup
  77. (
  78. ($canLink && $previewCanActions) ? btn(setClass('btn ghost text-gray w-5 h-5 mr-1'), set::icon('link'), set::url(createLink('thinkstep', 'link', "marketID={$marketID}&stepID={$item->id}")), set::hint($lang->thinkstep->actions['link']), set('data-toggle', 'modal'), set('data-dismiss', 'modal'), set('data-size', 'sm')): null,
  79. ($canEdit && $previewCanActions) ? btn(setClass('btn ghost text-gray w-5 h-5'), set::icon('edit'), set::hint($lang->thinkstep->actions['edit']), set::url(createLink('thinkstep', 'edit', "marketID={$marketID}&stepID={$item->id}&from={$from}"))) : null,
  80. $canDelete ? ((!$item->existNotNode && empty($quotedQuestions)) ? btn
  81. (
  82. setClass('btn ghost text-gray w-5 h-5 ml-1 ajax-submit'),
  83. set::icon('trash'),
  84. set::hint($lang->thinkstep->actions['delete']),
  85. setData('url', createLink('thinkstep', 'delete', "marketID={$marketID}&stepID={$item->id}&from={$from}")),
  86. setData('confirm', empty($item->link) ? $lang->thinkstep->deleteTips[$basicType] : array('message' => $lang->thinkstep->tips->deleteLinkStep, 'icon' => 'icon-exclamation-sign', 'iconClass' => 'warning-pale rounded-full icon-2x', 'size' => 'sm'))
  87. ) : icon
  88. (
  89. setClass('w-5 h-5 text-gray opacity-50 ml-1 text-md pl-1'),
  90. set::title($item->existNotNode ? $lang->thinkstep->cannotDeleteNode : $lang->thinkstep->cannotDeleteQuestion),
  91. 'trash'
  92. )) : null
  93. )
  94. )
  95. ),
  96. h::hr()
  97. ) : null,
  98. div(setClass('pt-6 pb-2 question-detail'), setStyle(array('padding-left' => '30px', 'padding-right' => '30px')), $this->buildBody())
  99. );
  100. }
  101. }