function getAutocompleteSource($args, &$request) { //FIXME: add validation here? $this->setupTemplate(); $sourceArray = $this->getPossibleItemList($request); $sourceJson = new JSON('true', null, 'false', 'local'); $sourceContent = array(); foreach ($sourceArray as $i => $item) { // The autocomplete code requires the JSON data to use 'label' as the array key for labels, and 'value' for the id $additionalAttributes = array('label' => sprintf('%s (%s)', $item['name'], $item['abbrev']), 'value' => $item['id']); $itemJson = new JSON('true', '', 'false', null, $additionalAttributes); $sourceContent[] = $itemJson->getString(); unset($itemJson); } $sourceJson->setContent('[' . implode(',', $sourceContent) . ']'); echo $sourceJson->getString(); }
/** * Get users for copyediting autocomplete. * @param $args array * @param $request PKPRequest * @return string Serialized JSON object */ function getCopyeditUserAutocomplete($args, &$request) { // Identify the Monograph we are working with $monograph =& $this->getAuthorizedContextObject(ASSOC_TYPE_MONOGRAPH); // Retrieve the users for the autocomplete control: Any author or press assistant user assigned to this stage $signoffDao =& DAORegistry::getDAO('SignoffDAO'); /* @var $signoffDao SignoffDAO */ $stageUsers =& $signoffDao->getAllBySymbolic('SIGNOFF_STAGE', ASSOC_TYPE_MONOGRAPH, $monograph->getId(), null, WORKFLOW_STAGE_ID_EDITING); $itemList = array(); $userGroupDao =& DAORegistry::getDAO('UserGroupDAO'); /* @var $userGroupDao UserGroupDAO */ $userDao =& DAORegistry::getDAO('UserDAO'); while ($stageUser =& $stageUsers->next()) { $userGroup =& $userGroupDao->getById($stageUser->getUserGroupId()); // Disallow if the user's user group is a reviewer role if ($userGroup->getRoleId() != ROLE_ID_REVIEWER) { $user =& $userDao->getUser($stageUser->getUserId()); $itemList[] = array('id' => $user->getId(), 'name' => $user->getFullName(), 'abbrev' => $userGroup->getLocalizedName(), 'userGroupId' => $stageUser->getUserGroupId()); } } import('lib.pkp.classes.core.JSON'); $sourceJson = new JSON(true, null, false, 'local'); $sourceContent = array(); foreach ($itemList as $i => $item) { // The autocomplete code requires the JSON data to use 'label' as the array key for labels, and 'value' for the id $additionalAttributes = array('label' => sprintf('%s (%s)', $item['name'], $item['abbrev']), 'value' => $item['id'] . "-" . $item['userGroupId']); $itemJson = new JSON(true, '', false, null, $additionalAttributes); $sourceContent[] = $itemJson->getString(); unset($itemJson); } $sourceJson->setContent('[' . implode(',', $sourceContent) . ']'); echo $sourceJson->getString(); }
/** * Get a list of all non-reviewer users in the system to populate the reviewer role assignment autocomplete. * @param $args array * @param $request PKPRequest * @return string Serialized JSON object */ function getReviewerRoleAssignmentAutocomplete($args, &$request) { $press =& $request->getPress(); $userGroupDao =& DAORegistry::getDAO('UserGroupDAO'); /* @var $userGroupDao UserGroupDAO */ $users =& $userGroupDao->getUsersByContextId($press->getId()); $itemList = array(); $roleDao =& DAORegistry::getDAO('RoleDAO'); /* @var $roleDao RoleDAO */ while ($user =& $users->next()) { // Check that the reviewer is not in the current round. We need to do the comparison here to avoid nested selects. if (!$roleDao->userHasRole($press->getId(), $user->getId(), ROLE_ID_REVIEWER)) { $itemList[] = array('id' => $user->getId(), 'name' => $user->getFullName(), 'abbrev' => $user->getUsername()); } unset($user); } import('lib.pkp.classes.core.JSON'); $sourceJson = new JSON(true, null, false, 'local'); $sourceContent = array(); foreach ($itemList as $i => $item) { // The autocomplete code requires the JSON data to use 'label' as the array key for labels, and 'value' for the id $additionalAttributes = array('label' => sprintf('%s (%s)', $item['name'], $item['abbrev']), 'value' => $item['id']); $itemJson = new JSON(true, '', false, null, $additionalAttributes); $sourceContent[] = $itemJson->getString(); unset($itemJson); } $sourceJson->setContent('[' . implode(',', $sourceContent) . ']'); echo $sourceJson->getString(); }