Files
opensourcepos/app/Controllers/Persons.php
objecttothis 1328b4d9b8 - Removed TODOs that had been completed
- Added TODO where we need to convert to querybuilder
- Converted to switch statement.
- Removed unnecessary local variable
- Replaced Qualifiers with imports
- Replaced isset() call with null coalescing operator
- Replaced strpos function calls in if statements with str_contains calls
- Removed unnecessary leading \ in use statement
- Replaced deprecated functions
- Updated PHPdocs to match function signature
- Added missing type declarations
- Made class variables private.
- Explicitly declared dynamic properties
- use https:// links instead of http://
- Fixed type error from sending null when editing transactions
- Fixed Search Suggestion function name in Employees, Persons, Suppliers controller
- Fixed function name on Receivings Controller

Signed-off-by: objecttothis <objecttothis@gmail.com>
2024-06-15 17:19:15 +02:00

70 lines
1.6 KiB
PHP

<?php
namespace App\Controllers;
use App\Models\Person;
use function Tamtamchik\NameCase\str_name_case;
abstract class Persons extends Secure_Controller
{
protected Person $person;
/**
* @param string|null $module_id
*/
public function __construct(string $module_id = null)
{
parent::__construct($module_id);
$this->person = model(Person::class);
}
/**
* @return void
*/
public function getIndex(): void
{
$data['table_headers'] = get_people_manage_table_headers();
echo view('people/manage', $data);
}
/**
* Gives search suggestions based on what is being searched for
*/
public function getSuggest(): void
{
$suggestions = $this->person->get_search_suggestions($this->request->getPost('term', FILTER_SANITIZE_FULL_SPECIAL_CHARS));
echo json_encode($suggestions);
}
/**
* Gets one row for a person manage table. This is called using AJAX to update one row.
*/
public function getRow(int $row_id): void
{
$data_row = get_person_data_row($this->person->get_info($row_id));
echo json_encode($data_row);
}
/**
* Capitalize segments of a name, and put the rest into lower case.
* You can pass the characters you want to use as delimiters as exceptions.
* The function supports UTF-8 strings
*
* Example:
* i.e. <?php echo nameize("john o'grady-smith"); ?>
*
* returns John O'Grady-Smith
*/
protected function nameize(string $input): string
{
$adjusted_name = str_name_case($input);
// Use preg_replace to match HTML entities and convert them to lowercase.
return preg_replace_callback('/&[a-zA-Z0-9#]+;/', function($matches) { return strtolower($matches[0]); }, $adjusted_name);
}
}