GroupFormSubmit.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 // | Authors: Greg Gilbert <ggilbert@codejanitor.com>                     |
00021 // +----------------------------------------------------------------------+
00022 
00023 // }}}
00024 // {{{ requires
00025 
00026 require_once FASTFRAME_ROOT . 'lib/FastFrame/Action/FormSubmit.php';
00027 
00028 // }}}
00029 // {{{ class FF_Action_FormSubmit_Group
00030 
00042 // }}}
00043 class FF_Action_FormSubmit_Group extends FF_Action_FormSubmit {
00044     // {{{ doMultiPageForm()
00045 
00053     function doMultiPageForm()
00054     {
00055         $s_nextActionId = ACTION_SELECT;
00056         if (FF_Request::getParam('selectCategory_x', 'p', false) !== false) {
00057             $s_nextModule = 'Category';
00058         }
00059         elseif (FF_Request::getParam('selectItem_x', 'p', false) !== false) {
00060             $s_nextModule = 'Item';
00061         }
00062         else {
00063             $s_nextActionId = false;
00064         }
00065 
00066         if ($s_nextActionId) {
00067             FF_Request::setParam('returnModel', $this->o_model->exportToArray(), 's');
00068             if ($this->currentActionId == ACTION_EDIT_SUBMIT) {
00069                 FF_Request::setParam('returnActionId', ACTION_EDIT, 's');
00070             }
00071             else {
00072                 FF_Request::setParam('returnActionId', ACTION_ADD, 's');
00073             }
00074 
00075             FF_Request::setParam('returnObjectId', $this->o_model->getId(), 's');
00076             FF_Request::setParam('returnModule', 'Group', 's');
00077             $this->o_nextAction->setNextActionId(ACTION_SELECT);
00078             $this->o_nextAction->setNextModuleId($s_nextModule);
00079             return true;
00080         } 
00081         else {
00082             return false;
00083         }
00084     }
00085 
00086     // }}}
00087     // {{{ fillModelWithSubmitData()
00088 
00095     function fillModelWithSubmitData()
00096     {
00097         $this->o_model->setId(FF_Request::getParam('objectId', 'p'));
00098         $this->o_model->setName(FF_Request::getParam('name', 'p'));
00099         $this->o_model->setDescription(FF_Request::getParam('description', 'p'));
00100         $this->o_model->setCategoryId(FF_Request::getParam('category_id', 'p'));
00101         $this->o_model->setStoreId(FF_Request::getParam('store_id', 'p'));
00102         $this->o_model->setShopperViewable(FF_Request::getParam('shopper_viewable', 'p'));
00103         $this->o_model->setIsKit(FF_Request::getParam('is_kit', 'p'));
00104         $this->o_model->setItemsByBarcode(FF_Request::getParam('newItems', 'p'));
00105         $this->o_model->setItemsToRemove(FF_Request::getParam('toRemove', 'p'));
00106         $this->o_model->setRules(FF_Request::getParam('rules', 'p'));
00107     }
00108 
00109     // }}}
00110     // {{{ save()
00111 
00118     function save()
00119     {
00120         $o_result =& $this->o_model->save($this->isUpdate());
00121         if ($o_result->isSuccess()) {
00122             $o_fileCache =& FF_FileCache::singleton();
00123             if (FF_Request::getParam('imageRemove', 'p', false)) {
00124                 FF_Request::setParam('imageRemove', null, 'p');
00125                 $o_fileCache->remove(array('subdir' => 'group_images', 'name' => $this->o_model->getId()), true);
00126             }
00127 
00128             $tmp_result =& $o_fileCache->saveUploadedFile(FF_Request::getParam('image', 'f'), 
00129                     array('subdir' => 'group_images', 'name' => $this->o_model->getId()),
00130                     $this->o_registry->getConfigParam('borrower/max_image_size'),
00131                     array('image/png', 'image/gif', 'image/jpeg', 'image/pjpeg'), true);
00132             if (!$tmp_result->isSuccess()) {
00133                 // Since it saved ok, it's just a warning
00134                 $o_result->addMessage($tmp_result->getMessages());
00135             }
00136 
00137             $o_fileCache->makeViewableFromWeb(array('subdir' => 'group_images', 'name' => $this->o_model->getId()), true);
00138         }
00139 
00140         return $o_result;
00141     }
00142 
00143     // }}}
00144     // {{{ validateInput()
00145 
00152     function validateInput()
00153     {
00154         require_once dirname(__FILE__) . '/../Validate/Group.php';
00155         $o_validate =& new FF_Validate_Group($this->o_model, $this->isUpdate());
00156         return $o_validate->validate();
00157     }
00158 
00159     // }}}
00160     // {{{ getSingularText()
00161 
00168     function getSingularText()
00169     {
00170         return _('group');
00171     }
00172 
00173     // }}}
00174     // {{{ setSuccessActionId()
00175 
00182     function setSuccessActionId()
00183     {
00184         $this->o_nextAction->setNextActionId(ACTION_GROUP_LIST);
00185         $this->o_nextAction->setNextModuleId('Item');
00186     }
00187 
00188     // }}}
00189     // {{{ checkPerms()
00190 
00197     function checkPerms()
00198     {
00199         switch ($this->currentActionId) {
00200             case ACTION_EDIT_SUBMIT:
00201                 if (($this->o_perms->hasPerm('can_edit_group'))) {
00202                     return true;
00203                 }
00204                 else {
00205                     $this->o_nextAction->setNextActionId(ACTION_PROBLEM);
00206                     $this->o_output->setMessage(_('You do not have permission to edit groups'), FASTFRAME_ERROR_MESSAGE);
00207                     return false;
00208                 }
00209             break;
00210             case ACTION_ADD_SUBMIT:
00211                 if (($this->o_perms->hasPerm('can_add_group'))) {
00212                     return true;
00213                 }
00214                 else {
00215                     $this->o_nextAction->setNextActionId(ACTION_PROBLEM);
00216                     $this->o_output->setMessage(_('You do not have permission to add groups'), FASTFRAME_ERROR_MESSAGE);
00217                     return false;
00218                 }
00219             break;
00220             default:
00221                 $this->o_nextAction->setNextActionId(ACTION_PROBLEM);
00222                 $this->o_output->setMessage(_('Could not determine the intended action'), FASTFRAME_ERROR_MESSAGE);
00223                 return false;
00224             break;
00225         }
00226     }
00227 
00228     // }}}
00229 }
00230 ?>

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