PostNuke: A Flexible Open Source Content Management System
home | forum | international support | contact us

Support Forum

Start ::  Developers Corner ::  Module Development ::  new functions in mediashare...

Moderated by: Support Team

Bottom
new functions in mediashare...

  • Link to this postingPosted: 09.04.2008, 21:10
    Profile Homepage
    Kaik
    rank:
    pnFreshman pnFreshman
    registered:
     December 2006
    Status:
    online
    Posts:
    14
    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 http://www.sexyandfamous.com...
    Ok so I make some changes:
    First user able to have only one module with nested level 2 - called User main module
    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 "
    ;

     //echo "<pre>$sql</pre>\n"; exit(0);
      $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)
    {
      // Argument check
      if (!isset($args['uname']))
        return mediashareErrorAPI(__file__, __line__, 'Missing username in mediashare_userapi_getMainAlbumItem');

        // Check access
      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 "
    ;

     //echo "<pre>$sql</pre>\n"; exit(0);
     $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?

    -----
    rgfdgafgaf

Start ::  Developers Corner ::  Module Development ::  new functions in mediashare...

Main Menu

Extensions Database

Documentation

Development

Login





 


 Log in Problems?
 New User? Sign Up!

Donate to PostNuke