예제 #1
0
 /**
  * Persist all the data to the datastore
  *
  * @param boolean $actual TRUE when referring to actual ORM, FALSE when referring to ConfigItem (default to TRUE)
  * @return boolean
  */
 public function persist($actual = true)
 {
     if ($actual) {
         $this->_table = $this->_name;
         parent::persist();
         return true;
     }
     $defaultTableName = $this->_defaultFormularyName;
     if ($defaultTableName == null) {
         $defaultTableName = self::getDefaultFormularyTable();
     }
     $db = Zend_Registry::get('dbAdapter');
     if ($this->_persistMode == WebVista_Model_ORM::DELETE) {
         $queries = array();
         $queries[] = "DROP TABLE {$this->_name}";
         $queries[] = "DELETE FROM {$this->_config->_table} WHERE configId='{$this->_name}'";
         $db->query(implode(';' . PHP_EOL, $queries));
     } else {
         // create new table based on default table
         $tableName = $this->_name;
         if (!self::isTableExists($tableName)) {
             $sql = 'CREATE TABLE ' . $tableName . ' LIKE ' . $defaultTableName;
             $sql .= '; INSERT INTO ' . $tableName . ' SELECT * FROM ' . $defaultTableName;
             trigger_error($sql, E_USER_NOTICE);
             $db->query($sql);
         }
         $this->_config->configId = $this->_name;
         $this->_config->value = serialize($this);
         $this->_config->setPersistMode($this->_persistMode);
         $this->_config->persist();
     }
     if ($this->_isDefaultSet) {
         // backup configId and value
         $configId = $this->_config->configId;
         $value = $this->_config->value;
         $this->_config->configId = $defaultTableName;
         $this->_config->populate();
         $formularyItem = unserialize($this->_config->value);
         if ($formularyItem !== false && $formularyItem instanceof self && $formularyItem->getName() != $this->getName()) {
             // unset the default
             $formularyItem->unsetDefault();
             $formularyItem->persist(false);
         }
         // set the default formulary table name to this table name
         $this->_config->configId = self::DEFAULTFORMULARYID;
         $this->_config->value = $this->_name;
         $this->_config->persist();
         // restore the previous data for configId and value
         $this->_config->configId = $configId;
         $this->_config->value = $value;
     }
     // temporarily return true, this might change later if needed
     return true;
 }
    public function processMenuReloadAction()
    {
        // clear cache
        $cache = Zend_Registry::get('cache');
        $cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array('tagMenu'));
        // check cache config
        $objConfig = new ConfigItem();
        $objConfig->configId = 'enableCache';
        $objConfig->populate();
        if (!$objConfig->value > 0) {
            $objConfig->value = 1;
            $objConfig->persist();
        }
        $data = true;
        $basePath = Zend_Registry::get('basePath');
        $jsActionFile = $basePath . '/js/menuActions.js';
        if (file_exists($jsActionFile) && !is_writable($jsActionFile) && chmod($basePath . '/js', 0777) === false) {
            $data = __('menuActions.js file is not writable');
        } else {
            $menuActions = '';
            $mainMenu = array();
            $menuItems = MenuItem::getMenuItems();
            foreach ($menuItems as $menu) {
                $idName = preg_replace('/\\ |[^A-Za-z]/', '_', strtolower($menu['title']));
                $mainMenu["{$menu['siteSection']}_{$idName}"] = $menu['jsAction'];
            }
            $menuActions .= <<<EOL
function onMainMenuItemSelected(itemId,itemValue) {
\tswitch (itemId) {
EOL;
            foreach ($mainMenu as $key => $value) {
                $menuActions .= <<<EOL

\t\tcase "{$key}":
\t\t\t{$value}
\t\t\tbreak;
EOL;
            }
            $menuActions .= <<<EOL

\t}
}
EOL;
            copy($jsActionFile, $jsActionFile . '.bak');
            file_put_contents($jsActionFile, $menuActions);
        }
        $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
        $json->suppressExit = true;
        $json->direct($data);
    }
 /**
  * Clear/Enable/Disable Cache
  */
 public function ajaxChangeCacheSettingsAction()
 {
     $cacheMode = $this->_getParam('cacheMode');
     $msg = '';
     switch (strtolower($cacheMode)) {
         case 'clear':
             $cache = Zend_Registry::get('cache');
             $cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array('tagMenu'));
             $msg = __("Successfully cleared cache menu");
             break;
         case 'enable':
         case 'disable':
             $objConfig = new ConfigItem();
             $objConfig->configId = 'enableCache';
             $objConfig->populate();
             $objConfig->value = $cacheMode == 'enable' ? 1 : 0;
             $objConfig->persist();
             $msg = __("Successfully {$cacheMode} cache menu");
             break;
         default:
             $msg = __("Invalid action");
     }
     $data = array('msg' => $msg);
     $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
     $json->suppressExit = true;
     $json->direct($data);
 }