00001 <?php
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 require_once FASTFRAME_ROOT . 'lib/FastFrame/DataAccess.php';
00026
00027
00028
00029
00040
00041 class FF_DataAccess_TicketComment_mysql extends FF_DataAccess {
00042
00043
00048 var $notificationTable;
00049
00050
00051
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
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
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
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
00143
00153 function markRead($in_id, $in_userId)
00154 {
00155 if (empty($in_id)) {
00156 return;
00157 }
00158
00159
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
00167
00177 function getDataByPrimaryKey($in_id, $in_fields = '*')
00178 {
00179 return parent::getDataByPrimaryKey($in_id, $this->_getSelectFields());
00180 }
00181
00182
00183
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
00215
00222 function getNextId()
00223 {
00224
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
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 ?>