Skip to content
This repository
Browse code

Add This Week's Most Discerning Followers to Dashboard and Followers …

…page

Use Web Intents for user avatar links
Closes #973
  • Loading branch information...
commit 70bcbd8577fc0327aabebf5b3576a634335b753f 1 parent 0f8f6c6
Gina Trapani authored November 03, 2011
11  tests/TestOfFollowMySQLDAO.php
@@ -71,13 +71,13 @@ protected function buildData() {
71 71
         'last_seen'=>'2006-01-08 23:54:41', 'network'=>'twitter'));
72 72
 
73 73
         $builders[] = FixtureBuilder::build('follows', array('user_id'=>1324567890, 'follower_id'=>14,
74  
-        'last_seen'=>'2006-01-08 23:54:41', 'network'=>'twitter'));
  74
+        'last_seen'=>'-1d', 'first_seen'=>'-1d', 'network'=>'twitter'));
75 75
 
76 76
         $builders[] = FixtureBuilder::build('follows', array('user_id'=>1324567890, 'follower_id'=>15,
77  
-        'last_seen'=>'2006-01-08 23:54:41', 'network'=>'twitter'));
  77
+        'last_seen'=>'-1d', 'first_seen'=>'-8d', 'network'=>'twitter'));
78 78
 
79 79
         $builders[] = FixtureBuilder::build('follows', array('user_id'=>1324567890, 'follower_id'=>1623457890,
80  
-        'last_seen'=>'2006-01-08 23:54:41', 'network'=>'twitter'));
  80
+        'last_seen'=>'-2d', 'first_seen'=>'-2d', 'network'=>'twitter'));
81 81
 
82 82
         $builders[] = FixtureBuilder::build('follows', array('user_id'=>1623457890, 'follower_id'=>1324567890,
83 83
         'last_seen'=>'2006-01-08 23:54:41', 'network'=>'twitter'));
@@ -233,6 +233,11 @@ public function testGetLeastLikelyFollowers(){
233 233
 
234 234
         $result = $this->DAO->getLeastLikelyFollowers(1324567890, 'twitter', 1, $page = 2);
235 235
         $this->assertEqual($result[0]["user_id"], 1623457890);
  236
+
  237
+        $result = $this->DAO->getLeastLikelyFollowersThisWeek(1324567890, 'twitter', 15);
  238
+        $this->assertIsA($result, "array");
  239
+        $this->assertEqual(count($result), 1);
  240
+        $this->assertEqual($result[0]["user_id"], 1623457890);
236 241
     }
237 242
 
