Collection Tree - Item Count and Description

I'd like to add an item count and description for my collections to the collection tree page (http://icfa.doaks.org/collections/artamonoff/collection-tree). Is anyone familiar with the plugin and could you let me know how to go about this?

This can probably be done by modifying the code in the linkToCollectionShow() method in CollectionTreePlugin.php

Changing what's there to this (or something similar) might do the trick -- haven't tried it myself yet.

// Require the helpers libraries. This is necessary when calling this
        // method before the libraries are loaded.
        require_once HELPERS;
        $collection = get_db()->getTable('Collection')->find($collectionId);
        set_current_collection($collection);
        $html = link_to_collection();
        $html .= "<p>Description: " . collection('description') . "</p>";
        $html .= "<p>Total Items: " . total_items_in_collection() . "</p>";
        return $html;

Patrick - could you point out what line the code needing this change is?

The original code is something like this, starting about line 334 in CollectionTreePlugin.php

public static function linkToCollectionShow($collectionId)
    {
        // Require the helpers libraries. This is necessary when calling this
        // method before the libraries are loaded.
        require_once HELPERS;
        return link_to_collection(null, array(), 'show',
                                  get_db()->getTable('Collection')->find($collectionId));
    }

What it returns is a little bit of HTML with a link to the collection.

My suggestion above builds up a little more HTML before returning it.

Thanks Patrick!
That worked pretty well - I made a few edits but still have a few issues. There is extra padding being added on top for the second level (children) collections. I suspect that is a issue somewhere in my css? But I can't find it.

And is there anyway to only show 'Description: _____" for those collections that do have text in their descriptions?

See the page here: http://icfa.doaks.org/collections/artamonoff/collection-tree

Code edits:

// Require the helpers libraries. This is necessary when calling this
        // method before the libraries are loaded.
        require_once HELPERS;
        $collection = get_db()->getTable('Collection')->find($collectionId);
        set_current_collection($collection);
        $html = link_to_collection();
        $html .= "<li><h5>Description: " . collection('description') . "</h5></li>";
        $html .= "<li><h5>" . multicollections_total_items_in_collection() . " photograph(s).</h5></li>";
        return $html;

I _think_ this will work to check for whether there is a description, replacing the line that adds the description above.

$description = collection('description');
if($description != '') {
    $html .= "<li><h5>Description: $description</h5></li>";
}

Again, big thanks Patrick! One last thing (this is probably easy, but is escaping me) - is their any way to make only the parent collections bold?

my guess would be to pick and choose which <h#> elements you want, and set a font-weight:bold CSS value on it. Not sure if there are better CSS approaches to that, though

I wonder what could we do to make this work in version 2.0.1. Is this code valid for the new version of CollectionTreePlugin.php?

I ask this because in my SERVER/collection-tree page I get Collections and sub-collections in proper order but there is no bullets indentation between them, as it happens in the admin panel .../collections/show/xx (number) page.

Following up, this is what I've had before version 2.0:

http://www.weebly.com/uploads/7/6/8/3/7683554/problem_collection_tree.jpg

Now, I have to get back the sums as well as the unordered list (bullets).

Ok, unordered list problem had to do with the style.css. Once I used the 2.0.1 file, Collection Tree worked... But I would still like some help with the code above.

The various functions for displaying metadata for items, collections, etc. are now consolidated into one function called metadata().

Something like this should get the description:

$description = metadata('collection', array('Dublin Core', 'Description'));

Thanks Patrick but my problem is the item count. How can I get the item count back in the Tree? (check screenshot above).

You can get the item count with metadata too:

metadata('collection', 'total items');

Could you possibly direct me to the exact line of code to be changed? The two versions of CollectionTreePlugin.php (old and new) seem completely different into my eyes so I can hardly understand now what affects what in the new code. In the previous version, I added the following code:

require_once HELPERS;
$collection = get_db()->getTable('Collection')->find($collectionId);
set_current_collection($collection);
$html = link_to_collection();
$html .= " (" . total_items_in_collection() . ")";
return $html;

to get this effect:

http://www.weebly.com/uploads/7/6/8/3/7683554/problem_collection_tree.jpg

Where should I look in the new version to achieve the same result?

I was also interested in adding an item count for my collections on the 2.0 collection tree page. After looking at this post, I implemented the following solution:

Edit the public function collectionTreeList($collectionTree, $linkToCollectionShow = true) within the file views/helpers/CollectionTreeList.php

if ($linkToCollectionShow && !isset($collection['current'])) {
$html .= link_to_collection(null, array(), 'show', $collectionTable->find($collection['id']));
$thiscollection = get_record_by_id('Collection', $collection['id']);
$html .= " (". metadata($thiscollection, 'total_items').")";
}

Hope this helps.