예제 #1
0
 /**
  * Save layout
  * @param
  * @return
  */
 public function save()
 {
     $data = $this->toArray();
     $cache = Zend_Controller_Action_HelperBroker::getStaticHelper('Cache')->getManager()->getCache('database');
     $cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array('layouts'));
     $data['layout_type'] = self::CUSTOM;
     // If we are updating content then we may need to update the file too
     if (!empty($this->layout_content)) {
         // Get the layout info
         $layoutGateway = new Layouts_Model_LayoutGateway();
         $path = $layoutGateway->fetchLayoutPath($this->layout_type, $this->layout_module);
         $file = $path . $data['layout_filename'];
         // Rename the file if needed
         if ($data['layout_title'] != $data['layout_title_orig']) {
             $filename = $this->createFilename($data['layout_title_orig']);
             $origFile = $path . $filename;
             if (rename($origFile, $file) === false) {
                 throw new Exception('There was a problem renaming the layout.  Probably a permission issue.');
             }
         }
         // Write the new contents
         $layoutFile = fopen($file, 'w+');
         fwrite($layoutFile, $this->layout_content);
         fclose($layoutFile);
     }
     unset($data['layout_content']);
     unset($data['layout_title_orig']);
     unset($data['layout_filename']);
     // Save/Insert our data into the db
     if (!isset($data['layout_id'])) {
         $this->getDbTable()->insert($data);
     } else {
         $this->getDbTable()->update($data, array('layout_id = ?' => $data['layout_id']));
     }
 }