16 import(
'lib.pkp.classes.controllers.grid.GridHandler');
17 import(
'lib.pkp.classes.controllers.listbuilder.ListbuilderGridRow');
18 import(
'lib.pkp.classes.controllers.listbuilder.ListbuilderGridColumn');
19 import(
'lib.pkp.classes.controllers.listbuilder.MultilingualListbuilderGridColumn');
22 define(
'LISTBUILDER_SOURCE_TYPE_TEXT', 0);
23 define(
'LISTBUILDER_SOURCE_TYPE_SELECT', 1);
26 define(
'LISTBUILDER_SAVE_TYPE_EXTERNAL', 0);
27 define(
'LISTBUILDER_SAVE_TYPE_INTERNAL', 1);
33 define(
'LISTBUILDER_OPTGROUP_LABEL',
'optGroupLabel');
49 parent::initialize($request, $args);
52 import(
'lib.pkp.classes.linkAction.request.NullAction');
66 if (is_null($this->_template)) {
67 $this->
setTemplate(
'controllers/listbuilder/listbuilder.tpl');
78 $this->_sourceType = $sourceType;
94 $this->_saveType = $saveType;
110 $this->_saveFieldName = $fieldName;
119 assert(isset($this->_saveFieldName));
132 __(
'grid.action.addItem'),
145 return $request->getUserVar(
'newRowId');
165 function updateEntry($request, $rowId, $newRowId) {
169 if (!$this->
deleteEntry($request, $rowId))
return false;
205 function fetch($args, $request) {
208 $availableOptions =
false;
209 if (is_array($options) && !empty($options)) {
210 $firstColumnOptions = current($options);
211 $optionsCount = count($firstColumnOptions);
212 if (is_array(current($firstColumnOptions))) {
213 unset($firstColumnOptions[LISTBUILDER_OPTGROUP_LABEL]);
215 $optionsCount = count($firstColumnOptions, COUNT_RECURSIVE) - $optionsCount;
219 if (count($listElements) < $optionsCount) {
220 $availableOptions =
true;
224 $templateMgr->assign(
'availableOptions', $availableOptions);
226 return $this->
fetchGrid($args, $request);
236 static function unpack($request, $data, $deletionCallback, $insertionCallback, $updateCallback) {
241 if (isset($data->deletions) && $data->deletions !==
'') {
242 foreach (explode(
' ', trim($data->deletions)) as $rowId) {
243 if (!call_user_func($deletionCallback, $request, $rowId, $data->numberOfRows)) {
250 if (isset($data->changes))
foreach ($data->changes as $entry) {
252 if (isset($entry->rowId)) {
253 $rowId = $entry->rowId;
254 unset($entry->rowId);
262 foreach ($entry as $key => $value) {
264 if (!preg_match(
'/^newRowId\[([a-zA-Z]+)\](\[([a-z][a-z]_[A-Z][A-Z](@([A-Za-z0-9]{5,8}|\d[A-Za-z0-9]{3}))?)\])?$/', $key, $matches)) assert(
false);
267 $column = $matches[1];
270 $locale = isset($matches[3])?$matches[3]:
null;
272 if ($locale) $changes[$column][$locale] = $value;
273 else $changes[$column] = $value;
279 if (is_null($rowId)) {
280 if (!call_user_func($insertionCallback, $request, $changes)) $status =
false;
282 if (!call_user_func($updateCallback, $request, $rowId, $changes)) $status =
false;
293 function save($args, $request) {
298 $data = $request->getUserVar(
'data');
301 array($this,
'deleteEntry'),
302 array($this,
'insertEntry'),
303 array($this,
'updateEntry')