本文整理汇总了PHP中UserDAO::getUserByName方法的典型用法代码示例。如果您正苦于以下问题:PHP UserDAO::getUserByName方法的具体用法?PHP UserDAO::getUserByName怎么用?PHP UserDAO::getUserByName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserDAO
的用法示例。
在下文中一共展示了UserDAO::getUserByName方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: header
if (!isset($_SESSION['user'])) {
header("Location: /session/login.php");
}
// set up
chdir("..");
require_once 'config.webapp.inc.php';
ini_set("include_path", ini_get("include_path") . PATH_SEPARATOR . $INCLUDE_PATH);
require_once "init.php";
$db = new Database($TWITALYTIC_CFG);
$conn = $db->getConnection();
$ud = new UserDAO($db);
$fd = new FollowDAO($db);
$id = new InstanceDAO($db);
$td = new TweetDAO($db);
if (isset($_REQUEST['u']) && $ud->isUserInDBByName($_REQUEST['u']) && isset($_REQUEST['i'])) {
$user = $ud->getUserByName($_REQUEST['u']);
$i = $id->getByUsername($_REQUEST['i']);
if (isset($i)) {
$cfg = new Config($i->twitter_username, $i->twitter_user_id);
$s = new SmartyTwitalytic();
if (!$s->is_cached('user.index.tpl', $i->twitter_username . "-" . $user['user_name'])) {
$s->assign('profile', $user);
$s->assign('user_statuses', $td->getAllTweets($user['user_id'], 20));
$s->assign('sources', $td->getStatusSources($user['user_id']));
$s->assign('cfg', $cfg);
$s->assign('instance', $i);
$exchanges = $td->getExchangesBetweenUsers($cfg->twitter_user_id, $user['user_id']);
$s->assign('exchanges', $exchanges);
$s->assign('total_exchanges', count($exchanges));
$mutual_friends = $fd->getMutualFriends($user['user_id'], $i->twitter_user_id);
$s->assign('mutual_friends', $mutual_friends);
示例2: convertPostToTweet
/**
* Convert the post as it is returned from the database to how it looks when output by the Twitter API.
* Also, add the replies into the post with the index "replies".
*
* If the $post parameter is not a Post object, the function returns null.
*
* @param Post $post The post object.
* @return stdObject The post formatted to look like the Twitter API.
*/
private function convertPostToTweet($post)
{
if (!$post instanceof Post) {
return null;
}
if ($this->include_replies) {
/*
* Get all replies to the post. The limit is set to 0 because if the count is not greater than 0,
* the method returns all replies.
*/
$replies = $this->post_dao->getRepliesToPost($post->post_id, $post->network, $this->order_by, $this->unit, $this->is_public, 0);
// if replies exist for this post
if ($replies) {
// recursively scan through the post replies, converting them
foreach ($replies as $reply) {
$reply = $this->convertPostToTweet($reply);
}
// add the replies to the post
$post->replies = $replies;
}
}
/*
* Chop and changing the data fetched from the database to look more like the official Twitter API.
*/
$post->text = $post->post_text;
$post->created_at = strftime('%a %b %d %T %z %Y', strtotime($post->pub_date));
$post->id = $post->post_id;
$post->favorited = $post->favorited ? true : false;
$post->annotations = null;
// to be implemented at some point
$post->truncated = false;
// always false
$post->protected = $post->is_protected == 0 ? false : true;
if ($post->geo != null) {
$coordinates = preg_split('/(, |,| )/', $post->geo);
$post->geo = new stdClass();
$post->geo->coordinates = $coordinates;
if (!isset($post->coordinates)) {
$post->coordinates = new stdClass();
}
$post->coordinates->coordinates = $coordinates;
}
/*
* SET THINKUP METADATA
*/
$post->thinkup = new stdClass();
$post->thinkup->retweet_count_cache = $post->retweet_count_cache;
$post->thinkup->retweet_count_api = $post->retweet_count_api;
$post->thinkup->reply_count_cache = $post->reply_count_cache;
$post->thinkup->old_retweet_count_cache = $post->old_retweet_count_cache;
$post->thinkup->is_geo_encoded = $post->is_geo_encoded;
$user = $this->user_dao->getUserByName($post->author_username, $post->network);
/*
* Occasionally you run into users you haven't fetched yet. Bypass this code if you find one of them.
*/
if ($user != null) {
if (!$this->trim_user) {
$post->user = $this->convertUserToStdClass($user);
$post->user->id = $post->user->user_id;
$post->user->followers_count = $post->user->follower_count;
$post->user->profile_image_url = $post->user->avatar;
$post->user->name = $post->user->full_name;
$post->user->screen_name = $post->user->username;
$post->user->statuses_count = $post->user->post_count;
$post->user->created_at = strftime('%a %b %d %T %z %Y', strtotime($post->user->joined));
$post->user->favorites_count = $post->user->favorites_count;
if (isset($post->user->other)) {
if (isset($post->user->other['avg_tweets_per_day'])) {
$post->user->avg_tweets_per_day = $post->user->other['avg_tweets_per_day'];
}
}
$post->user->thinkup = new stdClass();
$post->user->thinkup->last_post = $post->user->last_post;
$post->user->thinkup->last_post_id = $post->user->last_post_id;
$post->user->thinkup->found_in = $post->user->found_in;
} else {
$post->user = new stdClass();
$post->user->id = $user->user_id;
}
}
if ($this->include_entities) {
/*
* Gather hashtags and format them into a Tweet entity.
*/
$extracted_hashtags = Post::extractHashtags($post->text);
if (!isset($post->entities)) {
$post->entities = new stdClass();
}
$post->entities->hashtags = array();
if (!empty($extracted_hashtags)) {
foreach ($extracted_hashtags as $hashtag_text) {
//.........这里部分代码省略.........
示例3: testGetUserByNameUserDoesNotExist
function testGetUserByNameUserDoesNotExist()
{
$udao = new UserDAO($this->db, $this->logger);
$user = $udao->getUserByName('gina');
$this->assertTrue(!isset($user));
}