Skip to content

Commit

Permalink
Merge branch 'namespaces' into nextgen
Browse files Browse the repository at this point in the history
  • Loading branch information
jbtronics committed Aug 29, 2017
2 parents 9a4533e + dae51b6 commit b357e6e
Show file tree
Hide file tree
Showing 43 changed files with 2,972 additions and 2,932 deletions.
2 changes: 1 addition & 1 deletion edit_attachement_types.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
throw new Exception(_('Es ist kein Dateityp markiert oder es trat ein Fehler auf!'));
}

$attachements = $selected_attachement_type->get_attachements();
$attachements = $selected_attachement_type->get_attachements_for_type();
$count = count($attachements);

if ($count > 0) {
Expand Down
1,384 changes: 692 additions & 692 deletions edit_part_info.php

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion inc/lib.debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ function delete_debug_log_file()
* @param array|null $types @li here you can supply an array of all log types (strings) you want to get
* @li NULL if you want to get ALL log elements
*
* @retval array log elements (array-like)
* @return array log elements (array-like)
*
* @throws Exception if there was an error (maybe no file or no read permissions)
*/
Expand Down
2 changes: 1 addition & 1 deletion inc/lib.functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ function money_format($format, $number)
* str_getcsv()
*/
if (! function_exists('str_getcsv')) {
function str_getcsv($str, $delim=',', $enclose='"', $preserve=false)
function str_getcsv($str, $delim = ',', $enclose = '"', $preserve = false)
{
$resArr = array();
$n = 0;
Expand Down
2 changes: 1 addition & 1 deletion inc/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ function save_config()
$content .= ' //$manual_config[\'money_format\'][\'POSIX\'] = \'%!n €\';'."\n";
$content .= ' //$manual_config[\'DOCUMENT_ROOT\'] = \'/var/www\';'."\n";
$content .= array_to_php_lines($manual_config, $manual_config, ' $manual_config', false);
$content .= "\n?>";
$content .= "\n";

if (! ($fp = fopen(BASE.'/data/config.php', 'wb'))) {
throw new Exception('Die Datei "config.php" konnte nicht beschrieben werden. Überprüfen Sie, ob genügend Rechte vorhanden sind.');
Expand Down
2 changes: 1 addition & 1 deletion lib/Attachement.php
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ public static function add(
throw new Exception(_('$element ist kein Objekt!'));
}

return parent::add(
return parent::add_via_array(
$database,
$current_user,
$log,
Expand Down
4 changes: 2 additions & 2 deletions lib/AttachementType.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function __construct(&$database, &$current_user, &$log, $id, $db_data = n
*
* @throws Exception if there was an error
*/
public function get_attachements()
public function get_attachements_for_type()
{
// the attribute $this->attachements is used from class "AttachementsContainingDBELement"
if (! is_array($this->attachements)) {
Expand Down Expand Up @@ -138,7 +138,7 @@ public static function get_count(&$database)
*/
public static function add(&$database, &$current_user, &$log, $name, $parent_id)
{
return parent::add(
return parent::add_via_array(
$database,
$current_user,
$log,
Expand Down
4 changes: 2 additions & 2 deletions lib/Base/Company.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ abstract class Company extends PartsContainingDBElement implements IAPIModel
* @throws Exception if there is no such element in the database
* @throws Exception if there was an error
*/
public function __construct(&$database, &$current_user, &$log, $tablename, $id)
public function __construct(&$database, &$current_user, &$log, $tablename, $id, $data = null)
{
parent::__construct($database, $current_user, $log, $tablename, $id);
parent::__construct($database, $current_user, $log, $tablename, $id, $data);

if ($id == 0) {
// this is the root node
Expand Down
4 changes: 2 additions & 2 deletions lib/Base/DBElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,11 +342,11 @@ public static function check_values_validity(&$database, &$current_user, &$log,
* @li example: @code
* array(['name'] => 'abcd', ['parent_id'] => 123, ...) @endcode
*
* @retval object the created object (e.g. Device, Part, Category, ...)
* @return static the created object (e.g. Device, Part, Category, ...)
*
* @throws Exception if the values are not valid / the combination of values is not valid
*/
public static function add(&$database, &$current_user, &$log, $tablename, $new_values)
protected static function add_via_array(&$database, &$current_user, &$log, $tablename, $new_values)
{
if (!$database instanceof Database) {
throw new Exception(_('$database ist kein gültiges Database-Objekt!'));
Expand Down
5 changes: 3 additions & 2 deletions lib/Base/NamedDBElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public static function check_values_validity(&$database, &$current_user, &$log,
}

/**
* Search elements by name
* Search elements by name in the given table
*
* @param Database &$database reference to the database object
* @param User &$current_user reference to the user which is logged in
Expand All @@ -142,7 +142,7 @@ public static function check_values_validity(&$database, &$current_user, &$log,
*
* @throws Exception if there was an error
*/
public static function search(&$database, &$current_user, &$log, $tablename, $keyword, $exact_match)
protected static function search_table(&$database, &$current_user, &$log, $tablename, $keyword, $exact_match)
{
if (strlen($keyword) == 0) {
return array();
Expand All @@ -166,4 +166,5 @@ public static function search(&$database, &$current_user, &$log, $tablename, $ke

return $objects;
}

}
43 changes: 5 additions & 38 deletions lib/Base/PartsContainingDBElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ abstract class PartsContainingDBElement extends StructuralDBElement
* @throws Exception if there is no such element in the database
* @throws Exception if there was an error
*/
public function __construct(&$database, &$current_user, &$log, $tablename, $id)
public function __construct(&$database, &$current_user, &$log, $tablename, $id, $data = null)
{
parent::__construct($database, $current_user, $log, $tablename, $id);
parent::__construct($database, $current_user, $log, $tablename, $id, $data);
}

/**
Expand Down Expand Up @@ -161,43 +161,8 @@ public function delete($delete_recursive = false, $delete_files_from_hdd = false
*
* @throws Exception if there was an error
*/
public function get_parts($parts_rowname, $recursive = false, $hide_obsolete_and_zero = false)
public function get_table_parts($parts_rowname, $recursive = false, $hide_obsolete_and_zero = false)
{
/*
if ( ! is_array($this->parts))
{
$this->parts = array();
$query = 'SELECT id FROM parts WHERE '.$parts_rowname.'=? ORDER BY name, description';
$query_data = $this->database->query($query, array($this->get_id()));
foreach ($query_data as $row)
$this->parts[] = new Part($this->database, $this->current_user, $this->log, $row['id']);
}
$parts = $this->parts;
if ($hide_obsolete_and_zero)
{
// remove obsolete parts from array
$parts = array_values(array_filter($parts, function($part) {return (( ! $part->get_obsolete()) || ($part->get_instock() > 0));}));
}
if ($recursive)
{
$subelements = $this->get_subelements(false);
foreach ($subelements as $element) {
$i = $element->get_id();
$parts = array_merge($parts, $element->get_parts(true, $hide_obsolete_and_zero));
}
usort($parts, 'PartsContainingDBElement::usort_compare'); // Sort all parts by their names and descriptions
}
return $parts;
*/

$subelements = array();

if ($recursive) {
Expand Down Expand Up @@ -249,6 +214,8 @@ public function get_parts($parts_rowname, $recursive = false, $hide_obsolete_and
return $parts;
}

public abstract function get_parts($recursive = false, $hide_obsolete_and_zero = false);

/**
* Compare function for "usort()"
*
Expand Down
11 changes: 6 additions & 5 deletions lib/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* All elements of this class are stored in the database table "categories".
* @author kami89
*/
class Category extends Base\PartsContainingDBElement implements Interfaces\IAPIModel
class Category extends Base\PartsContainingDBElement implements Interfaces\IAPIModel, Interfaces\ISearchable
{
/********************************************************************************
*
Expand All @@ -59,7 +59,7 @@ class Category extends Base\PartsContainingDBElement implements Interfaces\IAPIM
*/
public function __construct(&$database, &$current_user, &$log, $id, $data = null)
{
parent::__construct($database, $current_user, $log, 'categories', $id, false, $data);
parent::__construct($database, $current_user, $log, 'categories', $id, $data);
}

/********************************************************************************
Expand Down Expand Up @@ -335,6 +335,7 @@ public function get_partname_regex_raw($including_parents = false, $show_escape
/**
* Gets the regex of this Category.
* @param bool $including_parents
* @return string The regex.
*/
public function get_partname_regex($including_parents = true)
{
Expand Down Expand Up @@ -378,7 +379,7 @@ public function check_partname($name, $including_parents = true)
*/
public function get_parts($recursive = false, $hide_obsolete_and_zero = false)
{
return parent::get_parts('id_category', $recursive, $hide_obsolete_and_zero);
return parent::get_table_parts('id_category', $recursive, $hide_obsolete_and_zero);
}

/********************************************************************************
Expand Down Expand Up @@ -547,7 +548,7 @@ public static function add(
$default_description = "",
$default_comment = ""
) {
return parent::add(
return parent::add_via_array(
$database,
$current_user,
$log,
Expand All @@ -568,7 +569,7 @@ public static function add(
*/
public static function search(&$database, &$current_user, &$log, $keyword, $exact_match = false)
{
return parent::search($database, $current_user, $log, 'categories', $keyword, $exact_match);
return parent::search_table($database, $current_user, $log, 'categories', $keyword, $exact_match);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion lib/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
namespace PartDB;

/** @noinspection PhpIncludeInspection */
use DebugBar\DataCollector\PDO\TraceablePDO;
use Exception;
use PartDB\Tools\PDBDebugBar;
use PDO;
Expand Down Expand Up @@ -170,7 +171,7 @@ public function __construct()
}

if (PDBDebugBar::is_activated()) {
$this->pdo = new \DebugBar\DataCollector\PDO\TraceablePDO($this->pdo);
$this->pdo = new TraceablePDO($this->pdo);
PDBDebugBar::getInstance()->registerPDO($this->pdo);
}
}
Expand Down
6 changes: 3 additions & 3 deletions lib/Device.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class Device extends Base\PartsContainingDBElement
*/
public function __construct(&$database, &$current_user, &$log, $id, $data = null)
{
parent::__construct($database, $current_user, $log, 'devices', $id, false, $data);
parent::__construct($database, $current_user, $log, 'devices', $id, $data);

if ($id == 0) {
// this is the root node
Expand Down Expand Up @@ -271,7 +271,7 @@ public function get_order_only_missing_parts()
*
* @throws Exception if there was an error
*/
public function get_parts($recursive = false)
public function get_parts($recursive = false, $hide_obsolet_and_zero = false)
{
if (! is_array($this->parts)) {
$this->parts = array();
Expand Down Expand Up @@ -500,7 +500,7 @@ public static function get_count(&$database)
*/
public static function add(&$database, &$current_user, &$log, $name, $parent_id)
{
return parent::add(
return parent::add_via_array(
$database,
$current_user,
$log,
Expand Down
2 changes: 1 addition & 1 deletion lib/DevicePart.php
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ public static function add(
}

// there is no such DevicePart, so we will create it
return parent::add(
return parent::add_via_array(
$database,
$current_user,
$log,
Expand Down
10 changes: 5 additions & 5 deletions lib/Footprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* All elements of this class are stored in the database table "footprints".
* @author kami89
*/
class Footprint extends Base\PartsContainingDBElement implements Interfaces\IAPIModel
class Footprint extends Base\PartsContainingDBElement implements Interfaces\IAPIModel, Interfaces\ISearchable
{
/********************************************************************************
*
Expand All @@ -58,7 +58,7 @@ class Footprint extends Base\PartsContainingDBElement implements Interfaces\IAPI
*/
public function __construct(&$database, &$current_user, &$log, $id, $data = null)
{
parent::__construct($database, $current_user, $log, 'footprints', $id, false, $data);
parent::__construct($database, $current_user, $log, 'footprints', $id, $data);

if ($id == 0) {
// this is the root node
Expand Down Expand Up @@ -117,7 +117,7 @@ public function get_3d_filename($absolute = true)
*/
public function get_parts($recursive = false, $hide_obsolete_and_zero = false)
{
return parent::get_parts('id_footprint', $recursive, $hide_obsolete_and_zero);
return parent::get_table_parts('id_footprint', $recursive, $hide_obsolete_and_zero);
}

/**
Expand Down Expand Up @@ -340,7 +340,7 @@ public static function get_broken_3d_filename_footprints(&$database, &$current_u
*/
public static function add(&$database, &$current_user, &$log, $name, $parent_id, $filename = '', $filename_3d = '')
{
return parent::add(
return parent::add_via_array(
$database,
$current_user,
$log,
Expand All @@ -356,7 +356,7 @@ public static function add(&$database, &$current_user, &$log, $name, $parent_id,
*/
public static function search(&$database, &$current_user, &$log, $keyword, $exact_match = false)
{
return parent::search($database, $current_user, $log, 'footprints', $keyword, $exact_match);
return parent::search_table($database, $current_user, $log, 'footprints', $keyword, $exact_match);
}

/**
Expand Down
30 changes: 30 additions & 0 deletions lib/Interfaces/ISearchable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* Created by PhpStorm.
* User: janhb
* Date: 29.08.2017
* Time: 14:25
*/

namespace PartDB\Interfaces;


interface ISearchable
{
/**
* Search elements by name.
*
* @param Database &$database reference to the database object
* @param User &$current_user reference to the user which is logged in
* @param Log &$log reference to the Log-object
* @param string $keyword the search string
* @param boolean $exact_match @li If true, only records which matches exactly will be returned
* @li If false, all similar records will be returned
*
* @return array all found elements as a one-dimensional array of objects,
* sorted by their names
*
* @throws Exception if there was an error
*/
public static function search(&$database, &$current_user, &$log, $keyword, $exact_match);
}
Loading

0 comments on commit b357e6e

Please sign in to comment.