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 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 
<?php
defined('C5_EXECUTE') or die("Access Denied.");
/**
 * An object for individual Guestbook responses.
 *
 * @package Blocks
 * @subpackage Guestbook
 * @author Ryan Tyler <[email protected]>
 * @author Andrew Embler <[email protected]>
 * @copyright  Copyright (c) 2003-2012 Concrete5. (http://www.concrete5.org)
 * @license    http://www.concrete5.org/license/     MIT License
 *
 */
    class Concrete5_Controller_Block_GuestbookEntry {
        /**
         * blocks bID
         * @var integer
        */
        public $bID;
        
        /**
         * page collectionID
         * @var integer
         */
        public $cID;
        
        /**
         * blocks uID user id
         * @var integer
        */
        public $uID;        
        
        /**
         * the entry id
         * @var integer
        */
        public $entryID;
        
        /**
         * the user's name
         * @var string
        */
        public $user_name;
        
        /**
         * the user's email address
         * @var string
        */
        public $user_email;
        
        /**
         * the text for the comment
         * @var string
        */
        public $commentText;
        
        function __construct($bID, $cID = NULL) {
            $this->bID = $bID;
            $this->cID = $cID;
        }
        
        /** 
         * Loads the object data from the db
         * @param integer $entryID
         * @return bool
        */
        function loadData($entryID) {
            $db = Loader::db();
            $data = $db->getRow("SELECT * FROM btGuestBookEntries WHERE entryID=? AND bID=?",array($entryID,$this->bID));
        
            $this->entryID      = $data['entryID'];
            $this->user_name    = $data['user_name'];
            $this->user_email   = $data['user_email'];
            $this->commentText  = $data['commentText'];
            $this->uID          = $data['uID'];
        }
        
        /** 
         * Adds an entry to the guestbook for the current block
         * @param string $comment
         * @param string $name
         * @param string $email
        */
        function addEntry($comment, $name, $email, $approved, $cID, $uID=0 ) {
            $txt = Loader::helper('text');
        
            $db = Loader::db();
            $query = "INSERT INTO btGuestBookEntries (bID, cID, uID, user_name, user_email, commentText, entryDate, approved) VALUES (?, ?, ?, ?, ?, ?, NOW(), ?)";
            $res = $db->query($query, array($this->bID, $cID, intval($uID), $txt->sanitize($name), $txt->sanitize($email), $txt->sanitize($comment), $approved) );

            $this->adjustCountCache(1);
        }

        /**
        * Adjusts cache of count bynumber specified, 
        *
        * Refreshes from db if cache is invalidated or
        * false is called in
        */      
        private function adjustCountCache($number=false){
            $ca     = new Cache();
            $db     = Loader::db();         
            $count = $ca->get('GuestBookCount',$this->cID."-".$this->bID);
            if($count && $number){
                $count += $number;              
            } else{
                $q = 'SELECT count(bID) as count
                FROM btGuestBookEntries
                WHERE bID = ?
                AND cID = ?
                AND approved=1';                
                $v = Array($this->bID, $this->cID);
                $rs = $db->query($q,$v);
                $row = $rs->FetchRow();
                $count = $row['count'];
            }
            $ca->set('GuestBookCount',$this->cID."-".$this->bID,$count);
        }
        
        /** 
         * Updates the given guestbook entry for the current block
         * @param integer $entryID
         * @param string $comment
         * @param string $name
         * @param string $email
         * @param string $uID
        */
        function updateEntry($entryID, $comment, $name, $email, $uID=0 ) {
            $db = Loader::db();
            $txt = Loader::helper('text');
            $query = "UPDATE btGuestBookEntries SET user_name=?, uID=?, user_email=?, commentText=? WHERE entryID=? AND bID=?";
            $res = $db->query($query, array($txt->sanitize($name), intval($uID), $txt->sanitize($email),$txt->sanitize($comment),$entryID,$this->bID));
        }
        
        /** 
         * Deletes the given guestbook entry for the current block
         * @param integer $entryID
        */
        function removeEntry($entryID) {
            $db = Loader::db();
            $query = "DELETE FROM btGuestBookEntries WHERE entryID=? AND bID=?";
            $res = $db->query($query, array($entryID,$this->bID));
            $this->adjustCountCache(-1);
        }
        
        function approveEntry($entryID) {
            $db = Loader::db();
            $query = "UPDATE btGuestBookEntries SET approved = 1 WHERE entryID=? AND bID=?";
            $res = $db->query($query, array($entryID,$this->bID));
            $this->adjustCountCache(1);
        }
    
        function unApproveEntry($entryID) {
            $db = Loader::db();
            $query = "UPDATE btGuestBookEntries SET approved = 0 WHERE entryID=? AND bID=?";
            $res = $db->query($query, array($entryID,$this->bID));
            $this->adjustCountCache(-1);
        }
        
        /** 
         * Deletes all the entries for the current block
        */
        function removeAllEntries($cID) {
            $db = Loader::db();
            $query = "DELETE FROM btGuestBookEntries WHERE bID=? AND cID = ?";
            $res = $db->query($query, array($this->bID, $cID)); 
            $this->adjustCountCache(false);
        }
        
        /** 
         * gets all entries for the current block
         * @param integer $bID
         * @param string $order ASC|DESC
         * @return array $rows  
        */
        public static function getAll($bID, $cID, $order="ASC") {
            $db = Loader::db();
            $query = "SELECT * FROM btGuestBookEntries WHERE bID = ? AND cID = ? ORDER BY entryDate {$order}"; 
            
            $rows = $db->getAll($query,array($bID,$cID));       
            
            return $rows;
        }
    
    } // end class def