DataAccess/mysql/Catalog.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 // {{{ constants
00029 
00030 // The type constants
00031 define('FILTER_BY_CREATOR', 1);
00032 define('FILTER_BY_REP', 2);
00033 // Exported constants
00034 define('REQUEST_NOT_EXPORTED', 0);
00035 define('REQUEST_EXPORTED', 1);
00036 define('REQUEST_DOWNLOADED', 2);
00037 
00038 // }}}
00039 // {{{ class FF_DataAccess_Catalog_mysql 
00040 
00051 // }}}
00052 class FF_DataAccess_Catalog_mysql extends FF_DataAccess {
00053     // {{{ constructor
00054 
00061     function FF_DataAccess_Catalog_mysql()
00062     {
00063         FF_DataAccess::FF_DataAccess();
00064         $this->table = $this->o_registry->getConfigParam('data/table', 'catalog_requests');
00065     }
00066 
00067     // }}}
00068     // {{{ update()
00069 
00078     function update($in_data)
00079     {
00080         $in_data['appt_date_rep'] = $this->timestampToISODate($in_data['appt_date_rep']);
00081         $in_data['exported'] = REQUEST_NOT_EXPORTED;
00082         $in_data['deleted'] = false;
00083         unset($in_data['create_date']);
00084         unset($in_data['creator_id']);
00085         return parent::update($in_data);
00086     }
00087 
00088     // }}}
00089     // {{{ add()
00090 
00099     function add($in_data)
00100     {
00101         $in_data['creator_id'] = FF_Auth::getCredential('userId');
00102         $in_data['create_date'] = $this->timestampToISODate(time());
00103         $in_data['appt_date_rep'] = $this->timestampToISODate($in_data['appt_date_rep']);
00104         $in_data['exported'] = REQUEST_NOT_EXPORTED;
00105         return parent::add($in_data);
00106     }
00107 
00108     // }}}
00109     // {{{ remove()
00110 
00120     function remove($in_id, $in_exported = false)
00121     {
00122         $o_result = new FF_Result();
00123         if ($in_exported) { 
00124             $s_where = 'exported > ' . REQUEST_NOT_EXPORTED;
00125         }
00126         else { 
00127             $s_where = 'id=' . $this->o_data->quoteSmart($in_id);
00128         }
00129 
00130         $result = $this->o_data->autoExecute($this->table, array('deleted' => true), DB_AUTOQUERY_UPDATE, $s_where);
00131         if (DB::isError($result)) {
00132             $o_result->addMessage($result->getMessage());
00133             $o_result->setSuccess(false);
00134         }
00135 
00136         return $o_result;
00137     }
00138 
00139     // }}}
00140     // {{{ markAsExported()
00141 
00148     function markAsExported()
00149     {
00150         $o_result = new FF_Result();
00151         $result = $this->o_data->autoExecute($this->table, array('exported' => REQUEST_EXPORTED), DB_AUTOQUERY_UPDATE, 'exported=' . REQUEST_DOWNLOADED);
00152         if (PEAR::isError($result)) {
00153             $o_result->setSuccess(false);
00154             $o_result->addMessage($result->getMessage());
00155         }
00156 
00157         return $o_result;
00158     }
00159 
00160     // }}}
00161     // {{{ markAsDownloaded()
00162 
00169     function markAsDownloaded()
00170     {
00171         $o_result = new FF_Result();
00172         $result = $this->o_data->autoExecute($this->table, array('exported' => REQUEST_DOWNLOADED), DB_AUTOQUERY_UPDATE, 'exported=' . REQUEST_NOT_EXPORTED);
00173         if (PEAR::isError($result)) {
00174             $o_result->setSuccess(false);
00175             $o_result->addMessage($result->getMessage());
00176         }
00177 
00178         return $o_result;
00179     }
00180 
00181     // }}}
00182     // {{{ getDataByPrimaryKey()
00183 
00193     function getDataByPrimaryKey($in_id, $in_fields = '*')
00194     {
00195         return parent::getDataByPrimaryKey($in_id, $this->_getSelectFields());
00196     }
00197 
00198     // }}}
00199     // {{{ getDataToExport()
00200 
00208     function &getDataToExport()
00209     {
00210         $s_query = "SELECT name, address, city, state, zip, phone, mail_method, '3' AS weight, rep, country,
00211                     DATE_FORMAT(appt_date_rep, '%W') AS appt_day,
00212                     DATE_FORMAT(appt_date_rep, '%c/%e/%Y') AS appt_date,
00213                     DATE_FORMAT(appt_date_rep, '%l:%i %p') AS appt_time_rep,
00214                     DATE_FORMAT(appt_date_rep + INTERVAL canidate_time_offset HOUR_MINUTE, '%l:%i %p') AS appt_time_canidate,
00215                     program, special_requests
00216                     FROM $this->table 
00217                     WHERE deleted = 0 AND (exported = " . REQUEST_NOT_EXPORTED . " OR
00218                     exported = " . REQUEST_DOWNLOADED . ") ORDER BY country, mail_method, rep";
00219         return $this->o_data->query($s_query);
00220     }
00221 
00222     // }}}
00223     // {{{ getListData()
00224 
00236     function getListData($in_where, $in_orderByField, $in_orderByDir, $in_fields = '*')
00237     {
00238         return parent::getListData($in_where, $in_orderByField, $in_orderByDir, $this->_getSelectFields());
00239     }
00240 
00241     // }}}
00242     // {{{ getListFilter()
00243 
00256     function getListFilter($in_searchString, $in_searchFields, $in_filter, $in_filterData)
00257     {
00258         if ($in_filter == FILTER_BY_CREATOR) {
00259             $s_filter = 'creator_id = ' . $this->o_data->quoteSmart($in_filterData['userId']) . ' AND ';
00260         }
00261         elseif ($in_filter == FILTER_BY_REP) {
00262             if (!empty($in_filterData['repId'])) {
00263                 $s_filter = 'rep = ' . $this->o_data->quoteSmart($in_filterData['repId']) . ' AND ';
00264             }
00265             else {
00266                 $s_filter = '';
00267             }
00268         }
00269         else {
00270             $s_filter = 'deleted != 1 AND ';
00271         }
00272 
00273         $s_filter .= '(' . parent::getListFilter($in_searchString, $in_searchFields, $in_filter, $in_filterData) . ')';
00274         return $s_filter;
00275     }
00276 
00277     // }}}
00278     // {{{ getStats()
00279 
00289     function getStats($in_start, $in_end)
00290     {
00291         $a_stats = array();
00292         $in_start = $this->timestampToISODate($in_start);
00293         $in_end = $this->timestampToISODate($in_end);
00294         $s_query = "SELECT COUNT(*) FROM $this->table 
00295                     WHERE create_date > ? AND create_date < ?";
00296         $a_stats['total'] = $this->o_data->getOne($s_query, array($in_start, $in_end));
00297 
00298         $s_query = "SELECT mail_method,COUNT(mail_method) AS tmp_count
00299                     FROM $this->table 
00300                     WHERE create_date > ? AND create_date < ?
00301                     GROUP BY mail_method ORDER BY tmp_count DESC";
00302         $a_stats['count_by_mail_method'] = $this->o_data->getAssoc($s_query, false, array($in_start, $in_end));
00303 
00304         $s_profileTable = $this->o_registry->getConfigParam('data/table', 'profile', 'profile');
00305         $s_query = "SELECT CONCAT(firstname, ' ', lastname), COUNT(creator_id) AS tmp_count
00306                     FROM $this->table AS c
00307                     INNER JOIN $s_profileTable AS p ON c.creator_id=p.id
00308                     WHERE create_date > ? AND create_date < ?
00309                     GROUP BY creator_id ORDER BY tmp_count DESC";
00310         $a_stats['count_by_rep'] = $this->o_data->getAssoc($s_query, false, array($in_start, $in_end));
00311         return $a_stats;
00312     }
00313 
00314     // }}}
00315     // {{{ getRepOptions()
00316 
00317     function getRepOptions()
00318     {
00319         $s_table = $this->o_registry->getConfigParam('data/reps_table');
00320         return $this->o_data->getAssoc("SELECT rep, rep FROM $s_table ORDER BY rep");
00321     }
00322 
00323     // }}}
00324     // {{{ _getSelectFields()
00325 
00333     function _getSelectFields()
00334     {
00335         return 'id, name, address, city, state, zip, phone, country, UNIX_TIMESTAMP(appt_date_rep) AS appt_date_rep, canidate_time_offset, program, rep, mail_method, special_requests, exported, manager_approved, UNIX_TIMESTAMP(create_date) AS create_date';
00336     }
00337 
00338     // }}}
00339 }
00340 ?>

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