Example #1
0
 /**
  * This function performs the validation work for complex object models.
  *
  * In addition to checking the current object, all related objects will
  * also be validated.  If all pass then <code>true</code> is returned; otherwise
  * an aggreagated array of ValidationFailed objects will be returned.
  *
  * @param      array $columns Array of column names to validate.
  * @return     mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise.
  */
 protected function doValidate($columns = null)
 {
     if (!$this->alreadyInValidation) {
         $this->alreadyInValidation = true;
         $retval = null;
         $failureMap = array();
         // We call the validate method on the following object(s) if they
         // were passed to this object by their coresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->asfGuardUser !== null) {
             if (!$this->asfGuardUser->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->asfGuardUser->getValidationFailures());
             }
         }
         if ($this->aConfig !== null) {
             if (!$this->aConfig->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aConfig->getValidationFailures());
             }
         }
         if (($retval = AdsPeer::doValidate($this, $columns)) !== true) {
             $failureMap = array_merge($failureMap, $retval);
         }
         $this->alreadyInValidation = false;
     }
     return !empty($failureMap) ? $failureMap : true;
 }
Example #2
0
 public function __construct(array $config)
 {
     Config::validate($config, ['name' => Config::STRING | Config::REQUIRED, 'fields' => Config::arrayOf(['name' => Config::STRING | Config::REQUIRED, 'type' => Config::INPUT_TYPE | Config::REQUIRED, 'defaultValue' => Config::ANY, 'description' => Config::STRING], Config::KEY_AS_NAME), 'description' => Config::STRING]);
     if (!empty($config['fields'])) {
         foreach ($config['fields'] as $name => $field) {
             $this->_fields[$name] = new InputObjectField($field + ['name' => $name]);
         }
     }
     $this->name = $config['name'];
     $this->description = isset($config['description']) ? $config['description'] : null;
 }
Example #3
0
 /**
  * Edit|save config
  * @param $key
  * @param $default
  * @param $type
  * @param $label
  * @return bool
  */
 public static function edit($key, $default, $type, $label)
 {
     $conf = self::model()->findByAttributes(array('key' => $key));
     if (!$conf) {
         $conf = new Config();
         $conf->key = $key;
     }
     $conf->default = self::formatValue($default, $type, true);
     $conf->type = $type;
     $conf->label = $label;
     if ($conf->validate()) {
         return $conf->save();
     }
     return false;
 }
Example #4
0
 /**
  * Метод добавление строки в таблицу config
  * @param string $alias псевдоним настройки
  * @return boolen TRUE - настройка успешно добавлена
  */
 public function insertData($alias)
 {
     $model = new Config();
     $model->alias = $alias;
     $model->is_done = (int) FALSE;
     if ($model->validate()) {
         $model->save();
     }
     return TRUE;
 }
Example #5
0
 /**
  * Updates a system param.
  * If update is successful, the browser will be redirected to the 'index' page.
  */
 public function actionUpdate($id)
 {
     if (!Yii::app()->user->checkAccess('updateSystemParam')) {
         throw new CHttpException(403, Yii::t('http_status', '403'));
     }
     $params = (include $file = Yii::app()->basePath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'params.php');
     $model = new Config();
     $params_list = array();
     if (array_key_exists($id, $params)) {
         $model->attributes = array('param_name' => $id, 'param_value' => $params[$id]);
     } else {
         while (list($key, $value) = each($params)) {
             if (is_array($value)) {
                 if (array_key_exists($id, $value)) {
                     $model->attributes = array('param_name' => $id, 'param_value' => $value[$id]);
                 }
                 array_push($params_list, $key);
             }
         }
     }
     if (isset($_POST['Config'])) {
         $model->attributes = $_POST['Config'];
         if (is_numeric($model->param_value)) {
             $model->param_value = (int) $model->param_value;
         }
         if ($model->validate()) {
             if (empty($_POST['param_parent'])) {
                 $params[$model->param_name] = $model->param_value;
             } else {
                 $params[$_POST['param_parent']][$model->param_name] = $model->param_value;
             }
             try {
                 copy(Yii::app()->basePath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'params.php', Yii::app()->basePath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'params_old.php');
                 $file = fopen($file = Yii::app()->basePath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'params.php', 'w');
                 fwrite($file, "<?php\n\r return ");
                 fwrite($file, var_export($params, TRUE));
                 fwrite($file, ";\n\r ?>");
                 fclose($file);
                 Yii::app()->user->setFlash('success', 'The update of the system param has been performed successfully.');
                 $this->redirect(array('index'));
             } catch (Exception $e) {
                 Yii::app()->user->setFlash('error', 'Editing of the system param failed. Please, try again.');
             }
         }
     }
     $this->render('update', array('model' => $model, 'params_list' => $params_list));
 }
        break;
    }
}
$conf = new Config();
if ($force_conf_silent) {
    $conf->silent = true;
}
if ($config_filename == '') {
    fprintf(STDERR, "Warning:No config file found... using default values!%s", PHP_EOL);
} else {
    $config_filename = realpath($config_filename);
    if (!$conf->silent) {
        fprintf(STDERR, "Info:\tUsing [%s] Config File...%s", $config_filename, PHP_EOL);
    }
    require_once $config_filename;
    $conf->validate();
    if ($force_conf_silent) {
        $conf->silent = true;
    }
}
//var_dump($conf);
$pos = array_search('-y', $t_args);
if (isset($pos) && $pos !== false) {
    $conf->confirm = false;
    array_splice($t_args, $pos, 1);
    // remove the arg and reorder
}
$pos = array_search('--default-link-name', $t_args);
if (isset($pos) && $pos !== false && isset($t_args[$pos + 1])) {
    $conf->default_link_name = str_replace('$', '', $t_args[$pos + 1]);
    // in the case where the user wrongly prepends a $ sign to the variable name.
Example #7
0
 /**
  * @param array|Config $field
  * @return FieldDefinition
  */
 public static function create($field)
 {
     Config::validate($field, self::getDefinition());
     return new self($field);
 }
                if (move_course_folder($currentFolder, $newFolder) === false) {
                    $moved_courses .= '<li>' . sprintf('Error: Cannot rename "%s" to "%s"', $currentFolder, $newFolder) . '</li>' . "\n";
                } else {
                    $moved_courses .= '<li>' . sprintf('Course repository "%s" moved to "%s"', $currentFolder, $newFolder) . '</li>' . "\n";
                }
            }
        }
        $restored_courses .= '</ol>' . "\n";
        $moved_courses .= '</ol>' . "\n";
    }
    // TODO if course move succeed, update the value in configuration
    if ($_REQUEST['cmd'] == 'exMove' && ($error = false)) {
        $_GLOBALS['coursesRepositoryAppend'] = 'courses/';
        $config = new Config('CLMAIN');
        $config->load();
        $config->validate(array('coursesRepositoryAppend' => 'courses/'));
        $config->save();
    }
}
// Display Header
echo upgrade_disp_header();
echo claro_html_tool_title($nameTools);
// display result
if (isset($restored_courses)) {
    echo $restored_courses;
}
if (isset($moved_courses)) {
    echo $moved_courses;
}
// display link to launch the restore
if (get_path('coursesRepositoryAppend') != 'courses/') {