Example #1
0
 /**
  * Internal function to return a GroupMembership object from a row.
  * @param $row array
  * @return GroupMembership
  */
 function &_returnMembershipFromRow(&$row)
 {
     // Keep a cache of users.
     static $users;
     if (!isset($users)) {
         $users = array();
     }
     $userId = $row['user_id'];
     if (!isset($users[$userId])) {
         $users[$userId] =& $this->userDao->getUser($userId);
     }
     $membership = new GroupMembership();
     $membership->setGroupId($row['group_id']);
     $membership->setUserId($row['user_id']);
     $membership->setUser($users[$userId]);
     $membership->setSequence($row['seq']);
     $membership->setAboutDisplayed($row['about_displayed']);
     HookRegistry::call('GroupMembershipDAO::_returnMemberFromRow', array(&$membership, &$row));
     return $membership;
 }
Example #2
0
 /**
  * Add group membership (or list users if none chosen).
  */
 function addMembership($args)
 {
     $groupId = isset($args[0]) ? (int) $args[0] : 0;
     $userId = isset($args[1]) ? (int) $args[1] : null;
     $groupMembershipDao =& DAORegistry::getDAO('GroupMembershipDAO');
     // If a user has been selected, add them to the group.
     // Otherwise list users.
     if ($userId !== null) {
         $this->validate($groupId, $userId);
         $group =& $this->group;
         $user =& $this->user;
         // A valid user has been chosen. Add them to
         // the membership list and redirect.
         // Avoid duplicating memberships.
         $groupMembership =& $groupMembershipDao->getMembership($group->getId(), $user->getId());
         if (!$groupMembership) {
             $groupMembership = new GroupMembership();
             $groupMembership->setGroupId($group->getId());
             $groupMembership->setUserId($user->getId());
             // For now, all memberships are displayed in About
             $groupMembership->setAboutDisplayed(true);
             $groupMembershipDao->insertMembership($groupMembership);
         }
         Request::redirect(null, null, 'groupMembership', $group->getId());
     } else {
         $this->validate($groupId);
         $group =& $this->group;
         $this->setupTemplate($group, true);
         $searchType = null;
         $searchMatch = null;
         $search = $searchQuery = Request::getUserVar('search');
         $searchInitial = Request::getUserVar('searchInitial');
         if (!empty($search)) {
             $searchType = Request::getUserVar('searchField');
             $searchMatch = Request::getUserVar('searchMatch');
         } elseif (!empty($searchInitial)) {
             $searchInitial = String::strtoupper($searchInitial);
             $searchType = USER_FIELD_INITIAL;
             $search = $searchInitial;
         }
         $roleDao =& DAORegistry::getDAO('RoleDAO');
         $journal =& Request::getJournal();
         $users = $roleDao->getUsersByRoleId(null, $journal->getId(), $searchType, $search, $searchMatch);
         $templateMgr =& TemplateManager::getManager();
         $templateMgr->assign('searchField', $searchType);
         $templateMgr->assign('searchMatch', $searchMatch);
         $templateMgr->assign('search', $searchQuery);
         $templateMgr->assign('searchInitial', Request::getUserVar('searchInitial'));
         $templateMgr->assign_by_ref('users', $users);
         $templateMgr->assign('fieldOptions', array(USER_FIELD_FIRSTNAME => 'user.firstName', USER_FIELD_LASTNAME => 'user.lastName', USER_FIELD_USERNAME => 'user.username', USER_FIELD_EMAIL => 'user.email'));
         $templateMgr->assign('alphaList', explode(' ', Locale::translate('common.alphaList')));
         $templateMgr->assign_by_ref('group', $group);
         $templateMgr->display('manager/groups/selectUser.tpl');
     }
 }
 function importGroups()
 {
     assert($this->xml->name == 'groups');
     $journal = $this->journal;
     $groupDao =& DAORegistry::getDAO('GroupDAO');
     $groupMembershipDao =& DAORegistry::getDAO('GroupMembershipDAO');
     $this->nextElement();
     while ($this->xml->name == 'group') {
         $groupXML = $this->getCurrentElementAsDom();
         $group =& new Group();
         $group->setAssocType(ASSOC_TYPE_JOURNAL);
         $group->setAssocId($journal->getId());
         $group->setAboutDisplayed((int) $groupXML->aboutDisplayed);
         $group->setPublishEmail((int) $groupXML->publishEmail);
         $group->setSequence((int) $groupXML->sequence);
         $group->setContext((int) $groupXML->context);
         $groupDao->insertGroup($group);
         foreach ($groupXML->groupMembership as $groupMembershipXML) {
             $groupMembership = new GroupMembership();
             $groupMembership->setGroupId($group->getId());
             $groupMembership->setUserId($this->idTranslationTable->resolve(INTERNAL_TRANSFER_OBJECT_USER, (int) $groupMembershipXML->userId));
             $groupMembership->setSequence((int) $groupMembershipXML->sequence);
             $groupMembership->setAboutDisplayed((int) $groupMembershipXML->aboutDisplayed);
             $groupMembershipDao->insertMembership($groupMembership);
         }
         $this->restoreDataObjectSettings($groupDao, $groupXML->settings, 'group_settings', 'group_id', $group->getId());
         $this->idTranslationTable->register(INTERNAL_TRANSFER_OBJECT_GROUP, (int) $groupXML->oldId, $group->getId());
         $this->nextElement();
     }
 }
 function addItem($args, &$request)
 {
     $this->setupTemplate();
     $publicationFormatDao =& DAORegistry::getDAO('PublicationFormatDAO');
     $press =& $request->getPress();
     $groupId = $args['groupId'];
     $index = 'sourceId-' . $this->getId() . '-' . $groupId;
     $userId = $args[$index];
     if (empty($userId)) {
         $json = new JSON(false, Locale::translate('common.listbuilder.completeForm'));
         return $json->getString();
     } else {
         $groupMembershipDao =& DAORegistry::getDAO('GroupMembershipDAO');
         $groupMembership =& $groupMembershipDao->getMembership($groupId, $userId);
         // Make sure the membership doesn't already exist
         if (isset($groupMembership)) {
             $json = new JSON(false, Locale::translate('common.listbuilder.itemExists'));
             return $json->getString();
             return false;
         }
         unset($groupMembership);
         $groupMembership = new GroupMembership();
         $groupMembership->setGroupId($request->getUserVar('groupId'));
         $groupMembership->setUserId($userId);
         // For now, all memberships are displayed in About
         $groupMembership->setAboutDisplayed(true);
         $groupMembershipDao->insertMembership($groupMembership);
         $userDao =& DAORegistry::getDAO('UserDAO');
         $user =& $userDao->getUser($userId);
         // Return JSON with formatted HTML to insert into list
         $row =& $this->getRowInstance();
         $row->setGridId($this->getId());
         $row->setId($userId);
         $rowData = array('item' => $user->getFullName(), 'attribute' => $user->getUsername());
         $row->setData($rowData);
         $row->initialize($request);
         $json = new JSON(true, $this->_renderRowInternally($request, $row));
         return $json->getString();
     }
 }
Example #5
0
        </tr>
        <?php 
    }
    ?>
    </table>
    <h2>Invites you sent:</h2>
    <table class="table table-striped">
        <tr>
            <th>To</th>
            <th>Group</th>
            <th>Withdraw</th>
        </tr>
        <?php 
    $sentInvites = $this->getSentInvites();
    foreach ($sentInvites as $inviteId) {
        $membership = new GroupMembership($inviteId);
        ?>
        <tr>
            <form id="withdrawInvite" class="form-horizontal" role="form" method="post" action="<?php 
        echo SITE_URL;
        ?>
invites">
            <td><?php 
        echo $membership->getUserName();
        ?>
</td>
            <td><?php 
        echo $membership->getGroupName();
        ?>
</td>
            <input type="hidden" name="inviteId" id="inviteId" value=<?php