本文整理汇总了PHP中Configuration::model方法的典型用法代码示例。如果您正苦于以下问题:PHP Configuration::model方法的具体用法?PHP Configuration::model怎么用?PHP Configuration::model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Configuration
的用法示例。
在下文中一共展示了Configuration::model方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionAdd
/**
* Creates a new Dashboard card with the $id dashboard_card_{ID_HERE}
* $id is a randomly generated hash based upon the unique data of the card.json + name, and contains 2 key pieces of information
* 1) The class name
* 2) The path in.dot.format
*
* Once created, the unique instance is added to the user's specific dashboard. This is an Ajax specific request
* @param string $id The unique id of the card as defined on creation of said card type
* @return bool
*/
public function actionAdd($id)
{
if ($id == NULL) {
throw new CHttpException(400, Yii::t('Dashboard.main', 'An ID must be specified'));
}
$config = Configuration::model()->findByAttributes(array('key' => $id));
if ($config == NULL) {
throw new CHttpException(400, Yii::t('Dashboard.main', 'No card type exists with that ID'));
}
$name = CJSON::decode($config->value);
Yii::import($name['path'] . '.*');
$card = new $name['class']();
$card->create($id, $name['path']);
$data = CJSON::decode($card->getJSON($name['path']));
$data['id'] = $card->id;
// Update the user's card information
$meta = UserMetadata::model()->findByAttributes(array('user_id' => Yii::app()->user->id, 'key' => 'dashboard'));
if ($meta == NULL) {
$meta = new UserMetadata();
$meta->key = 'dashboard';
$meta->user_id = Yii::app()->user->id;
$meta->value = array();
}
if (!is_array($meta->value)) {
$order = CJSON::decode($meta->value);
} else {
$order = $meta->value;
}
$order[] = $card->id;
$meta->value = CJSON::encode($order);
$meta->save();
return $card->render();
}
示例2: loadModel
/**
* Returns the data model based on the primary key given in the GET variable.
* If the data model is not found, an HTTP exception will be raised.
* @param integer $id the ID of the model to be loaded
* @return Configuration the loaded model
* @throws CHttpException
*/
public function loadModel($id)
{
$model = Configuration::model()->findByPk($id);
if ($model === null) {
throw new CHttpException(404, 'The requested page does not exist.');
}
return $model;
}
示例3: loadByKey
/**
* Bypasses our [param] file and loads key directly from database.
*
* Necessary for the NextOrderID as well
* as LSKEY Soap calls
*
* @param string $strKey Key name.
*
* @return bool|CActiveRecord
*/
public static function loadByKey($strKey)
{
$obj = Configuration::model()->findByAttributes(array('key_name' => $strKey));
if ($obj) {
return $obj;
}
return false;
}
示例4: actionIndex
public function actionIndex()
{
$model = Configuration::model()->findByPk(1);
if (isset($_POST['Configuration'])) {
$model->attributes = $_POST['Configuration'];
if ($model->save()) {
$this->redirect(array('config/index'));
}
}
$this->render('index', array('model' => $model));
}
示例5: canUserBid
public function canUserBid($userId)
{
$config = CHtml::listData(Configuration::model()->findAll(array('select' => 'name, value')), 'name', 'value');
$criteria = new CDbCriteria();
$criteria->condition = "fk_user = {$userId} AND DATE(created_at) = CURDATE() ";
$bidCount = $this->count($criteria);
if (isset($config['max_bid_count']) && $bidCount >= $config['max_bid_count']) {
return false;
} elseif ($bidCount >= self::DEFAULT_MAX_BID_COUNT) {
return false;
}
return true;
}
示例6: initParams
public static function initParams()
{
defined('DEFAULT_THEME') or define('DEFAULT_THEME', 'brooklyn2014');
$params = CHtml::listData(Configuration::model()->findAll(), 'key_name', 'key_value');
foreach ($params as $key => $value) {
Yii::app()->params->add($key, $value);
}
if (isset(Yii::app()->params['THEME'])) {
Yii::app()->theme = Yii::app()->params['THEME'];
} else {
Yii::app()->theme = DEFAULT_THEME;
}
if (isset(Yii::app()->params['LANG_CODE'])) {
Yii::app()->language = Yii::app()->params['LANG_CODE'];
} else {
Yii::app()->language = "en";
}
Yii::app()->params->add('listPerPage', Yii::app()->params['PRODUCTS_PER_PAGE']);
//Based on logging setting, set log level dynamically and possibly turn on debug mode
switch (Yii::app()->params['DEBUG_LOGGING']) {
case 'info':
$logLevel = "error,warning,info";
break;
case 'trace':
$logLevel = "error,warning,info,trace";
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL', 3);
break;
case 'error':
default:
$logLevel = "error,warning";
break;
}
foreach (Yii::app()->getComponent('log')->routes as $route) {
$route->levels = $logLevel;
}
Yii::app()->setViewPath(Yii::getPathOfAlias('application') . "/views-cities");
Yii::app()->name = Yii::app()->params['STORE_NAME'];
if (Yii::app()->params['LIGHTSPEED_CLOUD'] == '-1') {
//We should never see this, this means our cloud cache file is bad
$strHostfile = realpath(dirname(__FILE__)) . '/../../../config/cloud/' . $_SERVER['HTTP_HOST'] . ".php";
@unlink($strHostfile);
Yii::app()->request->redirect(Yii::app()->createUrl('site/index'));
}
}
示例7: actionEdit
/**
* Short Description.
*
* @return void
*/
public function actionEdit()
{
$id = Yii::app()->getRequest()->getQuery('id');
$model = Configuration::model()->findAllByAttributes(array('configuration_type_id' => $id), array('order' => 'sort_order'));
if ($this->IsCloud) {
$model = $this->sanitizeEditModule($model, 'Cloud');
}
if ($this->IsMT) {
$model = $this->sanitizeEditModule($model, 'MT');
}
if ($this->isHosted) {
$model = $this->sanitizeEditModule($model, 'Hosted');
}
if (isset($_POST['Configuration'])) {
$valid = true;
foreach ($model as $i => $item) {
if (isset($_POST['Configuration'][$i])) {
$item->attributes = $_POST['Configuration'][$i];
}
if ($item->key_name == 'LANG_MENU' && $item->key_value == 1) {
$itemLanguages = $model[2];
$itemLanguages->attributes = $_POST['Configuration'][2];
if (empty($itemLanguages->key_value)) {
$valid = false;
}
}
if ($item->options == "INT") {
if ((int) $item->key_value) {
$valid = true;
} else {
$valid = false;
}
}
if ($item->options == "EMAIL") {
$valid = $this->validateEmail($item) && $valid;
} else {
$valid = $item->validate() && $valid;
}
if (!$valid) {
if ($item->options == 'EMAIL') {
Yii::app()->user->setFlash('error', $item->title . ' is not a valid email address');
} elseif ($item->key_name == 'LANG_MENU') {
Yii::app()->user->setFlash('error', 'Languages field cannot be empty when language menu is enabled');
} elseif ($item->options == "INT") {
Yii::app()->user->setFlash('error', $item->title . ': ' . 'Only numbers are allowed', true);
} else {
$err = $item->getErrors();
Yii::app()->user->setFlash('error', $item->title . ' -- ' . print_r($err['key_value'][0], true));
}
break;
}
}
if ($valid) {
foreach ($model as $i => $item) {
$item->attributes = $_POST['Configuration'][$i];
if ($item->options == "PASSWORD") {
$item->key_value = _xls_encrypt($item->key_value);
}
if ($item->save() === false) {
Yii::app()->user->setFlash('error', print_r($item->getErrors(), true));
} else {
Yii::app()->user->setFlash('success', Yii::t('admin', 'Configuration updated on {time}.', array('{time}' => date('d F, Y h:i:sa'))));
$item->postConfigurationChange();
}
if ($item->key_name == 'EMAIL_TEST' && $item->key_value == 1) {
$this->sendEmailTest();
}
}
}
}
foreach ($model as $i => $item) {
if ($item->options == 'BOOL') {
$this->registerOnOff($item->id, "Configuration_{$i}_key_value", $item->key_value);
}
if ($item->options == 'PASSWORD') {
$model[$i]->key_value = _xls_decrypt($model[$i]->key_value);
}
$model[$i]->title = Yii::t('admin', $item->title, array('{color}' => _xls_regionalize('color'), '{check}' => _xls_regionalize('check')));
$model[$i]->helper_text = Yii::t('admin', $item->helper_text, array('{color}' => _xls_regionalize('color'), '{check}' => _xls_regionalize('check')));
}
/*
* http://www.yiiframework.com/doc/api/1.1/CModel#generateAttributeLabel-detail
*
* Unless we define the label attribute in activeLabelEx htmlOptions in the view,
* the label will be generated when it calls CModel::generateAttributeLabel().
* This is a problem for the labels we want to display on pages like the Google Integration
* page that have labels which deliberately require dashes and camel-case formatting.
*/
$defineLabel = false;
switch (CPropertyValue::ensureInteger($id)) {
case 20:
// IntegrationController::GOOGLE = 20
$defineLabel = true;
break;
default:
//.........这里部分代码省略.........
示例8: loadDefaults
protected function loadDefaults($strTheme)
{
$arrKeys = array();
$objComponent = Yii::app()->getComponent('wstheme');
$model = $objComponent->getAdminModel($strTheme);
if ($model) {
$formname = $strTheme . "AdminForm";
$arrKeys = get_class_vars($formname);
$form = new $formname();
$themeVersion = $form->version;
} else {
//If we don't have a CForm definition, we have to go old school
//(that means look for config.xml for backwards compatibility)
$fnOptions = self::getConfigFile($strTheme);
if (file_exists($fnOptions)) {
$strXml = file_get_contents($fnOptions);
// Parse xml for response values
$oXML = new SimpleXMLElement($strXml);
if ($oXML->defaults) {
foreach ($oXML->defaults->{'configuration'} as $item) {
$keyname = (string) $item->key_name;
$keyvalue = (string) $item->key_value;
$arrKeys[$keyname] = $keyvalue;
}
}
$themeVersion = $oXML->version;
}
}
//Now we have an array of keys no matter which method
foreach ($arrKeys as $keyname => $keyvalue) {
$objKey = Configuration::model()->findByAttributes(array('key_name' => $keyname));
if ($objKey) {
_xls_set_conf($keyname, $keyvalue);
Configuration::model()->updateByPk($objKey->id, array('template_specific' => '1'));
}
}
return array($arrKeys, $themeVersion);
}
示例9: actionEdit
public function actionEdit()
{
$id = Yii::app()->getRequest()->getQuery('id');
$model = Configuration::model()->findAllByAttributes(array('configuration_type_id' => $id), array('order' => 'sort_order'));
if (isset($_POST['Configuration'])) {
$valid = true;
foreach ($model as $i => $item) {
if (isset($_POST['Configuration'][$i])) {
$item->attributes = $_POST['Configuration'][$i];
}
$valid = $item->validate() && $valid;
if (!$valid) {
$err = $item->getErrors();
Yii::app()->user->setFlash('error', $item->title . " -- " . print_r($err['key_value'][0], true));
break;
}
}
if ($valid) {
foreach ($model as $i => $item) {
$item->attributes = $_POST['Configuration'][$i];
if ($item->options == "PASSWORD") {
$item->key_value = _xls_encrypt($item->key_value);
}
if (!$item->save()) {
Yii::app()->user->setFlash('error', print_r($item->getErrors(), true));
} else {
$item->postConfigurationChange();
}
if ($item->key_name == 'EMAIL_TEST' && $item->key_value == 1) {
$this->sendEmailTest();
}
}
Yii::app()->user->setFlash('success', Yii::t('admin', 'Configuration updated on {time}.', array('{time}' => date("d F, Y h:i:sa"))));
}
}
foreach ($model as $i => $item) {
if ($item->key_name == "EMAIL_TEST") {
$item->key_value = 0;
}
if ($item->options == "BOOL") {
$this->registerOnOff($item->id, "Configuration_{$i}_key_value", $item->key_value);
}
if ($item->options == "PASSWORD") {
$model[$i]->key_value = _xls_decrypt($model[$i]->key_value);
}
$model[$i]->title = Yii::t('admin', $item->title, array('{color}' => _xls_regionalize('color'), '{check}' => _xls_regionalize('check')));
$model[$i]->helper_text = Yii::t('admin', $item->helper_text, array('{color}' => _xls_regionalize('color'), '{check}' => _xls_regionalize('check')));
}
$this->render('edit', array('model' => $model));
}
示例10: actionDeleteCard
/**
* Deletes a card and all associated files from the system
* @param string $id The id of the card we want to delete
* @return boolean If the card was deleted or not
*/
public function actionDeleteCard($id = NULL)
{
if ($id == NULL) {
throw new CHttpException(400, Yii::t('Dashboard.main', 'You must specify a card to delete'));
}
$card = Configuration::model()->findByAttributes(array('key' => $id));
if ($card == NULL) {
throw new CHttpException(400, Yii::t('Dashboard.main', 'There are no dashboard cards with that id'));
}
$card->value = CJSON::decode($card->value);
return $card->fullDelete($card->value['folderName']);
}
示例11: _xls_insert_conf
function _xls_insert_conf($key, $title, $value, $helperText, $configType, $options, $sortOrder = NULL, $templateSpecific = 0)
{
$conf = Configuration::LoadByKey($key);
if (!$conf) {
$conf = new Configuration();
}
$conf->key_name = $key;
$conf->title = $title;
$conf->key_value = $value;
$conf->helper_text = $helperText;
$conf->configuration_type_id = $configType;
$conf->options = $options;
$query = <<<EOS
\t\tSELECT IFNULL(MAX(sortOrder),0)+1
\t\tFROM xlsws_configuration
\t\tWHERE configuration_type_id = '{$configType}';
EOS;
if (!$sortOrder) {
$sortOrder = Configuration::model()->findBySql($query);
}
$conf->sort_order = $sortOrder;
$conf->template_specific = $templateSpecific;
$conf->created = new CDbExpression('NOW()');
$conf->modified = new CDbExpression('NOW()');
if (!$conf->save()) {
print_r($conf->getErrors());
}
}