This is the API documentation for concrete5 version 5.6 and earlier. View Current API Documentation
  1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 
<?php

defined('C5_EXECUTE') or die("Access Denied.");

/**
 * @package Pages
 * @category Concrete
 * @author Andrew Embler <[email protected]>
 * @copyright  Copyright (c) 2003-2008 Concrete5. (http://www.concrete5.org)
 * @license    http://www.concrete5.org/license/     MIT License
 *
 */

/**
 * PageStatistics functions as a name space containing functions that return page-level statistics.
 *
 * @package Pages
 * @author Andrew Embler <[email protected]>
 * @category Concrete
 * @copyright  Copyright (c) 2003-2008 Concrete5. (http://www.concrete5.org)
 * @license    http://www.concrete5.org/license/     MIT License
 *
 */

class Concrete5_Model_PageStatistics {
    
    /**
     * Gets total page views across the entire site. 
     * @param date $date
     * @return int
     */
    public static function getTotalPageViews($date = null) {
        $db = Loader::db();
        if ($date != null) {
            return $db->GetOne("select count(pstID) from PageStatistics where date = ?", array($date));
        } else {
            return $db->GetOne("select count(pstID) from PageStatistics");
        }
    }

    /**
     * Gets total page views for everyone but the passed user object
     * @param User $u
     * @param date $date
     * @return int
     */
    public static function getTotalPageViewsForOthers($u, $date = null) {
        $db = Loader::db();
        if ($date != null) {
            $v = array($u->getUserID(), $date);
            return $db->GetOne("select count(pstID) from PageStatistics where uID <> ? and date = ?", $v);
        } else {
            $v = array($u->getUserID());
            return $db->GetOne("select count(pstID) from PageStatistics where uID <> ?", $v);
        }
    }

    /**
     * Gets the total number of versions across all pages. Used in the dashboard.
     * @todo It might be nice if this were a little more generalized
     * @return int
     */
    public static function getTotalPageVersions() {
        $db = Loader::db();
        return $db->GetOne("select count(cvID) from CollectionVersions");
    }
    
    /**
     * Returns the datetime of the last edit to the site. Used in the dashboard
     * @return datetime
     */
    public static function getSiteLastEdit($type = 'system') {
        $db = Loader::db();
        $cDateModified = $db->GetOne("select max(Collections.cDateModified) from Collections");
        if(ENABLE_USER_TIMEZONES && $type == 'user') {
            $dh = Loader::helper('date');
            return $dh->getLocalDateTime($cDateModified);
        } else {
            return $cDateModified;
        }
    }
    
    /**
     * Gets the total number of pages currently in edit mode
     * @return int
     */
    public static function getTotalPagesCheckedOut() {
        $db = Loader::db();
        return $db->GetOne("select count(cID) from Pages where cIsCheckedOut = 1");
    }
    
    
    /** 
     * For a particular page ID, grabs all the pages of this page, and increments the cTotalChildren number for them
     */
    public static function incrementParents($cID) {
        $db = Loader::db();
        $cParentID = $db->GetOne("select cParentID from Pages where cID = ?", array($cID));

        $q = "update Pages set cChildren = cChildren+1 where cID = ?";

        $cpc = Page::getByID($cParentID);
        $cpc->refreshCache();

        $r = $db->query($q, array($cParentID));

    }

    /** 
     * For a particular page ID, grabs all the pages of this page, and decrements the cTotalChildren number for them
     */
    public static function decrementParents($cID) {
        $db = Loader::db();
        $cParentID = $db->GetOne("select cParentID from Pages where cID = ?", array($cID));
        $cChildren = $db->GetOne("select cChildren from Pages where cID = ?", array($cParentID));
        $cChildren--;
        if ($cChildren < 0) {
            $cChildren = 0;
        }

        $q = "update Pages set cChildren = ? where cID = ?";
        
        $cpc = Page::getByID($cParentID);
        $cpc->refreshCache();
        
        $r = $db->query($q, array($cChildren, $cParentID));

    }
    
    /** 
     * Returns the total number of pages created for a given date 
     */
    public static function getTotalPagesCreated($date) {
        $db = Loader::db(); 
        $num = $db->GetOne('select count(Pages.cID) from Pages inner join Collections on Pages.cID = Collections.cID where cDateAdded >= ? and cDateAdded <= ? and cIsSystemPage = 0 and cIsTemplate = 0', array($date . ' 00:00:00', $date . ' 23:59:59'));
        return $num;
    }
}