* adjust the setting model.

This commit is contained in:
wangchunsheng
2012-06-27 15:09:26 +00:00
parent 2f1565b882
commit e0cee94adf
4 changed files with 85 additions and 137 deletions
+19 -24
View File
@@ -18,25 +18,20 @@ class admin extends control
*/
public function index()
{
$user = $this->loadModel('setting')->getItem('system', 'global', 'community');
if($user != '' and $user != 'na')
{
$this->view->bind = true;
$this->view->account = $user;
}
else
{
$this->view->bind = false;
$this->view->account = '';
}
if($this->loadModel('setting')->getItem('system', 'global', 'community') != '')
{
$this->view->ignore = true;
}
else
{
$this->view->ignore = false;
}
$community = $this->loadModel('setting')->getItem('system', 'common', 'global', 'community');
if(!$community or $community == 'na')
{
$this->view->bind = false;
$this->view->account = false;
$this->view->ignore = $community == 'na';
}
else
{
$this->view->bind = true;
$this->view->account = $community;
$this->view->ignore = false;
}
$this->app->loadLang('misc');
$this->display();
}
@@ -49,7 +44,7 @@ class admin extends control
*/
public function ignore()
{
$this->loadModel('setting')->setItem('system', 'global', 'community', 'na');
$this->loadModel('setting')->setItem('system', 'common', 'global', 'community', 'na');
die(js::locate(inlink('index'), 'parent'));
}
@@ -66,14 +61,14 @@ class admin extends control
$response = $this->admin->registerByAPI();
if($response == 'success')
{
$this->loadModel('setting')->setItem('system', 'global', 'community', $this->post->account);
$this->loadModel('setting')->setItem('system', 'common', 'global', 'community', $this->post->account);
echo js::alert($this->lang->admin->register->success);
die(js::locate(inlink('index'), 'parent'));
}
die($response);
}
$this->view->register = $this->admin->getRegisterInfo();
$this->view->sn = $this->loadModel('setting')->getItem('system', 'global', 'sn');
$this->view->sn = $this->loadModel('setting')->getItem('system', 'common', 'global', 'sn');
$this->display();
}
@@ -90,13 +85,13 @@ class admin extends control
$response = $this->admin->bindByAPI();
if($response == 'success')
{
$this->loadModel('setting')->setItem('system', 'global', 'community', $this->post->account);
$this->loadModel('setting')->setItem('system', 'common', 'global', 'community', $this->post->account);
echo js::alert($this->lang->admin->bind->success);
die(js::locate(inlink('index'), 'parent'));
}
die($response);
}
$this->view->sn = $this->loadModel('setting')->getItem('system', 'global', 'sn');
$this->view->sn = $this->loadModel('setting')->getItem('system', 'common', 'global', 'sn');
$this->display();
}
+1 -1
View File
@@ -47,7 +47,7 @@
<td colspan="2">
<?php
echo html::submitButton($lang->admin->register->submit) . html::hidden('sn', $sn);
echo "<span class='red strong'>" . sprintf($lang->admin->register->bind, html::a(inlink('bind'), $lang->admin->register->click)) . "</span>";
echo "<span>" . sprintf($lang->admin->register->bind, html::a(inlink('bind'), $lang->admin->register->click)) . "</span>";
?>
</td>
</th>
+64 -111
View File
@@ -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);
}
}
+1 -1
View File
@@ -422,7 +422,7 @@ class user extends control
$header['title'] = $this->lang->user->login;
$this->view->header = $header;
$this->view->referer = $this->referer;
$this->view->s = $this->loadModel('setting')->getItem('system', 'global', 'sn');
$this->view->s = $this->loadModel('setting')->getItem('system', 'common', 'global', 'sn');
$this->view->keepLogin = $this->cookie->keepLogin ? $this->cookie->keepLogin : 'off';
$this->display();
}