本文整理汇总了PHP中DataManager::getChannelsByUserId方法的典型用法代码示例。如果您正苦于以下问题:PHP DataManager::getChannelsByUserId方法的具体用法?PHP DataManager::getChannelsByUserId怎么用?PHP DataManager::getChannelsByUserId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataManager
的用法示例。
在下文中一共展示了DataManager::getChannelsByUserId方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: array
<div class="panel-body">
<ul class="list-group">
<li class="list-group-item">
First name: <?php
echo AuthenticationManager::getAuthenticatedUser()->getFirstName();
?>
</li>
<li class="list-group-item">
Last name: <?php
echo AuthenticationManager::getAuthenticatedUser()->getLastName();
?>
</li>
<li class="list-group-item">
Channels:
<?php
$user = AuthenticationManager::getAuthenticatedUser();
$channels = DataManager::getChannelsByUserId($user->getID());
$str = array();
foreach ($channels as $channel) {
$str[] = $channel->getName();
}
$strSeparated = implode(", ", $str);
echo $strSeparated;
?>
</li>
</ul>
</div> <!-- panel-body -->
</div> <!-- panel panel-default-->
<?php
include_once "views/partials/footer.php";
示例2: invokePostAction
public function invokePostAction()
{
if ($_SERVER['REQUEST_METHOD'] != self::REQUEST_METHOD) {
throw new Exception("Controller can only handle " . self::REQUEST_METHOD . ' requests');
return null;
} else {
if (!isset($_REQUEST[self::ACTION_PARAM])) {
throw new Exception(self::ACTION_PARAM . ' parameter is not specified');
}
}
$action = $_REQUEST[self::ACTION_PARAM];
switch ($action) {
case self::ACTION_LOGIN:
if (!AuthenticationManager::authenticate($_REQUEST[self::USR_NAME], $_REQUEST[self::USR_PASSWORD])) {
$this->forwardRequest(['Invalid user information provided']);
}
$user = DataManager::getUserByUsername($_REQUEST[self::USR_NAME]);
$_SESSION['username'] = $user->getID();
$user = AuthenticationManager::getAuthenticatedUser();
$channels = DataManager::getChannelsByUserId($user->getID());
$_SESSION['channel'] = $channels[0]->getName();
Util::redirect();
break;
case self::ACTION_LOGOUT:
if (AuthenticationManager::isAuthenticated()) {
AuthenticationManager::signOut();
}
Util::redirect();
break;
case self::ACTION_REGISTRATION:
$channels = $_REQUEST['channels'];
foreach ($channels as $ch) {
$channel = DataManager::getChannelByName($ch);
$registratedUsers = DataManager::getUsersByChannelId($channel->getID());
foreach ($registratedUsers as $user) {
if ($user->getUsername() === $_REQUEST[self::USR_NAME]) {
$this->forwardRequest(['The username ' . $_REQUEST[self::USR_NAME] . ' is already used!'], 'index.php?view=registration');
}
}
$user = DataManager::getUserByUsername($_REQUEST[self::USR_NAME]);
$userId = null;
if ($user) {
$userId = $user->getID();
} else {
$userId = DataManager::saveNewUser($_REQUEST[self::USR_FIRST_NAME], $_REQUEST[self::USR_LAST_NAME], $_REQUEST[self::USR_NAME], AuthenticationManager::getHash($_REQUEST[self::USR_NAME], $_REQUEST[self::USR_PASSWORD]));
}
DataManager::registrateUser($userId, $channel->getID());
}
if (!AuthenticationManager::authenticate($_REQUEST[self::USR_NAME], $_REQUEST[self::USR_PASSWORD])) {
$this->forwardRequest(['Invalid user information provided'], "index.php?view=registration");
}
$_SESSION[self::USR_CHANNELS] = $_REQUEST[self::USR_CHANNELS];
// first channel should be selected as default channel
$_SESSION['channel'] = $channels[0];
Util::redirect();
break;
case self::POST_MSG:
$channel = DataManager::getChannelByName($_SESSION['channel']);
$user = AuthenticationManager::getAuthenticatedUser();
$messages = DataManager::getAllUnansweredPosts($channel->getID());
//TODO: mark message as answered
foreach ($messages as $message) {
if ($message->getAuthor() != $user->getID()) {
DataManager::changePostStatus($message->getID(), Status::ANSWERED);
}
}
DataManager::publishMessage($user->getID(), $channel->getID(), $_REQUEST[self::POST_TITLE], $_REQUEST[self::POST_CONTENT], Status::UNREAD);
break;
case self::ACTION_CHANGE_CHANNEL:
//print_r($_REQUEST);
$_SESSION['channel'] = $_REQUEST['selectedChannel'];
Util::redirect();
break;
case self::ACTION_JOIN_CHANNEL:
$channel = DataManager::getChannelByName($_REQUEST[self::USR_CHANNEL]);
$registratedUsers = DataManager::getUsersByChannelId($channel->getID());
foreach ($registratedUsers as $user) {
if ($user->getUsername() === $_REQUEST[self::USR_NAME]) {
$this->forwardRequest(['User ' . $_REQUEST[self::USR_NAME] . ' is already registered!'], "index.php?view=join");
}
}
$user = DataManager::getUserByUsername($_REQUEST[self::USR_NAME]);
if (!$user) {
$this->forwardRequest(['Please registrate, the user ' . $_REQUEST[self::USR_NAME] . ' does not exists!'], "index.php?view=register");
}
DataManager::registrateUser($user->getID(), $channel->getID());
if (!AuthenticationManager::authenticate($_REQUEST[self::USR_NAME], $_REQUEST[self::USR_PASSWORD], $_REQUEST[self::USR_CHANNEL])) {
$this->forwardRequest(['Invalid user information provided'], "index.php?view=registration");
}
$_SESSION[self::USR_CHANNEL] = $_REQUEST[self::USR_CHANNEL];
Util::redirect();
break;
case self::AJAX_SET_PRIO:
if (isset($_POST) && $_POST) {
DataManager::changePostStatus($_POST['id'], Status::PRIOR);
echo "index.php?view=welcome";
}
break;
case self::AJAX_RESET_PRIO:
if (isset($_POST) && $_POST) {
//.........这里部分代码省略.........