How to display ^ca_objects._count in a static page?

edited June 2020 in Pawtucket Help

Hello,
In my About page, I would like to add some general statistics about my collections, such as counts of objects, places, entities, representations, occurrences...
I tried to add {{{^ca_objects._count}}} (and so on) but unsuccessfully...
Any idea?
Thanks!

Comments

  • We don't support those values as display template values. If you'd like that feature added, consider creating a ticket for it at https://collectiveaccess.atlassian.net

  • edited June 2020

    Done! Thank you.

  • Hi!

    Finally, I found a way to get some statistics, by using un little script that extract informations directly from database, writing a line in a file somewhere, and include this file in a static page.

    For those who are interested by this, here is my way:

    1. Create a script somewhere in your home like /to_your_path/log/stat.php that contains:

    <?php
    $connection = new mysqli("127.0.0.1","my_login","my_password") or die("Connection to server failed.");
    $connection->select_db("my_database");
    if ($connection->connect_error) {
    die('Connection to database failed: ' . $connection->connect_error);
    }
    
    // Get the number of resources that are not deleted
    $req = "SELECT * FROM `ca_entities` WHERE `deleted`=0";
    $res = $connection->query($req) or die("Request 1 failed.");
    $num_entities = $res->num_rows;
    $res->close();
    
    $req = "SELECT * FROM `ca_objects` WHERE `deleted`=0 ";
    $res = $connection->query($req) or die("Request 2 failed.");
    $num_objects = $res->num_rows;
    $res->close();
    
    $req = "SELECT * FROM `ca_occurrences` WHERE `deleted`=0";
    $res = $connection->query($req) or die("Request 3 failed.");
    $num_occurrences = $res->num_rows;
    $res->close();
    
    $req = "SELECT * FROM `ca_places` WHERE `deleted`=0";
    $res = $connection->query($req) or die("Request 4 failed.");
    $num_places = $res->num_rows;
    $res->close();
    
    $req = "SELECT * FROM `ca_object_representations` WHERE `deleted`=0";
    $res = $connection->query($req) or die("Request 5 failed.");
    $num_object_representations = $res->num_rows;
    $res->close();
    
    $req = "SELECT * FROM `ca_collections` WHERE `deleted`=0";
    $res = $connection->query($req) or die("Request 6 failed.");
    $num_collections = $res->num_rows;
    $res->close();
    
    $file = fopen("/var/www/to_your_path/log/stat.log", "w");
    $text = "The database contains: <b>$num_objects</b> objects, <b>$num_entities</b> entities, <b>$num_places</b> places, <b>$num_occurrences</b> events, <b>$num_collections</b> collections, <b>$num_object_representations</b> representations. (".date('d\/m\/Y').")<br>";
    fwrite($file,$text);
    fclose($file);
    ?>
    


    2. Call this script whith crontab:

    sudo crontab -e

    then insert these lines:

    # Launch to update the stat.log file every hour

    00 */1 * * * php /to_your_path/log/stat.php

    and save.


    3. Insert a call of the file stat.log in the static page you want. For example About/index.php:

          <p><?php readfile("/var/www/to_your_path/log/stat.log") ?></p>
    


    Hope this will help! ;-)

Sign In or Register to comment.