Forum

Thread tagged as: Question, Add-on-development

Get album by id

I come up with some questions from a recent project, hope someone can help me with these.

  1. Is there a way to use perch_gallery_image() by image slug instead of ID?

  2. I can get image's parent album's ID by perch_gallery_image(), can I get an album's detail using perch_gallery_album_images() by it's ID? If not how can I get album's slug in this case?

  3. I have created a image upload box to upload cover for an album on the master template
<perch:gallery id="cover" type="image" label="Cover" key="small" width="320" height="320" crop="true" />

How can I refer to this image? If I use

<perch:gallery id="cover" />

it refers to the original image; if I use

<perch:gallery id="small" />

it refers to the small version of the first image in albums. How can I refer to the small version of the cover?

  1. On the sidebar I want to have a gallery navigation dynamically. Level 1 is album name, level is image name. If it is on a specific image or album page, this album opens and other album close(not having level 2)

  2. Can I have category for multiple items region? Just that I can go into each category to add new items. If not, how to implement thing like this?

  3. How to output file size, file type, and upload date of a file uploaded by a

<perch:content id="download" type="file" label="File" />

Thanks,

Andrew Liu

Andrew Liu 0 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

  1. Is there a way to use perch_gallery_image() by image slug instead of ID?

No, you need an ID, which you can get when displaying the album.

  1. I can get image's parent album's ID by perch_gallery_image(), can I get an album's detail using perch_gallery_album_images() by it's ID? If not how can I get album's slug in this case?

It should be albumID on the image.

  1. I have created a image upload box to upload cover for an album on the master template

Use

<perch:gallery id="cover" type="image" width="320" height="320" crop="true" />
  1. On the sidebar I want to have a gallery navigation dynamically. Level 1 is album name, level is image name. If it is on a specific image or album page, this album opens and other album close(not having level 2)

Ok. Where are you having problems?

  1. Can I have category for multiple items region? Just that I can go into each category to add new items. If not, how to implement thing like this?

You can add a field for a category, yes.

  1. How to output file size, file type, and upload date of a file uploaded by a

output="size"

https://docs.grabaperch.com/docs/templates/attributes/type/file/

In future it's better to stick to one question per thread. As soon as you have further feedback on any of these six points, this thread is going to become very hard to manage and thus it'll be hard for me to help you.

2 I can get image's parent album's ID by perch_gallery_image(), can I get an album's detail using perch_gallery_album_images() by it's ID? If not how can I get album's slug in this case?

It should be albumID on the image.

Sorry if I didn't describe it clearly. perch_gallery_album_images() requires album slug, but I can only get albumID from perch_gallery_image(), in this case how to use perch_gallery_album_images()?

4 On the sidebar I want to have a gallery navigation dynamically. Level 1 is album name, level is image name. If it is on a specific image or album page, this album opens and other album close(not having level 2)

Ok. Where are you having problems?

Problem is how to achieve this? Can you show it with example?

5 Can I have category for multiple items region? Just that I can go into each category to add new items. If not, how to implement thing like this?

You can add a field for a category, yes.

I have just added this

<perch:content type="select" id="category" label="Category" options="A, B, C, D, E, F" allowempty="false" required="true"/>

Then how to filter them by categories in the CMS? Just want to make it easy to use for admins, they can target and go in a specific category to add record.

6 How to output file size, file type, and upload date of a file uploaded by a

output="size" https://docs.grabaperch.com/docs/templates/attributes/type/file/

~output="size"~ works for me, what about file type, and upload date of a file

In future it's better to stick to one question per thread. As soon as you have further feedback on any of these six points, this thread is going to become very hard to manage and thus it'll be hard for me to help you.

Ok, how do you want me to continue this if I still have future feedback on these 4? Thanks

Can you advice on this as well

                    if(!empty($_POST['search'])){
                        perch_blog_custom(array(
                            'count' => 999,
                            'template' => 'output-post-list.html',
                            'sort' => 'postDateTime',
                            'sort-order' => 'DESC',
                            'filter' => 'postTitle',
                            'match' => 'contains',
                            'value' => $_POST['search']
                        ));
                    }

I used this before without problem, but on this project using 'contains' doesn't give me results I want, it returns nothing. If I use 'eq' it works for me, not sure if syntax/keyword are changed on this version of perch, 2.5.4

Also how to filter multiple fields? like php and / or?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you turn debug on and show me the query it outputs for the filter?

Any answer to my first reply?

Drew McLellan

Drew McLellan 2638 points
Perch Support

We don't have an upload date for a file unless you've added a field to capture that.

You'd use a filter to filter for the category

'filter' => 'category',
'match' => 'eq',
'value' => 'A',

Found this syntax error

