Model/MaydayProfile.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/Model.php';
00026 
00027 // }}}
00028 // {{{ constants
00029 
00030 define('SUMMARY_FILTER', 'FILTER');
00031 define('SUMMARY_CATEGORY', 'CATEGORY');
00032 
00033 // }}}
00034 // {{{ class FF_Model_MaydayProfile
00035 
00046 // }}}
00047 class FF_Model_MaydayProfile extends FF_Model {
00048     // {{{ properties
00049 
00054     var $summaryRefresh = 300;
00055 
00060     var $summaryPageViews = array();
00061 
00062     // }}}
00063     // {{{ reset()
00064 
00071     function reset()
00072     {
00073         $this->id = null;
00074         $this->summaryRefresh = 300;
00075         $this->summaryPageViews = array();
00076     }
00077 
00078     // }}}
00079     // {{{ save()
00080 
00090     function save($in_isUpdate, $in_newId)
00091     {
00092         if ($in_isUpdate) {
00093             return $this->o_dataAccess->update($this->exportToArray());
00094         }
00095         else {
00096             $this->setId($in_newId);
00097             return $this->o_dataAccess->add($this->exportToArray());
00098         }
00099     }
00100 
00101     // }}}
00102     // {{{ importFromArray()
00103 
00112     function importFromArray($in_data)
00113     {
00114         $this->setId($in_data['id']);
00115         $this->setSummaryRefresh($in_data['summary_refresh']);
00116         for ($i = 1; $i <= 8; $i++) {
00117             $this->setSummaryPageView($i, $in_data["summary_id_$i"], $in_data["summary_type_$i"], $in_data["summary_limit_$i"]);
00118         }
00119     }
00120 
00121     // }}}
00122     // {{{ exportToArray()
00123 
00132     function exportToArray()
00133     {
00134         $a_data = array();
00135         $a_data['id'] = $this->getId();
00136         $a_data['summary_refresh'] = $this->getSummaryRefresh();
00137         for ($i = 1; $i <= 8; $i++) {
00138             $a_summary = $this->getSummaryPageView($i);
00139             $a_data["summary_id_$i"] = $a_summary[0];
00140             $a_data["summary_type_$i"] = $a_summary[1];
00141             $a_data["summary_limit_$i"] = $this->getSummaryPageLimit($i);
00142         }
00143 
00144         return $a_data;
00145     }
00146 
00147     // }}}
00148     // {{{ createDefaultSummary()
00149 
00157     function createDefaultSummary()
00158     {
00159         $o_dao =& FF_DataAccess::factory('Status');
00160         $a_status = $o_dao->getStatusOptions(array('addResolution' => 1));
00161         $s_resolution = $o_dao->getResolutionStatus();
00162         unset($a_status[$s_resolution]);
00163         require_once dirname(__FILE__) . '/Filter.php';
00164         $o_filter =& new FF_Model_Filter();
00165         $o_filter->setOwnerId(FF_Auth::getCredential('userId'));
00166         $o_filter->setSortField('last_updated');
00167         $o_filter->setSortOrder(0);
00168         $o_filter->setName(_('My Open Requests'));
00169         $o_filter->setReporterOperator(1);
00170         $o_filter->setReporterType(TEXT_EQUALS);
00171         $o_filter->setReporter(FF_Auth::getCredential('username'));
00172         $o_filter->setStatuses(array_keys($a_status));
00173         $o_filter->save(false);
00174         $this->setSummaryPageView(1, $o_filter->getId(), SUMMARY_FILTER, 10);
00175         $o_filter->setName(_('My Resolved Requests'));
00176         $o_filter->setStatuses(array($s_resolution));
00177         $o_filter->save(false);
00178         $this->setSummaryPageView(5, $o_filter->getId(), SUMMARY_FILTER, 10);
00179         $this->save(!is_null($this->getId()), FF_Auth::getCredential('userId'));
00180     }
00181 
00182     // }}}
00183     // {{{ getSummaryRefreshOptions()
00184 
00185     function getSummaryRefreshOptions()
00186     {
00187         $a_options = array();
00188         $a_options[60] = _('1 minute');
00189         for ($i = 2; $i <= 5; $i++) {
00190             $a_options[$i * 60] = sprintf(_('%s minutes'), $i);
00191         }
00192 
00193         for ($i = 10; $i <= 60; $i += 5) {
00194             $a_options[$i * 60] = sprintf(_('%s minutes'), $i);
00195         }
00196 
00197         return $a_options;
00198     }
00199 
00200     // }}}
00201     // {{{ setSummaryRefresh()
00202 
00203     function setSummaryRefresh($in_value)
00204     {
00205         $this->summaryRefresh = $in_value;
00206     }
00207 
00208     // }}}
00209     // {{{ getSummaryRefresh()
00210 
00211     function getSummaryRefresh()
00212     {
00213         return $this->summaryRefresh;
00214     }
00215 
00216     // }}}
00217     // {{{ getSummaryPageViewOptions()
00218 
00227     function getSummaryPageViewOptions($in_ownerId)
00228     {
00229         $a_options[''] = '&nbsp;';
00230         if (!empty($in_ownerId)) {
00231             $o_dao =& FF_DataAccess::factory('Filter', 'mayday');
00232             $a_options += $this->_modifySummaryOptions($o_dao->getFilterOptions(array($in_ownerId)), SUMMARY_FILTER, _('Filter'));
00233         }
00234 
00235         $o_dao =& FF_DataAccess::factory('Category', 'mayday');
00236         $a_options += $this->_modifySummaryOptions($o_dao->getCategoryOptions(array('perm' => PERMS_READ)),
00237                 SUMMARY_CATEGORY, _('Category'));
00238         return $a_options;
00239     }
00240 
00241     // }}}
00242     // {{{ hasNoSummaryPageViews()
00243 
00250     function hasNoSummaryPageViews()
00251     {
00252         foreach ($this->summaryPageViews as $a_data) {
00253             if (!empty($a_data[0])) {
00254                 return false;
00255             }
00256         }
00257 
00258         return true;
00259     }
00260 
00261     // }}}
00262     // {{{ setSummaryPageView()
00263 
00276     function setSummaryPageView($in_id, $in_summaryId, $in_summaryType, $in_summaryLimit)
00277     {
00278         $this->summaryPageViews[$in_id] = array($in_summaryId, $in_summaryType, $in_summaryLimit);
00279     }
00280 
00281     // }}}
00282     // {{{ getSummaryPageView()
00283 
00295     function getSummaryPageView($in_id, $in_asString = false)
00296     {
00297         if ($in_asString) {
00298             return isset($this->summaryPageViews[$in_id]) ? 
00299                 $this->summaryPageViews[$in_id][1] . ':' . $this->summaryPageViews[$in_id][0] : '';
00300         }
00301         else {
00302             return isset($this->summaryPageViews[$in_id]) ? $this->summaryPageViews[$in_id] : array(0 => '', 1 => '');
00303         }
00304     }
00305 
00306     // }}}
00307     // {{{ getSummaryPageLimit()
00308 
00317     function getSummaryPageLimit($in_id)
00318     {
00319         return empty($this->summaryPageViews[$in_id][2]) ? 10 : $this->summaryPageViews[$in_id][2];
00320     }
00321 
00322     // }}}
00323     // {{{ _modifySummaryOptions()
00324 
00337     function _modifySummaryOptions($in_options, $in_type, $in_desc)
00338     {
00339         foreach ($in_options as $s_key => $s_val) {
00340             unset($in_options[$s_key]);
00341             $s_key = $in_type . ':' . $s_key;
00342             $in_options[$s_key] = $in_desc . ' - ' . $s_val;
00343         }
00344 
00345         return $in_options;
00346     }
00347 
00348     // }}}
00349     // {{{ _initDataAccess()
00350 
00357     function _initDataAccess()
00358     {
00359         $this->o_dataAccess =& FF_DataAccess::factory('MaydayProfile');
00360     }
00361 
00362     // }}}
00363 }
00364 ?>

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