Skip to content

Commit

Permalink
Merge pull request #206 from quantacms/aldo-dev
Browse files Browse the repository at this point in the history
Aldo dev
  • Loading branch information
Aldus83 committed Nov 20, 2018
2 parents d38b4f7 + 1ec24a1 commit 2b17bc7
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 43 deletions.
11 changes: 2 additions & 9 deletions engine/modules/core/form/Form.class.inc
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
<?php
/**
*
*/
define("FORM_METHOD_POST", 'post');
/**
*
*/
define("FORM_METHOD_GET", 'get');
/**
*
*/
define("FORM_PAGE_FORM", '___page_form___');
/**
* Class Form
Expand Down Expand Up @@ -92,6 +83,7 @@ class Form extends DataContainer {
$this->env->hook('form_submit', $vars);
$this->env->hook('form_type_' . $this->getType() . '_submit', $vars);
$this->env->hook($this->getId() . '_form_submit', $vars);
// If there are no errors, redirect OR show the OK message of the form.
if (empty($this->getRedirect())) {
return $this->getOkMessage();
}
Expand Down Expand Up @@ -350,6 +342,7 @@ class Form extends DataContainer {
$this->setMethod((isset($attributes['method'])) ? $attributes['method'] : FORM_METHOD_POST);
$this->setOkMessage((isset($attributes['ok_message'])) ? $attributes['ok_message'] : 'Your form has been submitted.');
$this->setAnchor((isset($attributes['anchor'])) ? $attributes['anchor'] : $this->getId());
$this->setRedirect((isset($attributes['redirect'])) ? $attributes['redirect'] : NULL);

}

Expand Down
2 changes: 1 addition & 1 deletion engine/modules/core/form/FormItem.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ abstract class FormItem extends DataContainer {

// Check all the form item's attributes.
$this->setName($this->getInputAttr('name'));
$this->setData('class', array('form-item'));
$this->setData('class', array('form-item form-item-' . $this->getType()));
$this->setData('title', !empty($this->getInputAttr('title')) ? $this->getInputAttr('title') : $this->getInputAttr('name'));
$this->setData('label', !empty($this->getInputAttr('label')) ? $this->getInputAttr('label') : NULL);
$this->setData('id', !empty($this->getInputAttr('id')) ? $this->getInputAttr('id') : ('input-' . $this->getInputAttr('name')));
Expand Down
65 changes: 64 additions & 1 deletion engine/modules/core/form/FormItemDate.class.inc
Original file line number Diff line number Diff line change
@@ -1,13 +1,76 @@
<?php
define('INPUT_DATE_NOW', 'NOW');
/**
* Class FormItemString
* This class represents a Form Item of type dropdown Select
*/
class FormItemDate extends FormItemString {
public $type = 'date';
public $format = 'Y-m-d';

function loadAttributes() {
$this->addData('class', array('hasDatePicker'));
parent::loadAttributes(); // TODO: Change the autogenerated stub
parent::loadAttributes();
if (!empty($this->getInputAttr('date_format'))) {
$this->format = $this->getInputAttr('date_format');
}
if (!empty($this->getInputAttr('date_min'))) {
$this->setData('min', $this->parseDate($this->getInputAttr('date_min'), 'Y-m-d'));
}
if (!empty($this->getInputAttr('date_max'))) {
$this->setData('max', $this->parseDate($this->getInputAttr('date_max'), 'Y-m-d'));
}
}

public function parseDate($date, $format = NULL) {
if (empty($format)) {
$format = $this->getDateFormat();
}
if ($date == INPUT_DATE_NOW) {
$time = time();
}
else {
$time = strtotime($date);
}
return date($format, $time);
}

public function getDateFormat() {
return $this->format;
}
/**
* @return string
*/
public function getHTMLType() {
return 'date';
}

/**
* Renders the input item.
* @return mixed
*/
function render() {
$rendered = '';
// TODO: data items should go in an array and be rendered all together
// in order to be extendable by subclasses...

$rendered .= '<input value="' . str_replace('"', '&#34;', $this->getCurrentValue()) . '" type="' . $this->getHTMLType() . '" ' .
($this->isDisabled() ? 'disabled ' : '') .
($this->isRequired() ? 'required ' : '') .
('class="' . $this->getClass() . '" ') .
('placeholder="' . $this->getPlaceHolder() . '" ') .
('name="' . $this->getName() . '" ') .
('id="' . $this->getId() . '" ') .
($this->isMultiple() ? 'data-multiple ' : ' ') .
($this->isDistinct() ? 'data-distinct ' : ' ') .
($this->isMultiple() ? 'data-limit="' . $this->getData('limit'). '" ' : ' ') .
(!empty($this->getInputAttr('node')) ? (' data-node="' . $this->getInputAttr('node')) . '" ' : '') .
(!empty($this->getData('min')) ? (' min="' . $this->getData('min')) . '" ' : '') .

(!empty($this->getData('max')) ? (' max="' . $this->getData('max')) . '" ' : '') .

'/>';

return $rendered;
}
}
4 changes: 2 additions & 2 deletions engine/modules/core/form/form.hook.inc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function form_load_includes($env, $vars) {

/**
* Implements hook_form_validate();
* Check that required fields are met, and other stuff.
* Check that required fields are met, and other standard validations.
*
* @param Environment $env
* The Environment.
Expand All @@ -41,7 +41,7 @@ function form_form_validate($env, $vars) {

/**
* Implements hook_boot().
* TODO: refactor the whole.
* TODO: This approach was made for fetching results for autocomplete fields. Refactor the whole.
*
* @param Environment $env
* The Environment.
Expand Down
6 changes: 2 additions & 4 deletions engine/modules/core/page/page.qtags.inc
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,7 @@ function qtag_JSON($env, $target, &$attributes) {
function qtag_HEADER($env, $target, &$attributes) {
$attributes['grid'] = 'grid' . (!empty($attributes['grid']) ? ' ' . $attributes['grid'] : '');
$attributes['grid_html_tag'] = 'header';
$attributes['grid_id'] = isset($attributes['header_id']) ? $attributes['header_id'] : '';


$target_header = isset($target) ? $target : 'header';

return qtag_CONTENT($env, $target_header, $attributes);
Expand All @@ -298,8 +297,7 @@ function qtag_HEADER($env, $target, &$attributes) {
function qtag_FOOTER($env, $target, &$attributes) {
$attributes['grid'] = 'grid' . (!empty($attributes['grid']) ? ' ' . $attributes['grid'] : '');
$attributes['grid_html_tag'] = 'footer';
$attributes['grid_id'] = isset($attributes['footer_id']) ? $attributes['footer_id'] : '';


$target_footer = isset($target) ? $target : 'footer';

return qtag_CONTENT($env, $target_footer, $attributes);
Expand Down
23 changes: 2 additions & 21 deletions engine/modules/core/user/User.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -352,31 +352,12 @@ class User extends Node {
$this->setData('password', $password);
}

/**
* @param $context
* @return bool|string
*/
public function renderEditForm($context) {
$user_edit_form = file_get_contents($this->env->getModulePath('user') . '/tpl/user_edit.inc');
return $user_edit_form;
}


/**
* Renders a Login form.
* TODO: refactor and move elsewhere.
*
* @return string
*/
public function renderLoginForm() {
$login_form = file_get_contents($this->env->getModulePath('user') . '/tpl/user_login.inc');
return $login_form;
}

/**
* Rebuild the User object in session, based on current user.
*/
public function rebuildSession() {
// TODO: always appropriate to set logged when rebuilding a session?
$this->roles += array('logged' => 'logged');
$_SESSION['user'] = $this->serializeForSession();
}

Expand Down
23 changes: 23 additions & 0 deletions engine/modules/core/user/UserFactory.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,27 @@ class UserFactory {
}
return $user;
}