SELECT SQL_CALC_FOUND_ROWS DISTINCT p.* FROM perch2_blog_posts p WHERE postStatus='Published' AND postDateTime<='2014-08-04 11:25:00' AND postTitle REGEXP '[[:<:]]'.my-search-string.'[[:>:]]' ORDER BY postDateTime DESC LIMIT 0, 999

Invalid query: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.my-search-string.'[[:>:]]' ORDER BY postDateTime DESC LIMIT 0, 999' at line 1

This is the only question left in this post, other unsolved issues have been raised in different posts.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, that looks like a bug. I'll get it fixed.

Drew McLellan said:

Yes, that looks like a bug. I'll get it fixed.

Hi Drew,

When can this be done? Can you notify me on this post when you finish?

Drew McLellan

Drew McLellan 2638 points
Perch Support

It will be in the next release of Blog.

Hi Drew,

When will the next release be released?

In addition to this, I found something weird. I use filter to implement a search function like this

perch_content_custom('download', array(
    'template' => 'output-download.html',
    'filter'=>array(
        array(
            'filter'=>'title',
            'match' => 'contains',
            'value' => $_POST['search']
        ),
        array(
            'filter'=>'desc',
            'match' => 'contains',
            'value' => $_POST['search']
        ),
    ),
    'match'=>'or'
));

It works perfectly when I type in the full word without space. But if I put part of the word in the search box, it doesn't work. Say my target string is "Test File 1",

"test" works

"test " no

"tes" no

"test file" works

"test file " no

"test fi" no

Following is sample debug code

DIAGNOSTICS:
SELECT regionID, regionTemplate, regionPage, regionRev AS rev FROM perch2_content_regions WHERE regionKey='download' AND (regionPage='/resources.php' OR regionPage='*')
SELECT * FROM ( SELECT idx.itemID, c.regionID, idx.pageID, c.itemJSON, idx2.indexValue as sortval FROM perch2_content_index idx 
JOIN perch2_content_items c ON idx.itemID=c.itemID AND idx.itemRev=c.itemRev AND idx.regionID=c.regionID
JOIN perch2_content_index idx2 ON idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev AND idx2.indexKey='_order' WHERE ((idx.regionID='1' AND idx.itemRev='17')) AND ((idx.indexKey='title' AND idx.indexValue REGEXP '[[:<:]]tes[[:>:]]') OR (idx.indexKey='desc' AND idx.indexValue REGEXP '[[:<:]]tes[[:>:]]')) AND idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev
) as tbl GROUP BY itemID ORDER BY sortval ASC 
Using template: /templates/content/input-download.html
SELECT * FROM ( SELECT idx.itemID, c.regionID, idx.pageID, c.itemJSON, idx2.indexValue as sortval FROM perch2_content_index idx 
JOIN perch2_content_items c ON idx.itemID=c.itemID AND idx.itemRev=c.itemRev AND idx.regionID=c.regionID
JOIN perch2_content_index idx2 ON idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev AND idx2.indexKey='_order' WHERE ((idx.regionID='1' AND idx.itemRev='17')) AND ((idx.indexKey='title' AND idx.indexValue REGEXP '[[:<:]]tes[[:>:]]') OR (idx.indexKey='desc' AND idx.indexValue REGEXP '[[:<:]]tes[[:>:]]')) AND idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev
) as tbl GROUP BY itemID ORDER BY sortval ASC 
Using template: /templates/content/output-download.html
Drew McLellan

Drew McLellan 2638 points
Perch Support

We test against word boundaries.

Is there anyway to filter this like what we can do in mysql?

Drew McLellan

Drew McLellan 2638 points
Perch Support

How would you do it in MySQL? If you give me an idea what you're looking to do I can point you in the right direction.

Something like this

SELECT id FROM internal_quote WHERE name LIKE ? OR title LIKE ? OR description LIKE ? ORDER BY internal_quote.id DESC

?s are parameters to be bound

Drew McLellan

Drew McLellan 2638 points
Perch Support

I think the closest we have to a LIKE is the regexp match option, which enables you to give a regular expression as the value.

https://dev.mysql.com/doc/refman/5.0/en/regexp.html

Thank you, it works for me, and also using regex can bypass the blog's bug. Here come another issue: why doen't this multiple filters work for blog?

perch_blog_custom(array(
    'count' => 999,
    'template' => 'output-post-list.html',
    'sort' => 'postDateTime',
    'sort-order' => 'DESC',
    'filter'=>array(
        array(
            'filter'=>'postTitle',
            'match' => 'regex',
            'value' => $_POST['search']
        ),
        array(
            'filter'=>'postDescHTML',
            'match' => 'regex',
            'value' => $_POST['search']
        ),
    ),
    'match'=>'or'
));

It returns no error. The debug code indicates that it completely ignores the multiple filters

Similar code works on perch_content_custom()

Drew McLellan

Drew McLellan 2638 points
Perch Support

Multiple filters are coming in the next update.