| 1 |
<?php |
| 2 |
|
| 3 |
namespace AcyMailing\Helpers; |
| 4 |
|
| 5 |
use AcyMailing\Controllers\EntitySelectController; |
| 6 |
use AcyMailing\Core\AcymObject; |
| 7 |
|
| 8 |
class EntitySelectHelper extends AcymObject |
| 9 |
{ |
| 10 |
var $svg; |
| 11 |
var $columnsHeaderNotToDisplay; |
| 12 |
|
| 13 |
public function __construct() |
| 14 |
{ |
| 15 |
parent::__construct(); |
| 16 |
$this->svg = acym_loaderLogo(false); |
| 17 |
$this->columnsHeaderNotToDisplay = ['color']; |
| 18 |
} |
| 19 |
|
| 20 |
private function _getListing($type, $allSelector, $entity, $columnsToDisplay = [], $displayedName = '') |
| 21 |
{ |
| 22 |
if (empty($displayedName)) $displayedName = $entity; |
| 23 |
$display = '<div class="cell medium-auto grid-x acym_area acym__entity_select__'.$type.'"> |
| 24 |
<h5 class="cell font-bold acym__title acym__title__secondary text-center">'.acym_translation('ACYM_'.strtoupper($type).'_'.strtoupper($displayedName)).'</h5> |
| 25 |
<div class="cell grid-x"> |
| 26 |
<div class="cell grid-x acym__entity_select__header"> |
| 27 |
<div class="cell grid-x"> |
| 28 |
<div class="cell margin-bottom-1"><input type="text" v-model="'.$type.'Search" placeholder="'.acym_translation('ACYM_SEARCH').'"></div> |
| 29 |
<div class="cell align-right grid-x acym__entity_select__select__all"> |
| 30 |
<button type="button" v-show="!loading" v-if="displaySelectAll_'.$type.'" v-on:click="moveAll('.acym_escapeDB( |
| 31 |
$type |
| 32 |
).')" class="cell shrink acym__entity_select__select__all__button acym__entity_select__select__all__button__'.$type.'">'.acym_translation( |
| 33 |
'ACYM_'.strtoupper($allSelector).'_ALL' |
| 34 |
).'</button> |
| 35 |
</div> |
| 36 |
</div> |
| 37 |
</div> |
| 38 |
<div v-infinite-scroll="loadMoreEntity'.ucfirst( |
| 39 |
$type |
| 40 |
).'" :infinite-scroll-disabled="busy" class="acym__listing cell acym__entity_select__'.$type.'__listing acym__content" infinite-scroll-distance="10">'; |
| 41 |
$emptyMessage = acym_translation($type === 'available' ? 'ACYM_NOTHING_TO_SHOW_HERE_RIGHT_PANEL' : 'ACYM_PLEASE_CLICK_ON_THE_LEFT_PANEL'); |
| 42 |
$display .= '<div class="cell text-center acym__entity_select__title margin-top-2" v-show="Object.keys(entitiesToDisplay_'.$type.').length == 0 && !loading">'.$emptyMessage.'</div> |
| 43 |
<div class="cell acym_vcenter acym__listing__row grid-x acym__listing__row__header" v-if="Object.keys(entitiesToDisplay_'.$type.').length != 0">'; |
| 44 |
|
| 45 |
|
| 46 |
if ($type !== 'available') $display .= '<div class="cell small-1"></div>'; |
| 47 |
|
| 48 |
foreach ($columnsToDisplay as $column => $class) { |
| 49 |
$display .= '<div class="cell grid-x '.$class.'">'.(in_array($column, $this->columnsHeaderNotToDisplay) ? '' : acym_translation('ACYM_'.strtoupper($column))).'</div>'; |
| 50 |
} |
| 51 |
|
| 52 |
if ($type === 'available') $display .= '<div class="cell small-1"></div>'; |
| 53 |
$display .= '</div>'; |
| 54 |
|
| 55 |
$functionClick = $type === 'available' ? 'v-on:click="selectEntity(entity.id)"' : 'v-on:click="unselectEntity(entity.id)"'; |
| 56 |
$display .= '<div '.$functionClick.' v-for="(entity, index) in entitiesToDisplay_'.$type.'" class="cell acym_vcenter acym__listing__row grid-x acym__entity_select__'.$type.'__listing__row" >'; |
| 57 |
|
| 58 |
if ($type !== 'available') { |
| 59 |
$display .= '<div class="cell small-1 vertical-align-middle text-center"> |
| 60 |
<div class="plus-container acym__entity_select__selected__listing__row__unselect"> |
| 61 |
<div class="top-plus plus-bar"></div> |
| 62 |
<div class="plus plus-bar"></div> |
| 63 |
<div class="bottom-plus plus-bar"></div> |
| 64 |
</div> |
| 65 |
</div>'; |
| 66 |
} |
| 67 |
|
| 68 |
$display .= '<div v-for="(column, index) in columnsToDisplay" class="cell align-center acym__entity_select__columns" :class="getClass(column)" v-html="entity[column]"></div>'; |
| 69 |
|
| 70 |
if ($type === 'available') { |
| 71 |
$display .= '<div class="cell small-1 vertical-align-middle text-center"> |
| 72 |
<div class="plus-container acym__entity_select__available__listing__row__select"> |
| 73 |
<div class="top-plus plus-bar"></div> |
| 74 |
<div class="plus plus-bar"></div> |
| 75 |
<div class="bottom-plus plus-bar"></div> |
| 76 |
</div> |
| 77 |
</div>'; |
| 78 |
} |
| 79 |
|
| 80 |
$display .= '</div> |
| 81 |
<div class="cell grid-x align-center acym__entity_select__loading margin-top-1" v-show="loading"><div class="cell text-center acym__entity_select__title">'; |
| 82 |
$display .= acym_translation('ACYM_WE_ARE_LOADING_YOUR_DATA'); |
| 83 |
$display .= '</div><div class="cell grid-x shrink margin-top-1">'.$this->svg.'</div></div>'; |
| 84 |
$display .= '</div>'; |
| 85 |
$display .= '</div> |
| 86 |
</div>'; |
| 87 |
|
| 88 |
return $display; |
| 89 |
} |
| 90 |
|
| 91 |
public function entitySelect( |
| 92 |
$entity, |
| 93 |
$entityParams = [], |
| 94 |
$columnsToDisplay = ['name'], |
| 95 |
$buttonSubmit = [ |
| 96 |
'text' => '', |
| 97 |
'action' => '', |
| 98 |
'class' => '', |
| 99 |
], |
| 100 |
$displaySelected = true, |
| 101 |
$additionalData = '', |
| 102 |
$displayedName = '' |
| 103 |
) { |
| 104 |
$columnJoin = ''; |
| 105 |
if (!empty($columnsToDisplay['join'])) { |
| 106 |
$columnJoin = explode('.', $columnsToDisplay['join']); |
| 107 |
} |
| 108 |
|
| 109 |
unset($columnsToDisplay['join']); |
| 110 |
|
| 111 |
if (empty($entityParams['elementsPerPage']) || $entityParams['elementsPerPage'] < 1) { |
| 112 |
$paginationHelper = new PaginationHelper(); |
| 113 |
$entityParams['elementsPerPage'] = $paginationHelper->getListLimit(); |
| 114 |
} |
| 115 |
|
| 116 |
if (!empty($columnJoin)) $columnJoin = 'data-column-join="'.$columnJoin[1].'" data-table-join="'.$columnJoin[0].'"'; |
| 117 |
$display = '<div |
| 118 |
style="display: none;" |
| 119 |
id="acym__entity_select" |
| 120 |
class="acym__entity_select cell grid-x" |
| 121 |
data-display-selected="'.($displaySelected ? 'true' : 'false').'" |
| 122 |
data-entity="'.acym_escape($entity).'" |
| 123 |
data-type="select" |
| 124 |
data-columns="'.implode(',', array_keys($columnsToDisplay)).'" |
| 125 |
data-columns-class="'.acym_escape(json_encode($columnsToDisplay)).'" |
| 126 |
data-join="'.$entityParams['join'].'" |
| 127 |
'.$columnJoin.'>'; |
| 128 |
|
| 129 |
$display .= $this->_getListing('available', 'select', $entity, $columnsToDisplay, $displayedName); |
| 130 |
$display .= '<div class="cell medium-shrink text-center grid-x acym_vcenter"><i class="acymicon-arrows-h cell"></i></div>'; |
| 131 |
$display .= $this->_getListing('selected', 'unselect', $entity, $columnsToDisplay, $displayedName); |
| 132 |
$display .= $additionalData; |
| 133 |
|
| 134 |
if (!empty($buttonSubmit['text'])) { |
| 135 |
$class = !empty($buttonSubmit['action']) ? 'acy_button_submit' : 'acym__entity_select__button__close'; |
| 136 |
if (!empty($buttonSubmit['class'])) $class .= ' '.$buttonSubmit['class']; |
| 137 |
$buttonSubmit['action'] = !empty($buttonSubmit['action']) ? 'data-task="'.$buttonSubmit['action'].'"' : ''; |
| 138 |
$display .= '<div class="cell grid-x align-center margin-top-1">'; |
| 139 |
$display .= '<button |
| 140 |
type="button" |
| 141 |
id="acym__entity_select__button__submit" |
| 142 |
class="cell shrink grid-x '.$class.' button" '.$buttonSubmit['action'].'>'.$buttonSubmit['text'].'</button>'; |
| 143 |
$display .= '</div>'; |
| 144 |
} |
| 145 |
|
| 146 |
$display .= '<input type="hidden" class="acym__entity_select__selected" name="acym__entity_select__selected" value="">'; |
| 147 |
$display .= '<input type="hidden" class="acym__entity_select__unselected" name="acym__entity_select__unselected" value="">'; |
| 148 |
$display .= '</div>'; |
| 149 |
|
| 150 |
return $display; |
| 151 |
} |
| 152 |
|
| 153 |
public function getColumnsForList($join = '', $small = false) |
| 154 |
{ |
| 155 |
$columns = [ |
| 156 |
'color' => $small ? 'small-2' : 'small-1', |
| 157 |
'name' => 'auto', |
| 158 |
'id' => 'small-2', |
| 159 |
]; |
| 160 |
if (!empty($join)) $columns['join'] = $join; |
| 161 |
|
| 162 |
return $columns; |
| 163 |
} |
| 164 |
|
| 165 |
public function getColumnsForUser($join = '') |
| 166 |
{ |
| 167 |
$columns = [ |
| 168 |
'email' => 'auto', |
| 169 |
'name' => 'auto', |
| 170 |
'id' => 'small-1', |
| 171 |
]; |
| 172 |
|
| 173 |
if (!empty($join)) { |
| 174 |
$columns['join'] = $join; |
| 175 |
} |
| 176 |
|
| 177 |
return $columns; |
| 178 |
} |
| 179 |
|
| 180 |
} |
| 181 |
|