/** * Returns a list of all the active users. * * Returns a list of all the users with: * <pre> * - id => id of user. * - display => Display for the user. * </pre> * * The return is in JSON format. * * @return void */ public function jsonGetUsersAction() { IndexController::setCurrentProjectId(); $db = Phprojekt::getInstance()->getDb(); $where = sprintf('status = %s', $db->quote('A')); $user = new Phprojekt_User_User(); $records = $user->fetchAll($where); $data = array(); foreach ($records as $node) { $data['data'][] = array('id' => $node->id, 'display' => $node->displayName); } Phprojekt_Converter_Json::echoConvert($data, Phprojekt_ModelInformation_Default::ORDERING_LIST); }
public function jsonGetSpecificUsersAction() { $ids = Cleaner::sanitize('arrayofint', $this->getRequest()->getParam('users', array())); if (empty($ids)) { $ids[] = (int) PHprojekt_Auth::getUserId(); } $db = Phprojekt::getInstance()->getDb(); $where = sprintf('status = %s AND id IN (%s)', $db->quote('A'), implode(", ", $ids)); $user = new Phprojekt_User_User(); $records = $user->fetchAll($where); $data = array(); foreach ($records as $record) { $data['data'][] = array('id' => (int) $record->id, 'display' => $record->displayName); } Phprojekt_Converter_Json::echoConvert($data, Phprojekt_ModelInformation_Default::ORDERING_LIST); }
/** * */ public function testCreateHasManyAndBelongsToMany() { try { $user = new Phprojekt_User_User(array('db' => $this->sharedFixture)); $users = $user->fetchAll($this->sharedFixture->quoteInto('username = ?', 'david')); if ($users === null) { $this->fail('No user found'); } else { $david = $users[0]; $group = $david->groups->create(); $group->name = 'TEST GROUP'; $this->assertTrue($group->save()); $this->assertNotNull($group->id); } } catch (Exception $e) { $this->fail($e->getMessage() . $e->getTraceAsString()); } }
/** * Helper to create an array of users. * * @param string $idList Comma-separated list of user ids. * @param string $idListNN Optional additional lists of comma-separated user ids. * * @return array Array with 'id' and 'display' */ public static function expandIdList() { $addArray = array(); $num = func_num_args(); for ($i = 0; $i < $num; $i++) { $addList = (string) func_get_arg($i); if ("" != $addList) { $addArray[] = $addList; } } $idList = implode(",", $addArray); $data = array(); if (!empty($idList)) { $user = new Phprojekt_User_User(); $userList = $user->fetchAll(sprintf('id IN (%s)', $idList)); foreach ($userList as $record) { $data[] = array('id' => (int) $record->id, 'display' => $record->displayName); } } return $data; }
/** * Returns all users that have a given right (or any right if none is given) on an item. * * @param string $moduleId The module ID. * @param integer $itemId The item ID. * @param int $rights A bitmask of rights (Constants in Phprojekt_Acl). All users with any rights will be * returned if null or omitted. * @param bool $exact Only get users with exact $rights instead of all users that have at least $rights. * Default is false. * * @return array Array of user IDs. */ public function getUsersWithRight($moduleId, $itemId, $rights = null, $exact = false) { $db = Phprojekt::getInstance()->getDb(); $where = $db->quoteInto('module_id = ? AND ', (int) $moduleId); $where .= $db->quoteInto('item_id = ?', (int) $itemId); if (is_null($rights)) { $where .= ' AND access > 0'; } else { if ($exact) { $where .= $db->quoteInto(' AND access = ?', (int) $rights); } else { $where .= $db->quoteInto(' AND (access & ?) = ?', (int) $rights, (int) $rights); } } $user = new Phprojekt_User_User(); $users = $user->fetchAll($where, null, null, null, null, "JOIN item_rights ON item_rights.user_id = user.id"); return $users; }
/** * Gets only the recipients with at least a 'read' right * and checks if the user has disabled/enabled the settings for saving the messages. * * If no recipient is given, returns an empty array. * * @return array Array with user IDs. */ public function getRecipients() { if (false === empty($this->_recipients)) { return $this->_recipients; } $recipients = array(); if ($this->_model instanceof Phprojekt_Tree_Node_Database || $this->_model instanceof Phprojekt_Model_Interface) { $userIds = $this->_model->getUsersRights(); if (is_array($userIds) && !empty($userIds)) { foreach ($userIds as $userId => $right) { if ($userId == Phprojekt_Auth::getUserId() || true === $right['none']) { continue; } $recipients[] = $userId; } } } else { $user = new Phprojekt_User_User(); $userIds = $user->fetchAll(); foreach ($userIds as $user) { if ($user->id == Phprojekt_Auth::getUserId()) { continue; } $recipients[] = $user->id; } } return $this->filterRecipientsToSettings($recipients); }
/** * Collects all mail addresses from user ids. * * @param array $userIdList Array of user ids to be fetched. * @param Zend_Validate_Abstract $validator Validator to be used for the mail addresses. * * @return array Array of arrays with either 'mail'/'name' pairs or 'message'/'value' errors. */ private function _getMailFromUserIds($userIdList, Zend_Validate_Abstract $validator) { // Add regular recipients: $idList = array(); if (!empty($userIdList) && is_array($userIdList)) { foreach ($userIdList as $recipientId) { if (is_numeric($recipientId)) { $idList[] = (int) $recipientId; } } } $userMailList = array(); if (count($idList)) { /* @var $userModel Phprojekt_User_User */ $userModel = new Phprojekt_User_User(); $userList = $userModel->fetchAll(sprintf('id IN (%s)', implode(',', $idList))); /* @var $record Phprojekt_User_User */ foreach ($userList as $record) { $address = $record->getSetting('email'); if ($validator->isValid($address)) { $userMailList[] = array('mail' => $address, 'name' => $record->displayName); } else { $userMailList[] = array('message' => 'Invalid email address detected:', 'value' => $address); } } } return $userMailList; }