DataAccess/mysql/TicketComment.php

Go to the documentation of this file.
00001 <?php
00003 // {{{ license
00004 
00005 // +----------------------------------------------------------------------+
00006 // | FastFrame Application Framework                                      |
00007 // +----------------------------------------------------------------------+
00008 // | Copyright (c) 2002-2006 The Codejanitor Group                        |
00009 // +----------------------------------------------------------------------+
00010 // | This source file is subject to the GNU Lesser Public License (LGPL), |
00011 // | that is bundled with this package in the file LICENSE, and is        |
00012 // | available at through the world-wide-web at                           |
00013 // | http://www.fsf.org/copyleft/lesser.html                              |
00014 // | If you did not receive a copy of the LGPL and are unable to          |
00015 // | obtain it through the world-wide-web, you can get it by writing the  |
00016 // | Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
00017 // | MA 02111-1307, USA.                                                  |
00018 // +----------------------------------------------------------------------+
00019 // | Authors: Jason Rust <jrust@codejanitor.com>                          |
00020 // +----------------------------------------------------------------------+
00021 
00022 // }}}
00023 // {{{ requires
00024 
00025 require_once FASTFRAME_ROOT . 'lib/FastFrame/DataAccess.php';
00026 
00027 // }}}
00028 // {{{ class FF_DataAccess_TicketComment_mysql 
00029 
00040 // }}}
00041 class FF_DataAccess_TicketComment_mysql extends FF_DataAccess {
00042     // {{{ properties
00043 
00048     var $notificationTable;
00049 
00050     // }}}
00051     // {{{ constructor
00052 
00059     function FF_DataAccess_TicketComment_mysql()
00060     {
00061         FF_DataAccess::FF_DataAccess();
00062         $this->table = $this->o_registry->getConfigParam('data/ticket_comments_table');
00063         $this->notificationTable = $this->o_registry->getConfigParam('data/ticket_comment_notification_table');
00064     }
00065 
00066     // }}}
00067     // {{{ update()
00068 
00077     function update($in_data)
00078     {
00079         unset($in_data['create_date']);
00080         unset($in_data['creator_id']);
00081         $o_result = parent::update($in_data);
00082         if ($o_result->isSuccess()) {
00083             $o_ticketDao =& FF_DataAccess::factory('Ticket');
00084             $o_ticketDao->updateFullText($in_data['ticket_id']);
00085             $o_ticketDao->updateCommentTime($in_data['ticket_id']);
00086         }
00087 
00088         return $o_result;
00089     }
00090 
00091     // }}}
00092     // {{{ add()
00093 
00102     function add($in_data)
00103     {
00104         $in_data['create_date'] = $this->timestampToISODate(time());
00105         $o_result = parent::add($in_data);
00106         if ($o_result->isSuccess()) {
00107             $o_ticketDao =& FF_DataAccess::factory('Ticket');
00108             $o_ticketDao->updateFullText($in_data['ticket_id']);
00109             $o_ticketDao->updateCommentTime($in_data['ticket_id']);
00110         }
00111 
00112         return $o_result;
00113     }
00114 
00115     // }}}
00116     // {{{ remove()
00117 
00128     function remove($in_value, $in_field = null)
00129     {
00130         $s_query = "SELECT ticket_id FROM $this->table WHERE id = ?";
00131         $s_ticketId = $this->o_data->getOne($s_query, $in_value);
00132         $o_result =& parent::remove($in_value, $in_field);
00133         if (!is_null($s_ticketId) && $o_result->isSuccess()) {
00134             $o_ticketDao =& FF_DataAccess::factory('Ticket');
00135             $o_ticketDao->updateFullText($s_ticketId);
00136         }
00137 
00138         return $o_result;
00139     }
00140 
00141     // }}}
00142     // {{{ markRead()
00143 
00153     function markRead($in_id, $in_userId)
00154     { 
00155         if (empty($in_id)) {
00156             return;
00157         }
00158 
00159         // FIXME: Could probably be done more efficiently.
00160         $s_stmt = $this->o_data->prepare("DELETE FROM $this->notificationTable WHERE ticket_id = ? AND profile_id = ?");
00161         $this->o_data->execute($s_stmt, array($in_id, $in_userId));
00162         $this->o_data->autoExecute($this->notificationTable, array('ticket_id' => $in_id, 'profile_id' => $in_userId));
00163     }
00164 
00165     // }}}
00166     // {{{ getDataByPrimaryKey()
00167 
00177     function getDataByPrimaryKey($in_id, $in_fields = '*')
00178     {
00179         return parent::getDataByPrimaryKey($in_id, $this->_getSelectFields());
00180     }
00181 
00182     // }}}
00183     // {{{ getCommentsByTicketId()
00184 
00194     function getCommentsByTicketId($in_ticketId, $in_mostRecent)
00195     {
00196         $s_query = "SELECT " . $this->_getSelectFields() . " FROM $this->table 
00197                     WHERE ticket_id = ? ";
00198         if ($in_mostRecent) {
00199             $s_query .= 'ORDER BY create_date DESC LIMIT 1';
00200         }
00201         else {
00202             $s_query .= 'ORDER BY create_date ASC';
00203         }
00204 
00205         if (DB::isError($result = $this->o_data->getAll($s_query, array($in_ticketId)))) {
00206             return array();
00207         }
00208         else {
00209             return $result;
00210         }
00211     }
00212 
00213     // }}}
00214     // {{{ getNextId()
00215 
00222     function getNextId()
00223     {
00224         // change sequence name since we give it the full table name
00225         $this->o_data->setOption('seqname_format', '%s');
00226         return $this->o_data->nextId($this->o_registry->getConfigParam('data/sequence_table'));
00227     }
00228 
00229     // }}}
00230     // {{{ _getSelectFields()
00231 
00239     function _getSelectFields()
00240     {
00241         return 'id, ticket_id, is_private, UNIX_TIMESTAMP(create_date) AS create_date, comment, creator_id'; 
00242     }
00243 
00244     // }}}
00245 }
00246 ?>

Generated on Fri Jun 23 11:38:18 2006 for FastFrame by  doxygen 1.4.4