How to get setComment to work

I just added "getcomment" to work in the Zenphoto lightroom plugin it can now syn all comments of images

but for some reason I can get "setComment" to work .. what am I missing?

function addImageComments($args) {
global $_zp_current_image;
$v = var_export($args, true);
debuglog ('addImageComments');
debuglog ($v);
if (is_object($login_state = authorize($args))) return $login_state;

$args = decode64($args);
$image = getImageForImageID($args['Id']);
if ($image->filename)
$image->setCommentsAllowed;
$image->setComments($args['commentText']);
else
return new IXR_Error(-1, 'Image not found on server '.$obj['filename']);

return true;
}

Comments

  • Do I need to set an object some how ?
    ex: $comment = $_zp_current_comment new zp_current_comment()
  • acrylian Administrator, Developer
    `$image` must be an image object, otherwise the method cannot work. If this is the current image that would be in `$_zp_current_image` already. Otherwise you need to setup one.

    I don't remember`getImageForImageID($args['Id']);` but does that return an image object?

    Also you need to use the save() method after you setup a new object so you really save the values set (meaing if this is not an existing image in this case but a new one).
  • $image is a image object and the same coding works for my other functions with out a problem and I usually test it with an internal Zenphoto object I know works to make sure.
    I think something is missing :(

    As for the save() ...DUH!!! my bad let me check
  • Also having a issue with getting ratings

    it dies as soon as I do "$image->getRating()"
    So I did some hard coding to check my API logic and its fine,

    function getImageRatings($args) {
    global $_zp_current_image;
    $v = var_export($args, true);
    debuglog ('getImageRatings');
    debuglog ($v);
    if (is_object($login_state = authorize($args))) return $login_state;
    $args = decode64($args);
    $image = getImageForImageID($args['Id']);
    /**if ($image->filename)
    $image->getRating();
    //debuglog ('RatingNumber: '.$image->getRating();
    else
    return new IXR_Error(-1, 'Image not found on server '.$obj['filename']);**/

    return 7;//$image->getRating();
    }
  • This should help with your previous question:
    -----------------------------------------

    function getImageForImageID($id) {
    $row = query_single_row('SELECT '.prefix("images").'.id, '.prefix("images").'.filename, '.prefix("albums").'.folder FROM
    '.prefix("images").' LEFT JOIN '.prefix("albums").' ON '.prefix("images").'.albumId = '.prefix("albums").'.id
    WHERE
    '.prefix("images").'.id='.$id, true);

    $album = new Album(new Gallery(),$row['folder']);
    return new _Image($album, $row['filename']);
    }
  • As soon as I add "$image->save();" it breaks the code...

    I think I have to make a dum theme and test my code in a actual Zenphoto environment to rule up any issues before I make new functions to connect to Zenphoto through the API.

    Let me know if you have any insight.. thanks ... kinda stuck.
  • acrylian Administrator, Developer
    `getImageForImageID`should use `newImage()` instead of directly the constructor. I don't remember why we separated it (sbillard will know) but that makes sure an image obj is created.

    So you can't use the global directly? YOu also should not have to setup the gallery object as that is already in $_zp_gallery most everywhere.
  • Ok so I using one of the default themes to double check my code before I pull my hair out debugging what I can see ..

    When I executed this code
    "<?php echo ('RatingNumber: '.$_zp_current_image->getRating());?>"

    This is the error it produced.

    Fatal error: Call to undefined method _Image::getRating() in /home1/glamwor2/public_html/clients.philbertphotography.com/themes/copy_of_default/image.php on line 56
  • There is no `setComments()` method, so that would be a problem.

    You should probably tell us what errors you are getting. But your descriptions all point to `$image` NOT being an object.
  • acrylian Administrator, Developer
    There is no `getRating`method either. You have to use `$object->get('rating')` directly.
  • So you mean
    function getImageobject($id) {
    $row = query_single_row('SELECT '.prefix("images").'.id, '.prefix("images").'.filename, '.prefix("albums").'.folder FROM
    '.prefix("images").' LEFT JOIN '.prefix("albums").' ON '.prefix("images").'.albumId = '.prefix("albums").'.id
    WHERE
    '.prefix("images").'.id='.$id, true);
    $galleryobject = new Gallery();
    $album = new Album($galleryobject,$row['folder']);
    $image = new newImage($album, $row['filename']);
    return $image;
    }

    When I try it I get an error... let me rework the logic on that end later and see.
  • Or use the function from the rating plugin `getRating($object)`
  • Some suggestions:

    First there is always a global `$_zp_gallery` which contains the gallery object. You can use that. But actually, even that is not needed. The `$galleryobject` parameter is ignored now and you can simply pass NULL. (1.4.5 will introduce a `new_album()` function analogous to the `new_image()` function.)

    There is no guarantee that your will succeed, so you should be testing the result before using it.

    Otherwise, let us know the error and we can better tell what is failing.
  • This code $_zp_current_image->setComment('HELLO DOLLY');

    Created this error...

    Fatal error: Call to undefined method _Image::setComment() in /home1/glamwor2/public_html/clients.philbertphotography.com/themes/copy_of_default/image.php on line 60

    Well I am soo glad I was not going crazy after 10 hours of debugin :P

    I guess I have to make my own function to make this happen since the internal stuff is broken
  • acrylian Administrator, Developer
    `new newImage($album, $row['filename']);`is in any case wrong..;-) (one "new" is enough).

    @sbillard: Aren't the functions `newImage()` and `newAlbum()` without underscore actually unless I missed a change?

    You need to make sure that you use the methods on the right object. If you don't it never will work.
  • OK let me go over the docs again .. I think I made a mistake some where thanks so far ..

    So what is the "setcomment" for?
    http://www.zenphoto.org/documentation/classes/Comment.html#methodsetComment
  • Thanks sbillard and acrylian!
  • That is a method of the comment class, not the image class. That is why the URL you posted is to ...classes/Comment.html....

    Theme objects have an `addComment()` method. Is that what you are looking for?

    @acrylian: You are right, I should always look first before posting a function name.
  • Yes got everything to work except "addcomment" but that is what I was looking for and I will lick it ... Thanks again for the help and understanding ...
  • @sbillard ... forget what I said ... I got it to work after nulling everything I did not need with "" adding null is a bad thing smh.
    reference:
    http://www.zenphoto.org/documentation/classes/ThemeObject.html#methodaddComment
  • Not sure I understand. The comment about NULL had to do with album instantiation. Nothing at all to do with the addComment method.

    The album constructor totally ignores the gallery parameter since there is one and only one gallery object.
  • hmmm something I posted is missing ... sorry ...must have been the spam filter ...anyway here it is again:
    ==================================
    I tested this completely on Zenphoto and it works GREAT .as soon as I added it to the API for the plugin it returns user. any ideas as to why?
    ==================================
    $id = "someid";
    $row = query_single_row('SELECT '.prefix("images").'.id, '.prefix("images").'.filename, '.prefix("albums").'.folder FROM
    '.prefix("images").' LEFT JOIN '.prefix("albums").' ON '.prefix("images").'.albumId = '.prefix("albums").'.id
    WHERE
    '.prefix("images").'.id='.$id, true);

    $albumobject = new Album(new Gallery(),$row['folder']);
    $imageobject = newImage($albumobject, $row['filename']);
    $username = 'Joh Doe';
    $commentText = 'HELLO Blaster World';
    $postcomment = $imageobject->addComment($username, 'fake-email.com', '', $commentText, '','' , '', '', '', '');
    echo 'postcomment '. $postcomment;
Sign In or Register to comment.