Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impact of switching from lowercase to uppercase first character #50

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

ReactorShop
Copy link

This is what needs to be changed when switching from e.g. "add new line"
to "Add New Line", plus other minor fixes. The gettext translation terms
must match case and spacing.

ReactorShop added 3 commits October 31, 2016 12:05
This is what needs to be changed when switching from e.g. "add new line"
to "Add New Line", plus other minor fixes. The gettext translation terms
must match case and spacing.
- Added trim to gettext in the class' staticVar_init() functions to
remove leading/trailing spaces before translating.
- Translated certain terms found in the search class.
- Added sorting capability to array of classes (function
l_select_field_from_object) using usort.
- The program name can be read from a public or public static class
property.
- A few more translations, as required by the Purchasing Module's
Requisition.
@ReactorShop
Copy link
Author

ReactorShop commented Nov 1, 2016

The "Added sorting capability to array of classes" commit, refers to sorting lists, like the currency one and maybe others which are long and may require some effort in order to locate a specific value within them.

@inoerp
Copy link
Owner

inoerp commented Nov 1, 2016

Appreciate your effort but don't think we need to have the sorting parameter in select_field as that's already taken care of by the object itself (the object used in the function).

@inoerp
Copy link
Owner

inoerp commented Nov 1, 2016

Sorting can be done using the existing second parameter. So, no need to add a new one

@ReactorShop
Copy link
Author

ReactorShop commented Nov 2, 2016

Hi @inoerp. These are the two class_inofrm.inc functions used to process the currency classes' currency code into an html select list:

public function l_select_field_from_object($name, $object, $objectValueKey, $objectDescriptionKey, $value = "", $id = "", $divClass = "", $required = "", $readonly = "", $convertToText = "", $nonArrayName = "", $disabled = "", $dataname = '') { echo '<label>' . gettext(ucwords(str_replace('_', ' ', $name))) . '</label>'; echo $this->select_field_from_object($name, $object, $objectValueKey, $objectDescriptionKey, $value, $id, $divClass, $required, $readonly, $convertToText, $nonArrayName, $disabled, $dataname); }

Which then calls:

`public function select_field_from_object($name, $object, $objectValueKey, $objectDescriptionKey, $value = "", $id = "", $divClass = "", $required = "", $readonly = "", $convertToText = "", $nonArrayName = "", $disabled = "", $dataname = '') {
$value = htmlentities($value, ENT_QUOTES, 'UTF-8');
$objectValueKey = strtolower($objectValueKey);
if ($nonArrayName == 1) {
$bracketName = $name;
} else {
$bracketName = $name . '[]';
}
$idvalue = $this->_convert_id($id);
if ($readonly == 1) {
$readonly = 'disabled';
} else {
$readonly = '';
}

if ($required == 1) {
$required = 'required';
} else {
$required = '';
}

if ($disabled == 1) {
$disabled = 'disbaled';
} else {
$disabled = '';
}
$element_select_field = "<Select name="$bracketName" class="select $divClass $name" $idvalue $readonly $required $disabled>";
$element_select_field .= "<option value="" >" . gettext('Select') . "";
if ((is_array($object)) && (count($object) > 0 )) {
foreach ($object as $record) {
if ((!empty($value)) && ($record->$objectValueKey == $value)) {
$selected = 'selected';
} else {
$selected = '';
}

$element_select_field .= '<option value="' . $record->$objectValueKey . '" ';
$element_select_field .= $selected;
if (!empty($dataname)) {
 if (is_array($dataname)) {
  foreach ($dataname as $dataname_k => $dataname_v) {
   $element_select_field .= " data-$dataname_v='" . $record->$dataname_v . "' ";
  }
 } else {
  $element_select_field .= " data-$dataname='" . $record->$dataname . "' ";
 }
}
$element_select_field .= '>';
if (is_array($objectDescriptionKey)) {
 $newValue1 = '';
 foreach ($objectDescriptionKey as $keya => $valuea) {
  $newValue1 .= $record->$valuea . ' | ';
 }
 $newValue = rtrim($newValue1, ' | ');
} else {
 $objectDescriptionKey = strtolower($objectDescriptionKey);
 $newValue = $record->$objectDescriptionKey;
}
$element_select_field .= $newValue;
$element_select_field .= '</option>';

}
}

if ($convertToText == 1) {
$element_select_field .= "<option value="newentry" class="bold blue">" . gettext('New Entry') . "";
}
$element_select_field .= '';

return $element_select_field;
}`

