]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Quick function to get an array of thumbnails for a gallery page.
authorSean Corbett <sean@gnu.org>
Sat, 4 Sep 2010 21:17:52 +0000 (17:17 -0400)
committerSean Corbett <sean@gnu.org>
Sat, 4 Sep 2010 21:35:37 +0000 (17:35 -0400)
plugins/GNUsocialPhotos/GNUsocialPhotosPlugin.php
plugins/GNUsocialPhotos/actions/photos.php
plugins/GNUsocialPhotos/actions/photoupload.php
plugins/GNUsocialPhotos/classes/gnusocialphoto.php

index 79da703210ba4238318a4a389578d4e39b43c1ab..f67cfec3412a80b291c5e0483cd5d156e37a5b0e 100644 (file)
@@ -62,6 +62,8 @@ class GNUsocialPhotosPlugin extends Plugin
         $schema = Schema::get();
         $schema->ensureTable('GNUsocialPhoto',
                                 array(new ColumnDef('notice_id', 'int(11)', null, false),
+                                      new ColumnDef('album_id', 'int(11)', null, false),
+                                      //new ColumnDef('album_name', 'varchar(30)', null, false),
                                       new ColumnDef('uri', 'varchar(512)', null, false),
                                       new ColumnDef('thumb_uri', 'varchar(512)', null, false)));
     }
index 29a70e4589b03e730502711f91261988f6d0fb8a..bc54ae9937b572c434b526e0b3c78ec8dc22db1f 100644 (file)
@@ -86,6 +86,11 @@ class PhotosAction extends Action
             $pathparts = explode('/', $args[1]['nickname']);
             $username = $pathparts[0];
             $this->elementStart('ul', array('class' => 'photothumbs'));
+
+                       //scorbett
+                       $photo_obj = new GNUsocialPhoto();
+                       $photo_obj->getGalleryPage(1, 0, 9);
+
             while (false !== ($file = readdir($dir))) {
                 $fparts = explode('-', $file);
                 if ($fparts[0] == $username // uploaded by this user
index 216f1768f00eb40a19176a5b1f37b3b4103da6d6..84caf474754aebf2bc4110f4d6e79dabe4f3f872 100644 (file)
@@ -137,7 +137,8 @@ class PhotouploadAction extends Action
         $uri = 'http://' . common_config('site', 'server') . '/file/' . $filename;
         $thumb_uri = 'http://' . common_config('site', 'server') . '/file/thumb.' . $filename;
         $profile_id = $cur->id;
-        GNUsocialPhoto::saveNew($profile_id, $thumb_uri, $uri, 'web');
+               //scorbett: the second arg below should be set to the album ID
+        GNUsocialPhoto::saveNew($profile_id, 0, $thumb_uri, $uri, 'web');
     }
 
 }
index 4965cd0d9cec5a499f511e8de7214bc43f7bbcc0..f218d570f4c42d9da56f3fc776706825b76c3dbc 100644 (file)
@@ -36,9 +36,16 @@ class GNUsocialPhoto extends Memcached_DataObject
 {
     public $__table = 'GNUsocialPhoto';
     public $notice_id;  // int(11)
+    public $album_id;   // int(11)
     public $uri;        // varchar(512)
     public $thumb_uri;  // varchar(512)
     
+
+    /**
+     *
+     * k key
+     * v value
+     */
     function staticGet($k,$v=NULL)
     {
         return Memcached_DataObject::staticGet('GNUsocialPhoto',$k,$v);
@@ -58,6 +65,7 @@ class GNUsocialPhoto extends Memcached_DataObject
     function table()
     {
         return array('notice_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
+                     'album_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
                      'uri' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
                      'thumb_uri' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL);
     }
@@ -77,11 +85,12 @@ class GNUsocialPhoto extends Memcached_DataObject
         return array(false, false, false);
     }
 
-    function saveNew($profile_id, $thumb_uri, $uri, $source)
+    function saveNew($profile_id, $album_id, $thumb_uri, $uri, $source)
     {
         $photo = new GNUsocialPhoto();
         $photo->thumb_uri = $thumb_uri;
         $photo->uri = $uri;
+               $photo->album_id = $album_id;
 
         $notice = Notice::saveNew($profile_id, $uri, $source);
         $photo->notice_id = $notice->id;
@@ -92,6 +101,28 @@ class GNUsocialPhoto extends Memcached_DataObject
         }
     }
 
+
+    /*
+     * TODO: -Sanitize input
+     * @param int page_id The desired page of the gallery to show.
+     * @param int album_id The id of the album to get photos from.
+     * @param int gallery_size The number of thumbnails to show per page in the gallery.
+     * @return array Array of GNUsocialPhotos for this gallery page.
+     */
+    function getGalleryPage($page_id, $album_id, $gallery_size)
+    {
+               $page_offset = ($page_id-1) * $gallery_size; 
+        $sql = 'SELECT * FROM GNUsocialPhoto order by notice_id limit ' . $page_offset . ',' . $gallery_size; 
+        $this->query($sql);
+        $thumbs = array();
+
+        while ($this->fetch()) {
+            $thumbs[] = clone($this);
+        }
+
+        return $thumbs;
+    }
+
     /*
     function asActivityNoun($element)
     {