Minor - format code

pull/3159/head
Julio Montoya 6 years ago
parent e239260037
commit 129508cb00
  1. 58
      main/inc/lib/extra_field_option.lib.php
  2. 7
      main/inc/lib/extra_field_value.lib.php
  3. 5
      main/inc/lib/pear/HTML/QuickForm.php
  4. 77
      main/inc/lib/pear/HTML/QuickForm/checkbox.php
  5. 6
      main/inc/lib/pear/HTML/QuickForm/text.php

@ -1,4 +1,5 @@
<?php <?php
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Entity\ExtraFieldOptions; use Chamilo\CoreBundle\Entity\ExtraFieldOptions;
@ -46,19 +47,6 @@ class ExtraFieldOption extends Model
return $this->extraField; return $this->extraField;
} }
/**
* Gets the number of options already available in the table for this item type.
*
* @return int Number of options available
* @assert () >= 0
*/
/*public function get_count()
{
$row = Database::select('count(*) as count', $this->table, array(), 'first');
return $row['count'];
}*/
/** /**
* Gets the number of options available for this field. * Gets the number of options available for this field.
* *
@ -75,10 +63,10 @@ class ExtraFieldOption extends Model
return false; return false;
} }
$extraFieldType = $this->getExtraField()->getExtraFieldType(); $extraFieldType = $this->getExtraField()->getExtraFieldType();
$fieldId = intval($fieldId); $fieldId = (int) $fieldId;
$sql = "SELECT count(*) as count $sql = "SELECT count(*) as count
FROM $this->table o FROM $this->table o
INNER JOIN $this->tableExtraField e INNER JOIN $this->tableExtraField e
ON o.field_id = e.id ON o.field_id = e.id
WHERE WHERE
@ -125,11 +113,10 @@ class ExtraFieldOption extends Model
*/ */
public function delete_all_options_by_field_id($field_id) public function delete_all_options_by_field_id($field_id)
{ {
$field_id = intval($field_id); $field_id = (int) $field_id;
$sql = "DELETE FROM {$this->table} WHERE field_id = $field_id"; $sql = "DELETE FROM {$this->table} WHERE field_id = $field_id";
$r = Database::query($sql);
return $r; return Database::query($sql);
} }
/** /**
@ -173,7 +160,7 @@ class ExtraFieldOption extends Model
*/ */
public function save($params, $showQuery = false) public function save($params, $showQuery = false)
{ {
$field_id = intval($params['field_id']); $field_id = (int) $params['field_id'];
if (empty($field_id)) { if (empty($field_id)) {
return false; return false;
@ -421,7 +408,7 @@ class ExtraFieldOption extends Model
*/ */
public function get_field_option_by_field_and_option($field_id, $option_value) public function get_field_option_by_field_and_option($field_id, $option_value)
{ {
$field_id = intval($field_id); $field_id = (int) $field_id;
$option_value = Database::escape_string($option_value); $option_value = Database::escape_string($option_value);
$extraFieldType = $this->getExtraField()->getExtraFieldType(); $extraFieldType = $this->getExtraField()->getExtraFieldType();
@ -452,7 +439,7 @@ class ExtraFieldOption extends Model
*/ */
public function get_field_option_by_field_id_and_option_display_text($field_id, $option_display_text) public function get_field_option_by_field_id_and_option_display_text($field_id, $option_display_text)
{ {
$field_id = intval($field_id); $field_id = (int) $field_id;
$option_display_text = Database::escape_string($option_display_text); $option_display_text = Database::escape_string($option_display_text);
$extraFieldType = $this->getExtraField()->getExtraFieldType(); $extraFieldType = $this->getExtraField()->getExtraFieldType();
@ -487,7 +474,7 @@ class ExtraFieldOption extends Model
$option_display_text, $option_display_text,
$option_value $option_value
) { ) {
$field_id = intval($field_id); $field_id = (int) $field_id;
$option_display_text = Database::escape_string($option_display_text); $option_display_text = Database::escape_string($option_display_text);
$option_value = Database::escape_string($option_value); $option_value = Database::escape_string($option_value);
$extraFieldType = $this->getExtraField()->getExtraFieldType(); $extraFieldType = $this->getExtraField()->getExtraFieldType();
@ -520,7 +507,7 @@ class ExtraFieldOption extends Model
*/ */
public function get_field_options_by_field($field_id, $add_id_in_array = false, $ordered_by = null) public function get_field_options_by_field($field_id, $add_id_in_array = false, $ordered_by = null)
{ {
$field_id = intval($field_id); $field_id = (int) $field_id;
$orderBy = null; $orderBy = null;
switch ($ordered_by) { switch ($ordered_by) {
@ -589,7 +576,7 @@ class ExtraFieldOption extends Model
public function get_second_select_field_options_by_field($option_value_id, $to_json = false) public function get_second_select_field_options_by_field($option_value_id, $to_json = false)
{ {
$em = Database::getManager(); $em = Database::getManager();
$option = $em->find('ChamiloCoreBundle:ExtraFieldOptions', intval($option_value_id)); $option = $em->find('ChamiloCoreBundle:ExtraFieldOptions', $option_value_id);
if (!$option) { if (!$option) {
return !$to_json ? [] : '{}'; return !$to_json ? [] : '{}';
@ -676,7 +663,7 @@ class ExtraFieldOption extends Model
*/ */
public function get_max_order($field_id) public function get_max_order($field_id)
{ {
$field_id = intval($field_id); $field_id = (int) $field_id;
$sql = "SELECT MAX(option_order) $sql = "SELECT MAX(option_order)
FROM {$this->table} FROM {$this->table}
WHERE field_id = $field_id"; WHERE field_id = $field_id";
@ -753,18 +740,18 @@ class ExtraFieldOption extends Model
$form = new FormValidator($form_name, 'post', $url); $form = new FormValidator($form_name, 'post', $url);
// Setting the form elements // Setting the form elements
$header = get_lang('Add'); $header = get_lang('Add');
if ($action == 'edit') { if ($action === 'edit') {
$header = get_lang('Modify'); $header = get_lang('Modify');
} }
$form->addElement('header', $header); $form->addElement('header', $header);
$id = isset($_GET['id']) ? intval($_GET['id']) : ''; $id = isset($_GET['id']) ? (int) $_GET['id'] : '';
$form->addElement('hidden', 'id', $id); $form->addElement('hidden', 'id', $id);
$form->addElement('hidden', 'type', $this->type); $form->addElement('hidden', 'type', $this->type);
$form->addElement('hidden', 'field_id', $this->fieldId); $form->addElement('hidden', 'field_id', $this->fieldId);
if ($action == 'edit') { if ($action === 'edit') {
$translateUrl = api_get_path(WEB_CODE_PATH).'extrafield/translate.php?'.http_build_query([ $translateUrl = api_get_path(WEB_CODE_PATH).'extrafield/translate.php?'.http_build_query([
'extra_field_option' => $id, 'extra_field_option' => $id,
]); ]);
@ -790,7 +777,7 @@ class ExtraFieldOption extends Model
$defaults = []; $defaults = [];
if ($action == 'edit') { if ($action === 'edit') {
// Setting the defaults // Setting the defaults
$defaults = $this->get($id, false); $defaults = $this->get($id, false);
$form->freeze('option_value'); $form->freeze('option_value');
@ -817,9 +804,10 @@ class ExtraFieldOption extends Model
*/ */
public function searchByField($tag, $field_id, $limit = 10) public function searchByField($tag, $field_id, $limit = 10)
{ {
$field_id = intval($field_id); $field_id = (int) $field_id;
$limit = intval($limit); $limit = (int) $limit;
$tag = Database::escape_string($tag); $tag = Database::escape_string($tag);
$sql = "SELECT DISTINCT id, option_display_text $sql = "SELECT DISTINCT id, option_display_text
FROM {$this->table} FROM {$this->table}
WHERE WHERE
@ -928,16 +916,16 @@ class ExtraFieldOption extends Model
/** /**
* @param string $variable * @param string $variable
* *
* @return array|\Chamilo\CoreBundle\Entity\ExtraFieldOptions[] * @return array|ExtraFieldOptions[]
*/ */
public function getOptionsByFieldVariable($variable) public function getOptionsByFieldVariable($variable)
{ {
$extraFieldType = $this->getExtraField()->getExtraFieldType(); $extraFieldType = $this->getExtraField()->getExtraFieldType();
$dql = "SELECT o FROM ChamiloCoreBundle:ExtraFieldOptions o $dql = "SELECT o FROM ChamiloCoreBundle:ExtraFieldOptions o
INNER JOIN ChamiloCoreBundle:ExtraField f WITH o.field = f.id INNER JOIN ChamiloCoreBundle:ExtraField f WITH o.field = f.id
WHERE f.variable = :variable AND f.extraFieldType = :extra_field_type WHERE f.variable = :variable AND f.extraFieldType = :extra_field_type
ORDER BY o.value ASC"; ORDER BY o.value ASC";
$result = Database::getManager() $result = Database::getManager()
->createQuery($dql) ->createQuery($dql)

@ -1,4 +1,5 @@
<?php <?php
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Entity\ExtraField as EntityExtraField; use Chamilo\CoreBundle\Entity\ExtraField as EntityExtraField;
@ -11,8 +12,6 @@ use ChamiloSession as Session;
* Class ExtraFieldValue * Class ExtraFieldValue
* Declaration for the ExtraFieldValue class, managing the values in extra * Declaration for the ExtraFieldValue class, managing the values in extra
* fields for any data type. * fields for any data type.
*
* @package chamilo.library
*/ */
class ExtraFieldValue extends Model class ExtraFieldValue extends Model
{ {
@ -677,9 +676,9 @@ class ExtraFieldValue extends Model
} }
return $result; return $result;
} else {
return false;
} }
return false;
} }
/** /**

@ -650,6 +650,7 @@ class HTML_QuickForm extends HTML_Common
} }
// If not done, the elements will appear in reverse order // If not done, the elements will appear in reverse order
ksort($this->_elements); ksort($this->_elements);
return $element; return $element;
} }
@ -683,8 +684,8 @@ class HTML_QuickForm extends HTML_Common
if ($createElement) { if ($createElement) {
return $this->createElement('group', $name, $groupLabel, $elements, $separator, $appendName); return $this->createElement('group', $name, $groupLabel, $elements, $separator, $appendName);
} }
$group = & $this->addElement('group', $name, $groupLabel, $elements, $separator, $appendName);
return $group; return $this->addElement('group', $name, $groupLabel, $elements, $separator, $appendName);
} }
/** /**

@ -45,9 +45,6 @@ class HTML_QuickForm_checkbox extends HTML_QuickForm_input
public $labelClass; public $labelClass;
public $checkboxClass; public $checkboxClass;
// }}}
// {{{ constructor
/** /**
* Class constructor * Class constructor
* *
@ -99,17 +96,14 @@ class HTML_QuickForm_checkbox extends HTML_QuickForm_input
* @access public * @access public
* @return void * @return void
*/ */
function setChecked($checked) public function setChecked($checked)
{ {
if (!$checked) { if (!$checked) {
$this->removeAttribute('checked'); $this->removeAttribute('checked');
} else { } else {
$this->updateAttributes(array('checked' => 'checked')); $this->updateAttributes(array('checked' => 'checked'));
} }
} //end func setChecked }
// }}}
// {{{ getChecked()
/** /**
* Returns whether a checkbox is checked * Returns whether a checkbox is checked
@ -118,13 +112,10 @@ class HTML_QuickForm_checkbox extends HTML_QuickForm_input
* @access public * @access public
* @return bool * @return bool
*/ */
function getChecked() public function getChecked()
{ {
return (bool)$this->getAttribute('checked'); return (bool)$this->getAttribute('checked');
} //end func getChecked }
// }}}
// {{{ toHtml()
/** /**
* Returns the checkbox element in HTML * Returns the checkbox element in HTML
@ -144,7 +135,7 @@ class HTML_QuickForm_checkbox extends HTML_QuickForm_input
$checkClass = $this->checkboxClass; $checkClass = $this->checkboxClass;
$name = $this->_attributes['name']; $name = $this->_attributes['name'];
$label ='<div id="'.$name.'" class="'.$checkClass.'"> $label ='<div id="'.$name.'" class="'.$checkClass.'">
<label class="'.$labelClass.'">' . <label class="'.$labelClass.'">'.
HTML_QuickForm_input::toHtml().' '.$this->_text. HTML_QuickForm_input::toHtml().' '.$this->_text.
'</label> '</label>
</div> </div>
@ -153,7 +144,7 @@ class HTML_QuickForm_checkbox extends HTML_QuickForm_input
return $label; return $label;
} }
return HTML_QuickForm_input::toHtml() . $label; return HTML_QuickForm_input::toHtml().$label;
} }
/** /**
@ -164,7 +155,6 @@ class HTML_QuickForm_checkbox extends HTML_QuickForm_input
public function getTemplate($layout) public function getTemplate($layout)
{ {
$size = $this->calculateSize(); $size = $this->calculateSize();
switch ($layout) { switch ($layout) {
case FormValidator::LAYOUT_INLINE: case FormValidator::LAYOUT_INLINE:
return ' return '
@ -172,10 +162,10 @@ class HTML_QuickForm_checkbox extends HTML_QuickForm_input
<label {label-for} > <label {label-for} >
<!-- BEGIN required --><span class="form_required">*</span><!-- END required --> <!-- BEGIN required --><span class="form_required">*</span><!-- END required -->
{label} {label}
</label> </label>
</div> </div>
<div class="input-group {error_class}"> <div class="input-group {error_class}">
{element} {element}
</div> </div>
'; ';
break; break;
@ -222,18 +212,15 @@ class HTML_QuickForm_checkbox extends HTML_QuickForm_input
* @access public * @access public
* @return string * @return string
*/ */
function getFrozenHtml() public function getFrozenHtml()
{ {
if ($this->getChecked()) { if ($this->getChecked()) {
return '<code>[x]</code>' . return '<code>[x]</code>'.
$this->_getPersistantData(); $this->_getPersistantData();
} else { } else {
return '<code>[ ]</code>'; return '<code>[ ]</code>';
} }
} //end func getFrozenHtml }
// }}}
// {{{ setText()
/** /**
* Sets the checkbox text * Sets the checkbox text
@ -243,13 +230,10 @@ class HTML_QuickForm_checkbox extends HTML_QuickForm_input
* @access public * @access public
* @return void * @return void
*/ */
function setText($text) public function setText($text)
{ {
$this->_text = $text; $this->_text = $text;
} //end func setText }
// }}}
// {{{ getText()
/** /**
* Returns the checkbox text * Returns the checkbox text
@ -258,13 +242,10 @@ class HTML_QuickForm_checkbox extends HTML_QuickForm_input
* @access public * @access public
* @return string * @return string
*/ */
function getText() public function getText()
{ {
return $this->_text; return $this->_text;
} //end func getText }
// }}}
// {{{ setValue()
/** /**
* Sets the value of the form element * Sets the value of the form element
@ -274,13 +255,10 @@ class HTML_QuickForm_checkbox extends HTML_QuickForm_input
* @access public * @access public
* @return void * @return void
*/ */
function setValue($value) public function setValue($value)
{ {
return $this->setChecked($value); return $this->setChecked($value);
} // end func setValue }
// }}}
// {{{ getValue()
/** /**
* Returns the value of the form element * Returns the value of the form element
@ -289,13 +267,10 @@ class HTML_QuickForm_checkbox extends HTML_QuickForm_input
* @access public * @access public
* @return bool * @return bool
*/ */
function getValue() public function getValue()
{ {
return $this->getChecked(); return $this->getChecked();
} // end func getValue }
// }}}
// {{{ onQuickFormEvent()
/** /**
* Called by HTML_QuickForm whenever form event is made on this element * Called by HTML_QuickForm whenever form event is made on this element
@ -307,7 +282,7 @@ class HTML_QuickForm_checkbox extends HTML_QuickForm_input
* @access public * @access public
* @return void * @return void
*/ */
function onQuickFormEvent($event, $arg, &$caller) public function onQuickFormEvent($event, $arg, &$caller)
{ {
switch ($event) { switch ($event) {
case 'updateValue': case 'updateValue':
@ -335,16 +310,14 @@ class HTML_QuickForm_checkbox extends HTML_QuickForm_input
default: default:
parent::onQuickFormEvent($event, $arg, $caller); parent::onQuickFormEvent($event, $arg, $caller);
} }
return true;
} // end func onQuickFormEvent
// }}} return true;
// {{{ exportValue() }
/** /**
* Return true if the checkbox is checked, null if it is not checked (getValue() returns false) * Return true if the checkbox is checked, null if it is not checked (getValue() returns false)
*/ */
function exportValue(&$submitValues, $assoc = false) public function exportValue(&$submitValues, $assoc = false)
{ {
$value = $this->_findValue($submitValues); $value = $this->_findValue($submitValues);
if (null === $value) { if (null === $value) {

@ -152,7 +152,7 @@ class HTML_QuickForm_text extends HTML_QuickForm_input
<em class="fa fa-search"></em> <em class="fa fa-search"></em>
</button> </button>
</div> </div>
</div> </div>
'; ';
} else { } else {
$template = ' $template = '
@ -200,8 +200,8 @@ class HTML_QuickForm_text extends HTML_QuickForm_input
{ {
if ($this->isFrozen()) { if ($this->isFrozen()) {
return $this->getFrozenHtml(); return $this->getFrozenHtml();
} else {
return '<input '.$this->_getAttrString($this->_attributes).' />';
} }
return '<input '.$this->_getAttrString($this->_attributes).' />';
} }
} }

Loading…
Cancel
Save