ZenphotoCMS Forum
How to get setComment to work - Printable Version

+- ZenphotoCMS Forum (https://forum.zenphoto.org)
+-- Forum: Support (https://forum.zenphoto.org/forum-1.html)
+--- Forum: General support (https://forum.zenphoto.org/forum-4.html)
+--- Thread: How to get setComment to work (/thread-10989.html)

Pages: 1 2


How to get setComment to work - jphilbert - 2013-04-11

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;

}




How to get setComment to work - jphilbert - 2013-04-11

Do I need to set an object some how ?
ex: $comment = $_zp_current_comment new zp_current_comment()




How to get setComment to work - acrylian - 2013-04-11

$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 remembergetImageForImageID($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).




How to get setComment to work - jphilbert - 2013-04-11

$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




How to get setComment to work - jphilbert - 2013-04-11

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();

}




How to get setComment to work - jphilbert - 2013-04-11

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']);
}



How to get setComment to work - jphilbert - 2013-04-11

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.




How to get setComment to work - acrylian - 2013-04-11

getImageForImageIDshould 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.




How to get setComment to work - jphilbert - 2013-04-11

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
""

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




How to get setComment to work - sbillard - 2013-04-11

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 [b]NOT[/b] being an object.




How to get setComment to work - acrylian - 2013-04-11

There is no getRatingmethod either. You have to use $object->get('rating') directly.




How to get setComment to work - jphilbert - 2013-04-11

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.




How to get setComment to work - sbillard - 2013-04-11

Or use the function from the rating plugin getRating($object)




How to get setComment to work - sbillard - 2013-04-11

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.




How to get setComment to work - jphilbert - 2013-04-11

This code $_zp_current_image->setComment('HELLO DOLLY');

Created this error...

Fatal error: Call to undefined method _Image:etComment() 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

I guess I have to make my own function to make this happen since the internal stuff is broken




How to get setComment to work - acrylian - 2013-04-11

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.




How to get setComment to work - jphilbert - 2013-04-11

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




How to get setComment to work - jphilbert - 2013-04-11

Thanks sbillard and acrylian!




How to get setComment to work - sbillard - 2013-04-11

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.




How to get setComment to work - jphilbert - 2013-04-11

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 ...