/**
* Renders an user edit form
* @param $context
* @return bool|string
*/
public static function renderUserEditForm($env, $context) {
$user_edit_form = file_get_contents($env->getModulePath('user') . '/tpl/user_edit.inc');
return $user_edit_form;
}


/**
* Renders a Login form.
* TODO: refactor and move elsewhere.
*
* @return string
*/
public static function renderLoginForm($env) {
$login_form = file_get_contents($env->getModulePath('user') . '/tpl/user_login.inc');
return $login_form;
}
}
6 changes: 3 additions & 3 deletions engine/modules/core/user/user.hook.inc
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function user_action_login($env, $vars) {
*/
function user_shadow_user_register_form($env, $vars) {
$user = UserFactory::current($env);
$tab = '<h2>Create a free account</h2>' . $user->renderEditForm($env->getContext());
$tab = '<h2>Create a free account</h2>' . UserFactory::renderUserEditForm($env, $env->getContext());
$vars['shadow']->addTab('Insert your data', $tab, 1);
$vars['shadow']->addButton('edit-save', '<span style="color:green">&check;&nbsp;</span> Sign Up!');
}
Expand Down Expand Up @@ -182,7 +182,7 @@ function user_shadow_user_edit_form($env, $vars) {
break;
}

$tab = '<h2>' . $title . '</h2>' . $user->renderEditForm($env->getContext());
$tab = '<h2>' . $title . '</h2>' . UserFactory::renderUserEditForm($env, $env->getContext());
$shadow->addTab('Your Profile', $tab, 1);
$shadow->addButton('edit-save', '<span style="color:green">&check;&nbsp;</span> Update');
}
Expand All @@ -197,7 +197,7 @@ function user_shadow_user_edit_form($env, $vars) {
*/
function user_shadow_user_login_form($env, $vars) {
$user = UserFactory::current($env);
$tab = $user->renderLoginForm();
$tab = UserFactory::renderLoginForm($env);
/** @var Shadow $shadow */
$shadow = $vars['shadow'];
$shadow->addTab('Your Login Data', $tab, 1);
Expand Down
4 changes: 2 additions & 2 deletions profiles/generic/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
[MESSAGES]

<!-- Site's header -->
[HEADER|header_id=header|grid=p-1:_header]
[HEADER|grid_id=header|grid=p-1:_header]

<!-- Currently viewed node's content -->
[MAIN|grid_id=grid-main]

<!-- Site's footer -->
[FOOTER|footer_id=footer:_footer]
[FOOTER|grid_id=footer:_footer]

[JS|runlast]
</body>
Expand Down

0 comments on commit 2b17bc7

Please sign in to comment.