/** * @param array $options * @param bool $fromCreate * * @throws DreamFactory\Platform\Exceptions\BadRequestException */ public function actionUpdate($options = array(), $fromCreate = false) { $_id = $_schema = $_errors = null; // New provider if (false !== $fromCreate && null !== ($_resourceId = FilterInput::request('resource'))) { // New request $_model = ResourceStore::model($_resourceId); $_displayName = Inflector::display($_resourceId); $_schema = $this->_loadConfigSchema($_resourceId, $_model->hasAttribute('config_text') ? $_model->config_text : array()); } else { // Requests will come in like: /admin/update/<resource>/<id> list($_resourceId, $_id) = $this->_parseRequest(); $_displayName = Inflector::display($_resourceId); // Load it up. /** @var $_model BasePlatformSystemModel */ if (null !== ($_model = ResourceStore::model($_resourceId)->findByPk($_id))) { $_schema = $this->_loadConfigSchema($_resourceId, $_model->hasAttribute('config_text') ? $_model->config_text : array()); if (Pii::postRequest()) { // On a post, update if (null === ($_data = Option::get($_POST, $_displayName))) { throw new BadRequestException('No payload received.'); } /** @var Provider $_model */ if ($_model->hasAttribute('config_text')) { $_len = strlen(static::SCHEMA_PREFIX); $_config = Option::clean($_model->config_text); foreach ($_data as $_key => $_value) { if (static::SCHEMA_PREFIX == substr($_key, 0, $_len)) { $_newKey = str_replace(static::SCHEMA_PREFIX, null, $_key); if (isset($_config[$_newKey])) { $_config[$_newKey] = $_value; } unset($_data[$_key]); } } $_model->config_text = $_config; unset($_data['config_text']); } $_model->setAttributes($_data); $_model->save(); Pii::setState('status_message', 'Resource Updated Successfully'); $this->redirect('/admin/' . $_resourceId . '/update/' . $_id); } } if ($_model->hasAttribute('name')) { $_displayName = $_model->name; } else { if ($_model->hasAttribute('provider_name')) { $_displayName = $_model->provider_name; } else { if ($_model->hasAttribute('api_name')) { $_displayName = $_model->api_name; } } } } $this->render('update', array('model' => $_model, 'schema' => $_schema, 'errors' => $_errors, 'resourceName' => $_resourceId, 'displayName' => $_displayName, 'update' => null !== $_id)); }
/** * First-time Welcome page */ public function actionWelcome() { // User cool too? if (null === ($_user = ResourceStore::model('user')->findByPk(Session::getCurrentUserId()))) { throw new ForbiddenException(); } /** * If request contains a "force_remove=1" parameter, * remove the registration file and redirect */ if ('1' == FilterInput::get(INPUT_GET, 'force_remove', 0)) { Log::debug('Forced removal of registration marker requested.'); SystemManager::registerPlatform($_user, false, true); $this->redirect($this->_getRedirectUrl()); } $_model = new SupportForm(); // collect user input data if (isset($_POST, $_POST['SupportForm'])) { $_model->setAttributes($_POST['SupportForm']); // Validate user input and redirect to the previous page if valid if ($_model->validate()) { try { SystemManager::registerPlatform($_user, $_model->getSkipped()); $this->redirect($this->_getRedirectUrl()); return; } catch (\Exception $_ex) { $_model->addError(null, $_ex->getMessage()); } } $_model->addError('Problem', 'Registration System Unavailable'); } $this->render('welcome', array('model' => $_model)); }
$_apps = $_providers = null; $_providerCache = new \stdClass(); $_models = ResourceStore::model('app')->findAll(array('select' => 'id, api_name, name', 'order' => 'name')); if (!empty($_models)) { /** @var App[] $_models */ foreach ($_models as $_model) { $_attributes = array('value' => $_model->api_name, 'name' => $_model->api_name); if (APPLICATION_NAME == $_model->api_name) { $_attributes['selected'] = 'selected'; } $_apps .= HtmlMarkup::tag('option', $_attributes, $_model->name); unset($_model); } unset($_models); } $_models = ResourceStore::model('provider')->findAll(array('select' => 'id, provider_name, api_name', 'order' => 'provider_name')); if (!empty($_models)) { $_first = true; /** @var Provider[] $_models */ foreach ($_models as $_model) { $_attributes = array('name' => $_model->api_name, 'value' => $_model->api_name, 'data-provider-id' => $_model->id, 'data-provider-tag' => Inflector::neutralize($_model->provider_name) . ':' . $_model->api_name, 'data-profile-resource' => strtolower($_model->provider_name) == 'facebook' ? '/me' : '/user'); if ($_first) { $_attributes['selected'] = 'selected'; $_first = false; } $_providers .= HtmlMarkup::tag('option', $_attributes, $_model->api_name . ' (' . Inflector::display($_model->provider_name) . ')'); $_providerCache->{$_model->api_name} = $_model->getAttributes(); unset($_model, $_config, $_attributes, $_profileResource); } unset($_models); }