Fork me on GitHub

new functions in mediashare...  Bottom

  • Hi
    I have look recently for module which could really handle user pictures... I want to make some functions for community like user album, user picture instead of avatar everything in one good module like Pagesetter :D. First I start to think about Mediashare but I wasn't sure about it, then I have found on elfisk.dk www.sexyandfamous.com...

    Ok so I make some changes:
    First user able to have only one folder with nested level 2 - called User main folder
    At the beginning of user edit view function, when function is called without aid I add check if user have already his own main album. If yes then pass it's aid to edit function, if not create album with his name as a title and then pass newaid to edit function.
    I have add small function to handle check if user have album:

    Code

    function mediashare_userapi_getMainUserAlbum($args)
    {
      Argument check
      if (!isset($args['uid']))
        return mediashareErrorAPI(__file__, __line__, 'Missing userid in mediashare_userapi_getMainUserAlbum');

        Check access
      if (!pnSecAuthAction(0, 'mediashare::', '::', ACCESS_READ))
        return mediashareErrorAPI(__file__, __line__, _MSNOAUTH);

      $ownerId = (int)$args['uid'];

      list($dbconn) = pnDBGetConn();
      $pntable = pnDBGetTables();

      $albumsTable   = $pntable['mediashare_albums'];
      $albumsColumn  = $pntable['mediashare_albums_column'];

    $sql = "        SELECT album.$albumsColumn[id]
                    FROM $albumsTable album
                     WHERE album.$albumsColumn[ownerId] = $ownerId
                     AND album.$albumsColumn[nestedSetLevel] <= 2
                     ORDER BY album.$albumsColumn[createdDate] ASC "
    ;

      $result = $dbconn->execute($sql);

      if ($dbconn->errorNo() != 0)
        return mediashareErrorAPI(__file__, __line__, '"getMainAlbumItem" failed: ' . $dbconn->errorMsg() . " while executing: $sql");

      if ($result->EOF)
        return null;

        $item = $result->fields[0];

        $result->Close();

        return $item;
     }


    it's not perfect but it's working correctly.

    Now main item in main user album is the main user picture :D and here I have problem. This function is called every time when user picture is needed so in comments, last seen block, members list, forum...

    Code

    function mediashare_userapi_getMainAlbumItem($args)
    {
     
      if (!isset($args['uname']))
        return mediashareErrorAPI(__file__, __line__, 'Missing username in mediashare_userapi_getMainAlbumItem');

       
      if (!pnSecAuthAction(0, 'mediashare::', '::', ACCESS_READ))
        return mediashareErrorAPI(__file__, __line__, _MSNOAUTH);

      $albumId        = (int)$args['albumId'];
      $ownerId        = (int)pnUserGetIDFromName($args['uname']);

      list($dbconn) = pnDBGetConn();
      $pntable = pnDBGetTables();

      $albumsTable   = $pntable['mediashare_albums'];
      $albumsColumn  = $pntable['mediashare_albums_column'];
      $mediaTable    = $pntable['mediashare_media'];
      $mediaColumn   = $pntable['mediashare_media_column'];
      $storageTable  = $pntable['mediashare_mediastore'];
      $storageColumn = $pntable['mediashare_mediastore_column'];

     $sql = "        SELECT album.$albumsColumn[id],
                            album.$albumsColumn[mainMediaId],
                            thumbnail.$storageColumn[fileRef],
                            preview.$storageColumn[fileRef]
                     FROM $albumsTable album
                     LEFT JOIN $mediaTable main
                        ON main.$mediaColumn[id] = album.$albumsColumn[mainMediaId]
                     LEFT JOIN $storageTable thumbnail
                        ON thumbnail.$storageColumn[id] = $mediaColumn[thumbnailId]
                     LEFT JOIN $storageTable preview
                     ON preview.$storageColumn[id] = $mediaColumn[previewId]
                     WHERE album.$albumsColumn[ownerId] = $ownerId
                     AND album.$albumsColumn[nestedSetLevel] = 2
                     ORDER BY album.$albumsColumn[createdDate] ASC "
    ;

     
     $result = $dbconn->execute($sql);

      if ($dbconn->errorNo() != 0)
        return mediashareErrorAPI(__file__, __line__, '"getMainAlbumItem" failed: ' . $dbconn->errorMsg() . " while executing: $sql");
           
     $item = array();
      if ($result->EOF)
        return null;

        $item = array( 'albumId'   => $result->fields[0],
                       'mainMediaId'   => $result->fields[1],
                       'thumbnailRef'  => $result->fields[2],
                       'previewRef'  => $result->fields[3]);

        $result->Close();

        return $item;
     }



    I don't know how big load it will generate to the database...
    Other thing is that I'm calling this function from templates and I'm using pnmodapifunc I think some kind of plug-in would be better way to use this than calling but I don't which way is faster...

    Any ideas?




    edited by: Kaik, Oct 31, 2008 - 10:44 PM

    --
    rgfdgafgaf
  • Do your members have own albums?
    How do you create these albums?
    And how and where do you store the aid for each user?
  • ok so I had it done.
    Yes my members have own albums and they are able to use Mediashare as a avatar/userpicture module.
    When someone Clik on "My album" link, system is checking if there is album with have same aid that the user id if is then is moved to his own album if not system is creating albym with user id as aid and then redirect user to its own album. So aid == uid.
    What i have done for rest of users that already have avatar with avatar module. I change avatar path to /documents - where the Mediashare file are stored and copy all avatars to this folder so now all modules looking for avatar in /documents (avatar name is stored in user field) if they have old avatar then is is going to be /documents/avatarname.jpg. when it is user picture from Mediashare it will be /documends/path to catalog and hashed file.jpg

    How it is happening that in user avatar field we have that path?
    We aiming to have a file hashed path so I can update that in users fields.
    I have changed a bit the function whitch is setting the main album file...
    I assumed that the main album will be that "special" album and only setting main file in this album will update the user avatar field.
    When user clik on "My albym" system is redirecting him to his album.
    We know already that the album have aid == uid and we know that this album have nested level = 2.
    Because user may have his own subalbums in his album so that nested level is importand so few ifs in code and function updating user field and it is done:D

    Hope you understand :P http://www.mojecoventry.pl - working perfect :D


    --
    rgfdgafgaf
  • 0 users

This list is based on users active over the last 60 minutes.