Example #1
0
 public function save($type)
 {
     $db = Zend_Registry::get('db');
     $config = Zend_Registry::get('config');
     $mapper = new SxModule_Sheets_Subtype_Mapper();
     $typeData = $mapper->toArray($this, 'item');
     $typeTsl = $mapper->toArray($this, 'tsl');
     $typeData['type'] = $type;
     if ($this->getId() == 0) {
         $db->insert('SheetsSubtype', $typeData);
         $type_id = $db->lastInsertId();
         $typeTsl = array('subtype_id' => $type_id, 'name' => $this->getName());
         foreach ($config->system->language as $lng => $slng) {
             $typeTsl['subtype_id'] = $type_id;
             $typeTsl['lng'] = $lng;
             $db->insert('SheetsSubtypeTsl', $typeTsl);
         }
     } else {
         $type_id = $this->getId();
         $db->update('SheetsSubtype', $typeData, 'subtype_id = ' . $type_id);
         $typeTsl = array('subtype_id' => $type_id, 'name' => $this->getName());
         $db->update('SheetsSubtypeTsl', $typeTsl, 'subtype_id = ' . $typeTsl['subtype_id'] . ' AND lng = \'' . $this->getLng() . '\'');
     }
     return $this;
 }
 public function editAction()
 {
     SxCms_Acl::requireAcl('sheets', 'sheets.edit');
     $proxy = new SxModule_Sheets_Type_Proxy();
     $type = $proxy->getTypeById((int) $this->_getParam('type'), $_SESSION['System']['lng']);
     $this->view->type = $type;
     $proxy = new SxModule_Sheets_Subtype_Proxy();
     $subtype = $proxy->getTypeById((int) $this->_getParam('id'), $_SESSION['System']['lng']);
     if ($this->getRequest()->isPost()) {
         $mapper = new SxModule_Sheets_Subtype_Mapper();
         $fields = $mapper->fromInput($this->_getAllParams(), $this->_editablefields());
         $data = $mapper->toObject($fields, $subtype);
         $validator = new SxModule_Sheets_Subtype_Validator();
         if ($validator->validate($data)) {
             $data->save((int) $this->_getParam('type'));
             $cache = Zend_Registry::get('cache');
             $cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, array('SxModule_Sheets_Subtype'));
             $flashMessenger = $this->_helper->getHelper('FlashMessenger');
             $flashMessenger->addMessage($this->admin_tmx->_('itemedited'));
             $this->_helper->redirector->gotoSimple('index', 'sheets_subtype', 'admin', array('type' => $this->_getParam('type')));
         }
         $subtype = $data;
     }
     $this->view->messages = Sanmax_MessageStack::getInstance('SxModule_Sheets_Subtype');
     $this->view->subtype = $subtype;
 }