front page now has movers and shakers
authorToby Elliott <telliott@mozilla.com>
Tue, 07 Jul 2009 15:04:10 -0700
changeset 1063 8d3c2f468be2a9bb4287549315d49559258eaecd
parent 1062 a529392313f65eeef76f95b93356936915fb07b0
child 1064 637af711c76366d8895b2a88eb5f6813e2abd3d0
push id680
push usertelliott@mozilla.com
push dateTue, 07 Jul 2009 22:04:13 +0000
front page now has movers and shakers
personas.sql
server/index.php
server/lib/storage.php
server/templates/movers.php
--- a/personas.sql
+++ b/personas.sql
@@ -50,17 +50,17 @@ CREATE TABLE `personas` (
   `textcolor` varchar(10) default NULL,
   `popularity` int(11) default NULL,
   `description` text,
   `license` varbinary(10) default NULL,
   `reason` varbinary(24) default NULL,
   `reason_other` varbinary(256) default NULL,
   `featured` tinyint(4) default NULL,
   `locale` varchar(2) default NULL,
-  `movers` int(11) default NULL,
+  `movers` float default NULL,
   PRIMARY KEY  (`id`),
   UNIQUE KEY `name` (`name`),
   FULLTEXT KEY `name_2` (`name`,`description`)
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
 
 CREATE TABLE `users` (
   `username` varchar(32) NOT NULL,
   `display_username` varchar(32) default NULL,
--- a/server/index.php
+++ b/server/index.php
@@ -33,17 +33,17 @@
                     <div id="info">
                         <h4>Theme your browser according to your mood, hobby or season. </h4>
                         <p>Click the green download button to get started!</p>                  
                     </div>
                 </div>
             </div>
 <?php include 'templates/featured_personas.php'; ?>
 <?php include 'templates/featured_designer.php'; ?>
-<?php include 'templates/popular_personas.php'; ?>
+<?php include 'templates/movers.php'; ?>
 
         </div>
     </div>
 <?php include 'templates/footer.php'; ?>
     <script type="text/javascript" charset="utf-8">
         $(document).ready(function () {
             $(".slideshow").slider();
             $("#more-info").popup();
--- a/server/lib/storage.php
+++ b/server/lib/storage.php
@@ -114,16 +114,17 @@
 #  added - date added
 
 #####
 # Memcache keys used by this module: 
 #  p:<persona id> - data for a single persona
 #  ca:<page>:<category> - gallery 'All' pages entries for a category
 #  cr:<category> - gallery 'Recent' page entries for a category
 #  cp:<category> - gallery 'Popular' page entries for a category
+#  cm:<category> - movers and shakers for a category
 #  pc:<category> - current persona count for a category
 #  au:<author>:<category> - personas from an author
 #  fav:<author>:<category> - favorite personas
 #  categories - a list of categories
 
 require_once 'personas_constants.php';
 
 class PersonaStorage
@@ -463,16 +464,65 @@ class PersonaStorage
 		}		
 
 		if ($this->_memcache)
 			$this->_memcache->set("cp:" . ($category ? $category : 'All'), $personas, false, MEMCACHE_DECAY);
 
 		return $personas;
 	}
 
+#####
+# Returns the most active movers and shakers from the db - personas that are seeing big changes in numbers
+
+	function get_movers($category = null)
+	{
+		if ($category == 'All')
+			$category = null;
+		
+		if ($this->_memcache)
+		{
+			$result = $this->_memcache->get("cm:" . ($category ? $category : 'All'));
+			if ($result)
+				return $result;
+		}
+
+		if (!$this->_dbh)
+			$this->db_connect();		
+		
+		try
+		{
+			$statement = 'select * from personas where status = 1' . ($category ? " and category = :category" : "") . ' order by movers desc limit ' . PERSONA_GALLERY_PAGE_SIZE;
+			$sth = $this->_dbh->prepare($statement);
+			if ($category)
+			{
+				$sth->bindParam(':category', $category);
+			}
+			$sth->execute();
+		}
+		catch( PDOException $exception )
+		{
+			error_log($exception->getMessage());
+			throw new Exception("Database unavailable", 503);
+		}
+		
+		$personas = array();
+		
+		while ($result = $sth->fetch(PDO::FETCH_ASSOC))
+		{
+			if (!$result['display_username'])
+				$result['display_username'] = $result['author'];
+			$personas[] = $result;
+		}		
+
+		if ($this->_memcache)
+			$this->_memcache->set("cm:" . ($category ? $category : 'All'), $personas, false, MEMCACHE_DECAY);
+
+		return $personas;
+		
+	}
 
 #####
 # Searches through the name and description for the requested keywords. Will give you a 
 # PERSONA_GALLERY_PAGE_SIZE worth unless you specify another limit
 	
 	function search_personas($string, $category = null, $limit = null)
 	{
 		$string = str_replace(',', ' ', $string);
new file mode 100644
--- /dev/null
+++ b/server/templates/movers.php
@@ -0,0 +1,22 @@
+            <div class="feature last">
+                <h3>Movers and Shakers</h3>
+                <ol class="popular">
+<?php
+	$list = array_slice($db->get_movers(null), 0, 3);
+	
+	foreach ($list as $persona)
+	{
+		$persona_json = htmlentities(json_encode(extract_record_data($persona)));
+?>
+					<li>
+                            <h4><?= $persona['name'] ?></h4>
+                            <hr />
+                             <a href="/persona/<?= $persona['id'] ?>"><img class="persona" alt="<?= $persona['name'] ?>" persona="<?= $persona_json ?>" src="<?= PERSONAS_LIVE_PREFIX . '/' . url_prefix($persona['id']) ?>/preview_popular.jpg"></a>
+                            <p class="author">By: <a href="/gallery/Designer/<?= $persona['author'] ?>"><?= $persona['display_username'] ?></a></p>
+                            <p class="downloads"><?= number_format($persona['popularity']) ?> active daily users</p>
+                    </li>
+<?php
+	}
+?>
+                </ol>
+            </div>