238 243
     public function testGetEarliestJoinerFollowers(){
4  webapp/_lib/controller/class.DashboardController.php
@@ -210,8 +210,8 @@ private function loadDefaultDashboard() {
210 210
 
211 211
             //follows
212 212
             $follow_dao = DAOFactory::getDAO('FollowDAO');
213  
-            $least_likely_followers = $follow_dao->getLeastLikelyFollowers($this->instance->network_user_id, 'twitter',
214  
-            12);
  213
+            $least_likely_followers = $follow_dao->getLeastLikelyFollowersThisWeek($this->instance->network_user_id,
  214
+            'twitter', 12);
215 215
             $this->addToView('least_likely_followers', $least_likely_followers);
216 216
 
217 217
             //follower count history
25  webapp/_lib/model/class.FollowMySQLDAO.php
@@ -269,7 +269,7 @@ public function getMostFollowedFollowers($user_id, $network, $count = 20, $page
269 269
     public function getLeastLikelyFollowers($user_id, $network, $count = 20, $page = 1) {
270 270
         $start_on_record = ($page - 1) * $count;
271 271
 
272  
-        $q  = "SELECT u.*, ROUND(100*friend_count/follower_count,4) ";
  272
+        $q  = "SELECT u.*, ROUND((100*(friend_count/follower_count)),4) ";
273 273
         $q .= "AS LikelihoodOfFollow, ".$this->getAverageTweetCount()." ";
274 274
         $q .= "FROM #prefix#users AS u INNER JOIN #prefix#follows AS f ";
275 275
         $q .= "ON u.user_id = f.follower_id ";
@@ -288,6 +288,29 @@ public function getLeastLikelyFollowers($user_id, $network, $count = 20, $page =
288 288
         return $this->getDataRowsAsArrays($ps);
289 289
     }
290 290
 
  291
+    public function getLeastLikelyFollowersThisWeek($user_id, $network, $count = 20, $page = 1) {
  292
+        $start_on_record = ($page - 1) * $count;
  293
+
  294
+        $q  = "SELECT u.*, ROUND((100*(friend_count/follower_count)),4) ";
  295
+        $q .= "AS likelihood_of_follow, ".$this->getAverageTweetCount()." ";
  296
+        $q .= "FROM #prefix#users AS u INNER JOIN #prefix#follows AS f ";
  297
+        $q .= "ON u.user_id = f.follower_id ";
  298
+        $q .= "WHERE f.first_seen >= date_sub(current_date, INTERVAL 7 day) ";
  299
+        $q .= "AND f.user_id = :user_id AND f.network=:network AND f.network=u.network AND active=1 ";
  300
+        $q .= "AND follower_count > 1000 AND friend_count > 0 ";
  301
+        $q .= "ORDER BY likelihood_of_follow ASC, u.follower_count DESC ";
  302
+        $q .= "LIMIT :start_on_record, :count ;";
  303
+        $vars = array(
  304
+            ':user_id'=>(string)$user_id, 
  305
+            ':network'=>$network,
  306
+            ':count'=>(int)$count,
  307
+            ':start_on_record'=>(int)$start_on_record
  308
+        );
  309
+        if ($this->profiler_enabled) Profiler::setDAOMethod(__METHOD__);
  310
+        $ps = $this->execute($q, $vars);
  311
+        return $this->getDataRowsAsArrays($ps);
  312
+    }
  313
+
291 314
     public function getEarliestJoinerFollowers($user_id, $network, $count = 20, $page = 1) {
292 315
         $start_on_record = ($page - 1) * $count;
293 316
 
12  webapp/_lib/model/interface.FollowDAO.php
@@ -155,7 +155,7 @@ public function getOldestFollow($network);
155 155
     public function getMostFollowedFollowers($user_id, $network, $count = 20, $page = 1);
156 156
 
157 157
     /**
158  
-     * Gets the followes with highest follower:friend count.
  158
+     * Gets the followers with highest follower:friend count.
159 159
      * @param int $user_id
160 160
      * @param str $network
161 161
      * @param int $count
@@ -165,6 +165,16 @@ public function getMostFollowedFollowers($user_id, $network, $count = 20, $page
165 165
     public function getLeastLikelyFollowers($user_id, $network, $count = 20, $page = 1);
166 166
 
167 167
     /**
  168
+     * Gets the followers with highest follower:friend count first seen by ThinkUp in the past 7 days.
  169
+     * @param int $user_id
  170
+     * @param str $network
  171
+     * @param int $count
  172
+     * @param int $page defaults to 1
  173
+     * @return array - numbered keys, with arrays - named keys
  174
+     */
  175
+    public function getLeastLikelyFollowersThisWeek($user_id, $network, $count = 20, $page = 1);
  176
+
  177
+    /**
168 178
      * Gets the followers with the earliest join date.
169 179
      * @param int $user_id
170 180
      * @param str $network
4  webapp/_lib/view/dashboard.tpl
@@ -171,11 +171,11 @@
171 171
             {/if}
172 172
             {if $least_likely_followers}
173 173
               <div class="clearfix">
174  
-                <h2>Most Discerning Followers</h2>
  174
+                <h2>This Week's Most Discerning Followers</h2>
175 175
                 <div class="clearfix">
176 176
                 {foreach from=$least_likely_followers key=uid item=u name=foo}
177 177
                   <div class="avatar-container" style="float:left;margin:7px;">
178  
-                    <a href="http://twitter.com/{$u.user_name}" title="{$u.user_name}"><img src="{$u.avatar}" class="avatar2"/><img src="{$site_root_path}plugins/{$u.network}/assets/img/favicon.ico" class="service-icon2"/></a>
  178
+                    <a href="https://twitter.com/intent/user?user_id={$u.user_id}" title="{$u.user_name} has {$u.follower_count|number_format} followers and {$u.friend_count|number_format} friends"><img src="{$u.avatar}" class="avatar2"/><img src="{$site_root_path}plugins/{$u.network}/assets/img/favicon.ico" class="service-icon2"/></a>
179 179
                   </div>
180 180
                 {/foreach}
181 181
                 <div class="clearfix small prepend">
7  webapp/plugins/twitter/model/class.TwitterPlugin.php
@@ -250,9 +250,12 @@ public function getDashboardMenuItems($instance) {
250 250
 
251 251
         $followers_ds1 = new Dataset('leastlikely', 'FollowDAO', "getLeastLikelyFollowers", array(
252 252
         $instance->network_user_id, 'twitter', 13, '#page_number#'));
253  
-        $followers_ds1->addHelp('userguide/listings/twitter/dashboard_friends-mostactive');
254 253
         $followers_menu_item->addDataset($followers_ds1);
255 254
 
  255
+        $followers_ds9 = new Dataset('leastlikelythisweek', 'FollowDAO', "getLeastLikelyFollowersThisWeek", array(
  256
+        $instance->network_user_id, 'twitter', 13, '#page_number#'));
  257
+        $followers_menu_item->addDataset($followers_ds9);
  258
+
256 259
         $followers_ds2 = new Dataset("popular", 'FollowDAO', "getMostFollowedFollowers", array(
257 260
         $instance->network_user_id, 'twitter', 13, '#page_number#'));
258 261
         $followers_ds2->addHelp('userguide/listings/twitter/dashboard_followers-mostfollowed');
@@ -455,7 +458,7 @@ public function getDashboardMenuItems($instance) {
455 458
 
456 459
         //List membership count history
457 460
         $group_membership_history_tpl = Utils::getPluginViewDirectory('twitter').'twitter.listmembershipcount.tpl';
458  
-        $group_trend_tab = new MenuItem('List stats', 'Your list membership count over time', 
  461
+        $group_trend_tab = new MenuItem('List stats', 'Your list membership count over time',
459 462
         $group_membership_history_tpl, 'followers');
460 463
         $group_trend_tab_ds = new Dataset("list_membership_count_history_by_day", 'GroupMembershipCountDAO',
461 464
         'getHistory', array($instance->network_user_id, 'twitter', 'DAY', 15));
18  webapp/plugins/twitter/view/followers.tpl
... ...
@@ -1,18 +1,28 @@
  1
+{if $leastlikelythisweek|@count >1}
  2
+    <h2>This Week's Most Discerning Followers</h2>
  3
+    {foreach from=$leastlikelythisweek key=tid item=u name=foo}
  4
+      <div class="avatar-container" style="float:left;margin:7px;">
  5
+        <a href="https://twitter.com/intent/user?user_id={$u.user_id}"  title="{$u.user_name} has {$u.follower_count|number_format} followers and {$u.friend_count|number_format} friends"><img src="{$u.avatar}" class="avatar2"/><img src="{$site_root_path}plugins/{$u.network}/assets/img/favicon.ico" class="service-icon2"/></a>
  6
+      </div>
  7
+    {/foreach}
  8
+    <div align="right" style="clear:all;padding-top:60px"><a href="index.php?v=followers-leastlikely&u={$instance->network_username}&n=twitter">More...</a></div>
  9
+{/if}
  10
+
1 11
 {if $leastlikely|@count >1}
2  
-    <h2>Most Discerning</h2>
  12
+    <h2>All-Time Most Discerning Followers</h2>
3 13
     {foreach from=$leastlikely key=tid item=u name=foo}
4 14
       <div class="avatar-container" style="float:left;margin:7px;">
5  
-        <a href="http://twitter.com/{$u.user_name}" title="{$u.user_name}"><img src="{$u.avatar}" class="avatar2"/><img src="{$site_root_path}plugins/{$u.network}/assets/img/favicon.ico" class="service-icon2"/></a>
  15
+        <a href="https://twitter.com/intent/user?user_id={$u.user_id}" title="{$u.user_name} has {$u.follower_count|number_format} followers and {$u.friend_count|number_format} friends"><img src="{$u.avatar}" class="avatar2"/><img src="{$site_root_path}plugins/{$u.network}/assets/img/favicon.ico" class="service-icon2"/></a>
6 16
       </div>
7 17
     {/foreach}
8 18
     <div align="right" style="clear:all;padding-top:60px"><a href="index.php?v=followers-leastlikely&u={$instance->network_username}&n=twitter">More...</a></div>
9 19
 {/if}
10 20
 
11 21
 {if $popular|@count >1}
12  
-    <h2>Most Popular</h2>
  22
+    <h2>Most Popular Followers</h2>
13 23
     {foreach from=$popular key=tid item=u name=foo}
14 24
       <div class="avatar-container" style="float:left;margin:7px;">
15  
-        <a href="http://twitter.com/{$u.user_name}" title="{$u.user_name}"><img src="{$u.avatar}" class="avatar2"/><img src="{$site_root_path}plugins/{$u.network}/assets/img/favicon.ico" class="service-icon2"/></a>
  25
+        <a href="https://twitter.com/intent/user?user_id={$u.user_id}" title="{$u.user_name} has {$u.follower_count|number_format} followers and {$u.friend_count|number_format} friends"><img src="{$u.avatar}" class="avatar2"/><img src="{$site_root_path}plugins/{$u.network}/assets/img/favicon.ico" class="service-icon2"/></a>
16 26
       </div>
17 27
     {/foreach}
18 28
     <div align="right" style="clear:all;padding-top:60px"><a href="index.php?v=followers-mostfollowed&u={$instance->network_username}&n=twitter">More...</a></div>

0 notes on commit 70bcbd8

Please sign in to comment.
Something went wrong with that request. Please try again.