Files
EasySoft-ZenTaoPMS/module/custom/model.php
2013-08-06 17:09:23 +08:00

117 lines
3.5 KiB
PHP

<?php
/**
* The model file of xxx module of ZenTaoCMS.
*
* @copyright Copyright 2009-2010 QingDao Nature Easy Soft Network Technology Co,LTD (www.cnezsoft.com)
* @license LGPL (http://www.gnu.org/licenses/lgpl.html)
* @author Chunsheng Wang <chunsheng@cnezsoft.com>
* @package xxx
* @version $Id$
* @link http://www.zentao.net
*/
class customModel extends model
{
/**
* Get config of system and one user.
*
* @param string $account
* @access public
* @return array
*/
public function getAll()
{
return $this->dao->select('*')->from(TABLE_CUSTOM)->orderBy('id')->fetchAll('id');
}
/**
* Set value of an item.
*
* @param string $path system.common.global.sn or system.common.sn
* @param string $value
* @access public
* @return void
*/
public function setItem($path, $value = '')
{
$level = substr_count($path, '.');
$section = '';
if($level <= 1) return false;
if($level == 2) list($lang, $module, $key) = explode('.', $path);
if($level == 3) list($lang, $module, $section, $key) = explode('.', $path);
$item = new stdclass();
$item->lang = $lang;
$item->module = $module;
$item->section = $section;
$item->key = $key;
$item->value = $value;
$this->dao->replace(TABLE_CUSTOM)->data($item)->exec();
}
public function getStandardList($module, $field)
{
$this->loadModel($module);
$lang = $this->app->getClientLang();
$currentList = $this->lang->$module->$field;
$dbList = $this->getItems("{$lang}.{$module}.{$field}");
}
public function getItems($paramString)
{
return $this->createDAO($this->parseItemParam($paramString), 'select')->fetchAll('id');
}
/**
* Delete items.
*
* @param string $paramString see parseItemParam();
* @access public
* @return void
*/
public function deleteItems($paramString)
{
$this->createDAO($this->parseItemParam($paramString), 'delete')->exec();
}
/**
* Parse the param string for select or delete items.
*
* @param string $paramString owner=xxx&key=sn and so on.
* @access public
* @return array
*/
public function parseItemParam($paramString)
{
/* Parse the param string into array. */
parse_str($paramString, $params);
/* Init fields not set in the param string. */
$fields = 'lang,module,section,key';
$fields = explode(',', $fields);
foreach($fields as $field) if(!isset($params[$field])) $params[$field] = '';
return $params;
}
/**
* Create a DAO object to select or delete one or more records.
*
* @param array $params the params parsed by parseItemParam() method.
* @param string $method select|delete.
* @access public
* @return object
*/
public function createDAO($params, $method = 'select')
{
return $this->dao->$method('*')->from(TABLE_CUSTOM)->where('1 = 1')
->beginIF($params['lang'])->andWhere('lang')->in($params['lang'])->fi()
->beginIF($params['module'])->andWhere('module')->in($params['module'])->fi()
->beginIF($params['section'])->andWhere('section')->in($params['section'])->fi()
->beginIF($params['key'])->andWhere('`key`')->in($params['key'])->fi();
}
}