* adjust the setting model.
This commit is contained in:
+64
-111
@@ -13,21 +13,6 @@
|
||||
<?php
|
||||
class settingModel extends model
|
||||
{
|
||||
/**
|
||||
* Get the version of current zentaopms.
|
||||
*
|
||||
* Since the version field not saved in db. So if empty, return 0.3 beta.
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function getVersion()
|
||||
{
|
||||
$version = $this->getItem('system', 'common', 'global', 'version');
|
||||
if($version == '3.0.stable') $version = '3.0'; // convert 3.0.stable to 3.0.
|
||||
if($version) return $version;
|
||||
return '0.3 beta';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get config of system and one user.
|
||||
*
|
||||
@@ -55,61 +40,30 @@ class settingModel extends model
|
||||
}
|
||||
|
||||
/**
|
||||
* Get value of an item.
|
||||
* Get the version of current zentaopms.
|
||||
*
|
||||
* @param string $owner
|
||||
* @param string $module
|
||||
* @param string $section
|
||||
* @param string $key
|
||||
* @access public
|
||||
* @return misc
|
||||
*/
|
||||
public function getItem($owner, $module, $section, $key)
|
||||
{
|
||||
return $this->dao->select('`value`')->from(TABLE_CONFIG)
|
||||
->where('company')->eq(0)
|
||||
->andWhere('owner')->eq($owner)
|
||||
->andWhere('module')->eq($module)
|
||||
->andWhere('section')->eq($section)
|
||||
->andWhere('`key`')->eq($key)
|
||||
->fetch('value', $autoCompany = false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set value of an item.
|
||||
*
|
||||
* @param string $owner
|
||||
* @param string $module
|
||||
* @param string $section
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
* Since the version field not saved in db. So if empty, return 0.3 beta.
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function setItem($owner, $module, $section, $key, $value = '')
|
||||
public function getVersion()
|
||||
{
|
||||
$item->company = 0;
|
||||
$item->owner = $owner;
|
||||
$item->module = $module;
|
||||
$item->section = $section;
|
||||
$item->key = $key;
|
||||
$item->value = $value;
|
||||
$version = $this->getItem('system', 'common', 'global', 'version', 0);
|
||||
if($version == '3.0.stable') $version = '3.0'; // convert 3.0.stable to 3.0.
|
||||
if($version) return $version;
|
||||
return '0.3 beta';
|
||||
}
|
||||
|
||||
$config = $this->dao->select('`value`')->from(TABLE_CONFIG)
|
||||
->where('company')->eq(0)
|
||||
->andWhere('owner')->eq($owner)
|
||||
->andWhere('module')->eq($module)
|
||||
->andWhere('section')->eq($section)
|
||||
->andWhere('`key`')->eq($key)
|
||||
->fetch('', $autoComapny = false);
|
||||
if(!$config)
|
||||
{
|
||||
$this->dao->insert(TABLE_CONFIG)->data($item)->exec($autoCompany = false);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->dao->update(TABLE_CONFIG)->data($item)->where('id')->eq($config->id)->exec($autoCompany = false);
|
||||
}
|
||||
/**
|
||||
* Update version
|
||||
*
|
||||
* @param string $version
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function updateVersion($version)
|
||||
{
|
||||
$this->setItem('system', 'common', 'global', 'version', $version, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -135,63 +89,62 @@ class settingModel extends model
|
||||
*/
|
||||
public function setSN()
|
||||
{
|
||||
$item->company = 0;
|
||||
$item->owner = 'system';
|
||||
$item->module = 'common';
|
||||
$item->section = 'global';
|
||||
$item->key = 'sn';
|
||||
$item->value = $this->computeSN();
|
||||
|
||||
$config = $this->dao->select('id, value')->from(TABLE_CONFIG)
|
||||
->where('company')->eq(0)
|
||||
->andWhere('owner')->eq('system')
|
||||
->andWhere('module')->eq('common')
|
||||
->andWhere('section')->eq('global')
|
||||
->andWhere('`key`')->eq('sn')
|
||||
->fetch('', $autoComapny = false);
|
||||
if(!$config)
|
||||
$sn = $this->getItem('system', 'common', 'global', 'sn', 0);
|
||||
if(!$sn) return false;
|
||||
if($sn->value == '281602d8ff5ee7533eeafd26eda4e776' or
|
||||
$sn->value == '9bed3108092c94a0db2b934a46268b4a' or
|
||||
$sn->value == '8522dd4d76762a49d02261ddbe4ad432' or
|
||||
$sn->value == '13593e340ee2bdffed640d0c4eed8bec')
|
||||
{
|
||||
$this->dao->insert(TABLE_CONFIG)->data($item)->exec($autoCompany = false);
|
||||
}
|
||||
elseif($config->value == '281602d8ff5ee7533eeafd26eda4e776' or
|
||||
$config->value == '9bed3108092c94a0db2b934a46268b4a' or
|
||||
$config->value == '8522dd4d76762a49d02261ddbe4ad432' or
|
||||
$config->value == '13593e340ee2bdffed640d0c4eed8bec')
|
||||
{
|
||||
$this->dao->update(TABLE_CONFIG)->data($item)->where('id')->eq($config->id)->exec($autoCompany = false);
|
||||
$sn->value = $this->computeSN();
|
||||
$this->dao->replace(TABLE_CONFIG)->data($sn)->exec($autoCompany = false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update version
|
||||
* Get value of an item.
|
||||
*
|
||||
* @param string $version
|
||||
* @param string $owner
|
||||
* @param string $module
|
||||
* @param string $section
|
||||
* @param string $key
|
||||
* @param string|int $company
|
||||
* @access public
|
||||
* @return misc
|
||||
*/
|
||||
public function getItem($owner, $module, $section, $key, $company = 'current')
|
||||
{
|
||||
if($company === 'current') $company = $this->app->company->id;
|
||||
return $this->dao->select('`value`')->from(TABLE_CONFIG)
|
||||
->where('company')->eq($company)
|
||||
->andWhere('owner')->eq($owner)
|
||||
->andWhere('module')->eq($module)
|
||||
->andWhere('section')->eq($section)
|
||||
->andWhere('`key`')->eq($key)
|
||||
->fetch('value', $autoCompany = false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set value of an item.
|
||||
*
|
||||
* @param string $owner
|
||||
* @param string $module
|
||||
* @param string $section
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
* @param string|int $company
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function updateVersion($version)
|
||||
public function setItem($owner, $module, $section, $key, $value = '', $company = 'current')
|
||||
{
|
||||
$item->company = 0;
|
||||
$item->owner = 'system';
|
||||
$item->module = 'common';
|
||||
$item->section = 'global';
|
||||
$item->key = 'version';
|
||||
$item->value = $version;
|
||||
$item->company = $company === 'current' ? $this->app->company->id : $company;
|
||||
$item->owner = $owner;
|
||||
$item->module = $module;
|
||||
$item->section = $section;
|
||||
$item->key = $key;
|
||||
$item->value = $value;
|
||||
|
||||
$configID = $this->dao->select('id')->from(TABLE_CONFIG)
|
||||
->where('company')->eq(0)
|
||||
->andWhere('owner')->eq('system')
|
||||
->andWhere('module')->eq('common')
|
||||
->andWhere('section')->eq('global')
|
||||
->andWhere('`key`')->eq('version')
|
||||
->fetch('id', $autoComapny = false);
|
||||
if($configID > 0)
|
||||
{
|
||||
$this->dao->update(TABLE_CONFIG)->data($item)->where('id')->eq($configID)->exec($autoCompany = false);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->dao->insert(TABLE_CONFIG)->data($item)->exec($autoCompany = false);
|
||||
}
|
||||
$this->dao->replace(TABLE_CONFIG)->data($item)->exec($autoCompany = false);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user