The second parameter of this function is $object, which is the array of currency classes that contain the currency code in need of sorting, and we're talking about sorting this array of classes using one of their class properties (the currency code) as the criteria, which is covered by the usort added to this function.

Can you please help me point out which parameter is the one that sorts the array of objects using a class property as the criteria?

Regards!

- Translation paths' titles will now be hinted translated.
- Class inv_serial_number is translated too.
- Added more terms to the translation domain files.
@inoerp
Copy link
Owner

inoerp commented Nov 3, 2016

can't we pass the parameter $object after sorting ?
Does it make more sense to do the sorting in this function instead of at the source of the object?
There is nothing horribly wrong about having the sort feature in the function but its a matter of principle of decoupling.

Below is the code for currency
Public static function currencies() { $option_header = self::find_by_name('CURRENCY'); $ol = new option_line(); $currencies = $ol->findBy_parentId($option_header->option_header_id, 'option_line_value'); return $currencies; }

Below is the code for findBy_parentId
` public function findBy_parentId($id, $order_by_field = '', $order_by_seq = '') {
global $dbc;
$order_by_field = empty($order_by_field) ? static::$primary_column : $order_by_field;
$order_by_seq = empty($order_by_seq) ? 'ASC' : $order_by_seq;
if (empty($id)) {
return false;
}
$sql = " SELECT * FROM ";
$sql.= static::$table_name;
$sql.= " WHERE " . static::$parent_primary_column . " = :primary_id ";
if (!empty($order_by_field)) {
$sql.= " ORDER BY {$order_by_field} ";
$sql.= " $order_by_seq ";
}

$stmt = $dbc->connection->prepare(" $sql ");
$stmt->bindParam(':primary_id', $id);
try {
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_CLASS);
} catch (PDOException $e) {
echo ino_show_debug_msg('Failed to read the data ', $e->getMessage(), $sql, ' Error @dbObject @@ Line " '.LINE);
}
return !empty($result) ? $result : false;
}`

@ReactorShop
Copy link
Author

The function will need to be hardcoded like this:

Public static function currencies() { $option_header = self::find_by_name('CURRENCY'); $ol = new option_line(); $currencies = $ol->findBy_parentId($option_header->option_header_id, 'option_line_value'); usort($currencies, function ($a, $b) { return $a->option_line_code <=> $b->option_line_code; }); return $currencies; }

This will only work with currencies, but I can do the same thing if I find another array of classes that requires sorting.

I already tested it and it works as expected.

I'm going to provide a commit that will remove my previous attempt and will provide this modification.

Regards

- Usort was placed inside the currencies() function.
@inoerp
Copy link
Owner

inoerp commented Nov 3, 2016

You don't need that either as sorting is done findBy_parentId
Below will work
Public static function currencies() { $option_header = self::find_by_name('CURRENCY'); $ol = new option_line(); $currencies = $ol->findBy_parentId($option_header->option_header_id, 'option_line_code'); return $currencies; }

Just need to modify the parameter to option_line_code from option_line_value

- I didn't check the findBy_parentId method, so I didn't know it could
sort.
@ReactorShop
Copy link
Author

As I said, I didn't check the findBy_parentId method, and I apologize. Here's how the PO Requisition Header screen looks like completely translated into Spanish, with the currency code sorted:

image

Thank you!

ReactorShop added 2 commits November 3, 2016 17:37
…ntity

I'm saying capabilities because there are too many pages and I can't add
all the translation terms to the domain files at this moment. Some are
going to be picked up because they already exist in the domain files,
though.
I had to enter the ampersand html entity name in order for it to be
displayed correctly.
It's taking into consideration the space before and after that I found
in almost all of the page titles class properties.
@ReactorShop
Copy link
Author

For the two latest commits, I'm going to apply the htmlentities() function so that we don't need to write the page title strings as html entities. I'll provide later a commit applying this modification.

…ted to text

I checked again, and the ampersand now shows as expected, so the
ampersand html entity code was replaced by the ampersand text, as it was
before.
@ReactorShop
Copy link
Author

AFAIK, in Spanish we don't use the ampersand, so this is a screen shot of a Spanish translation modified to include the ampersand as text in the clear, removing the htmlentities or htmlspecialchars I added before to test.

image

It works as expected,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants