]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/Sample/User_greeting_count.php
Merge branch 'testing' of gitorious.org:statusnet/mainline into testing
[quix0rs-gnu-social.git] / plugins / Sample / User_greeting_count.php
index d9a59770d3c6fad0a65d8ffa96f0c6b02b8011b7..8128343d817f338660cf12dd27af019bc10ff91f 100644 (file)
@@ -52,7 +52,6 @@ require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
  *
  * @see      DB_DataObject
  */
-
 class User_greeting_count extends Memcached_DataObject
 {
     public $__table = 'user_greeting_count'; // table name
@@ -68,9 +67,7 @@ class User_greeting_count extends Memcached_DataObject
      * @param mixed  $v Value to lookup
      *
      * @return User_greeting_count object found, or null for no hits
-     *
      */
-
     function staticGet($k, $v=null)
     {
         return Memcached_DataObject::staticGet('User_greeting_count', $k, $v);
@@ -84,7 +81,6 @@ class User_greeting_count extends Memcached_DataObject
      *
      * @return array array of column definitions
      */
-
     function table()
     {
         return array('user_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
@@ -94,29 +90,32 @@ class User_greeting_count extends Memcached_DataObject
     /**
      * return key definitions for DB_DataObject
      *
-     * DB_DataObject needs to know about keys that the table has; this function
-     * defines them.
+     * DB_DataObject needs to know about keys that the table has, since it
+     * won't appear in StatusNet's own keys list. In most cases, this will
+     * simply reference your keyTypes() function.
      *
-     * @return array key definitions
+     * @return array list of key field names
      */
-
     function keys()
     {
-        return array('user_id' => 'K');
+        return array_keys($this->keyTypes());
     }
 
     /**
      * return key definitions for Memcached_DataObject
      *
      * Our caching system uses the same key definitions, but uses a different
-     * method to get them.
+     * method to get them. This key information is used to store and clear
+     * cached data, so be sure to list any key that will be used for static
+     * lookups.
      *
-     * @return array key definitions
+     * @return array associative array of key definitions, field name to type:
+     *         'K' for primary key: for compound keys, add an entry for each component;
+     *         'U' for unique keys: compound keys are not well supported here.
      */
-
     function keyTypes()
     {
-        return $this->keys();
+        return array('user_id' => 'K');
     }
 
     /**
@@ -129,7 +128,6 @@ class User_greeting_count extends Memcached_DataObject
      *
      * @return array magic three-false array that stops auto-incrementing.
      */
-
     function sequenceKey()
     {
         return array(false, false, false);
@@ -145,13 +143,11 @@ class User_greeting_count extends Memcached_DataObject
      *
      * @return User_greeting_count instance for this user, with count already incremented.
      */
-
     static function inc($user_id)
     {
         $gc = User_greeting_count::staticGet('user_id', $user_id);
 
         if (empty($gc)) {
-
             $gc = new User_greeting_count();
 
             $gc->user_id        = $user_id;
@@ -160,12 +156,12 @@ class User_greeting_count extends Memcached_DataObject
             $result = $gc->insert();
 
             if (!$result) {
-                throw Exception(sprintf(_m("Could not save new greeting count for %d"),
+                // TRANS: Exception thrown when the user greeting count could not be saved in the database.
+                // TRANS: %d is a user ID (number).
+                throw Exception(sprintf(_m('Could not save new greeting count for %d.'),
                                         $user_id));
             }
-
         } else {
-
             $orig = clone($gc);
 
             $gc->greeting_count++;
@@ -173,7 +169,9 @@ class User_greeting_count extends Memcached_DataObject
             $result = $gc->update($orig);
 
             if (!$result) {
-                throw Exception(sprintf(_m("Could not increment greeting count for %d"),
+                // TRANS: Exception thrown when the user greeting count could not be saved in the database.
+                // TRANS: %d is a user ID (number).
+                throw Exception(sprintf(_m('Could not increment greeting count for %d.'),
                                         $user_id));
             }
         }