commit 6bd4d533333568056c1fefcc9c255838906f8cb6 Author: Thomas Kuschel Date: Tue Oct 3 03:56:38 2023 +0200 B1 first commit, example diff --git a/CODING_STANDARDS.md b/CODING_STANDARDS.md new file mode 100644 index 0000000..63d9688 --- /dev/null +++ b/CODING_STANDARDS.md @@ -0,0 +1,341 @@ +# KW4NZ coding standards + +This file lists standards that any programmer adding or changing code in +this project should follow. + +## Code implementation + +1. Document your code in source files and the manual. (tm) + +1. This project is implemented in PHP Version 8.2. The base of the Joomla + core is version 5.0 as a minimum and is not maintained backward compatible. + +1. The return type of "is" or "has" style functions should be `bool`, + which return a "yes"/"no" answer. `zend_result` is an appropriate + return value for functions that perform some operation that may + succeed or fail. + +## User functions/methods naming conventions + +1. Function names should be in lowercase, with words underscore + delimited, with care taken to minimize the letter count. + The exception to this is of course the Joomla core functions and + Joomla naming conventions for classes. + Abbreviations should not be used when they greatly decrease + the readability of the function name itself: + + Good: + + ```php + str_word_count + array_key_exists + ``` + + Ok: + + ```php + date_interval_create_from_date_string + // Could be 'date_intvl_create_from_date_str'? + get_html_translation_table() + // Could be 'html_get_trans_table'? + ``` + + Bad: + + ```php + hw_GetObjectByQueryCollObj + pg_setclientencoding + jf_n_s_i + ``` + +1. If they are part of a "parent set" of functions, that parent should be + included in the user function name, and should be clearly related to the + parent program or function family. This should be in the form of `parent_*`: + + A family of `foo` functions, for example: + + Good: + + ```php + foo_select_bar + foo_insert_baz + foo_delete_baz + ``` + + Bad: + + ```php + fooselect_bar + fooinsertbaz + delete_foo_baz + ``` + +1. Variable names must be meaningful. One letter variable names must be avoided, + except for places where the variable has no real meaning or a trivial + meaning (e.g. `for ($i=0; $i<100; $i++) ...`). + +1. Variable names should be in lowercase. Use underscores to separate between + words. + +1. Method names follow the *studlyCaps* (also referred to as *bumpy case* or + *camel caps*) naming convention, with care taken to minimize the letter + count. The initial letter of the name is lowercase, and each letter that + starts a new `word` is capitalized: + + Good: + + ```php + connect() + getData() + buildSomeWidget() + ``` + + Bad: + + ```php + get_Data() + buildsomewidget() + getI() + ``` + +1. Class names should be descriptive nouns in *PascalCase* and as short as + possible. Each word in the class name should start with a capital letter, + without underscore delimiters. The class name should be prefixed with the + name of the "parent set" (e.g. the name of the extension) if no namespaces + are used. Abbreviations and acronyms as well as initialisms should be + avoided wherever possible, unless they are much more widely used than the + long form (e.g. HTTP or URL). Abbreviations start with a capital letter + followed by lowercase letters, whereas acronyms and initialisms are written + according to their standard notation. Usage of acronyms and initialisms is + not allowed if they are not widely adopted and recognized as such. + + Good: + + ```php + Curl + CurlResponse + HTTPStatusCode + URL + BTreeMap // B-tree Map + Id // Identifier + ID // Identity Document + Char // Character + Intl // Internationalization + Radar // Radio Detecting and Ranging + ``` + + Bad: + + ```php + curl + curl_response + HttpStatusCode + Url + BtreeMap + ID // Identifier + CHAR + INTL + RADAR // Radio Detecting and Ranging + ``` + +## Syntax and indentation + +1. Use K&R-style and use 1TBS ()"One True Bace Style"). + Of course, we can't and don't + want to force anybody to use a style he or she is not used to, but, at the very + least, when you write code that goes into the core of PHP or one of its standard + modules, please maintain the K&R style. + This applies to just about everything, starting with indentation and comment + styles and up to function declaration syntax. Also + see [Indentstyle](http://www.catb.org/~esr/jargon/html/I/indent-style.html). + When following K&R, each function has its opening brace at the next line on the + same indentation level as its header, the statements within the braces are + indented, and the closing brace at the end is on the same indentation level as + the header of the function at a line of its own. + +```php +protected function batch_client($value, $pks, $contexts) +{ + // Set the variables + $user = $this->getCurrentUser(); + $table = $this->getTable(); + + foreach ($pks as $pk) { + if (!$user->authorise('core.edit', $contexts[$pk])) { + $this->setError(Text::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_EDIT')); + + return false; + } + + $table->reset(); + $table->load($pk); + $table->cid = (int) $value; + + if (!$table->store()) { + $this->setError($table->getError()); + + return false; + } + } + + // Clean the cache + $this->cleanCache(); + + return true; +} +``` + +1. Be generous with whitespace and braces. Keep one empty line between the + variable declaration section and the statements in a block, as well as + between logical statement groups in a block. Maintain at least one empty + line between two functions, preferably two. Always prefer: + + ```php + if (foo) { + bar; + } + ``` + + to: + + ```php + if(foo)bar; + ``` + +1. When indenting, use the tab character. A tab is expected to represent four + spaces (1 tab == 4 spaces). It is important to maintain consistency in indentation so that + definitions, comments, and control structures line up correctly. + +## Trailing whitespace, EOF + +1. Trailing whitespace must not be present after statements or serial comma break +or on blank lines. Remove trailing white spaces. + + Good: + + ```php + $quotes_exist = false; + $my_movies = [ + \t'Slumdog Millionaire', + 'The Lives of Ohters', + 'The Shawshank Redemption' + ]; + + print_welcome_message(); + //EOF + ``` + + Bad, because there is a space after `','` , also two spaces on the blank line below `print_welcome_message()`. No whitespaces in the last line.: + + ```php + $quotes_exist = false; + $my_movies = [ + 'Slumdog Millionaire', + 'The Lives of Ohters', + 'The Shawshank Redemption' + ]; + + print_welcome_message(); + + //EOF + ``` + +1. Use newline at the end of a file (EOF). + +## Doctype + +Always use the minimal doctype + +```php + +``` + + +## Capitalisation +All HTML should be lowercase; element names, attributes, attribute values +(unless text/CDATA), CSS selectors, properties, and property values (except of strings). +Additionally, there is no need to use CDATA to escape inline JavaScript, formerly a +requirement to meet XML strictness in XHTML. + +## Documentation headers +Documentation headers for PHP code in: files, classes, class properties, methods and functions, called the **docblocks**. +The file header DocBlock consists of the following required and optional elements in +the following order: + +- @version (optional and must be first) +- @category (optional and rarely used) +- @package (generally optional but required when files contain only procedural code. + Always optional in namespaced code) +- @subpackage (optional) +- @author (optional but only permitted in non-Joomla sources files) +- @copyright (required) +- @license (required and must be compatible with the Joomla license) +- @link(optional) +- @see (optional) +- @since (generally optional but required when files contain only procedural code) +- @deprecated (optional) + +```php +/** +* @package Depot.Administrator +* @subpackage com_depot +* @author Thomas Kuschel +* @copyright (C) 2023 KW4NZ, +* @license GNU General Public License version 2 or later; see LICENSE.txt +* @since 0.1 +``` + +## PHP code +Use the full `` to delimit PHP code. Since PHP8.0, the short tag `` is obsolete and removed. + +For files that contain only PHP code, the closing tag (`?>`) should not be included. +It is not required by PHP. Leaving this out prevents trailing white space from being +accidentally injected into the output that can introduce errors. + +PHP includes a short tag `

Welcome

+``` +is equivalent and more readable than: + +```php +

Welcome

+``` + +### Including code +Anywhere you are unconditionally including a file, use **require_once**. +Anywhere you are conditionally including a file (for example, factory mathods), +use **include_once**. Either of these will ensure that files are included only +once. You should not enclose the filename in parentheses. + +```php +require_once JPATH_COMPONENT_ADMINISTRATOR . '/Helper/InstallerHelper.php'; +``` + +### Global variables +Global variables should not be used. Use static class properties or constants +instead of globals, following OOP and factory patterns. + +### Control structures +For all control structures there is a space between the keyword and an opening +paranthesis, then no space either after the opening parenthesis or before the +closing bracking. This is done to distinguish control keywords from function names. +All control structures must contain their logic within braces. + +### Concatenation spacing +There should always be a space before and after the concatenation operator `('.')` because +of readablity. + +### Constants +Constants should always be all-uppercase, with underscores to separate words. + +### Namespaces + +Namespaces are formatted according to this flow: First there is the file docblock followed by the namespace the file lives in. When required, the namespace is followed by the defined check. Lastly, the imported classes using the use keyword. All namespace imports should be alphabetically ordered. + +### Function Calls + +Functions should be called with no spaces between the function name and the opening parenthesis, and no space between this and the first parameter; a space after the comma between each parameter (if they are present), and no space between the last parameter and the closing parenthesis. There should be space before and exactly one space after the equals sign. diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..d141248 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,361 @@ +# GNU GENERAL PUBLIC LICENSE + +Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +## Preamble + +The licenses for most software are designed to take away your freedom +to share and change it. By contrast, the GNU General Public License is +intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + +When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + +To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if +you distribute copies of the software, or if you modify it. + +For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + +We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + +Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, +we want its recipients to know that what they have is not the +original, so that any problems introduced by others will not reflect +on the original authors' reputations. + +Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at +all. + +The precise terms and conditions for copying, distribution and +modification follow. + +## TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + +**0.** This License applies to any program or other work which +contains a notice placed by the copyright holder saying it may be +distributed under the terms of this General Public License. The +"Program", below, refers to any such program or work, and a "work +based on the Program" means either the Program or any derivative work +under copyright law: that is to say, a work containing the Program or +a portion of it, either verbatim or with modifications and/or +translated into another language. (Hereinafter, translation is +included without limitation in the term "modification".) Each licensee +is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the Program +(independent of having been made by running the Program). Whether that +is true depends on what the Program does. + +**1.** You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a +fee. + +**2.** You may modify your copy or copies of the Program or any +portion of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + +**a)** You must cause the modified files to carry prominent notices +stating that you changed the files and the date of any change. + + +**b)** You must cause any work that you distribute or publish, that in +whole or in part contains or is derived from the Program or any part +thereof, to be licensed as a whole at no charge to all third parties +under the terms of this License. + + +**c)** If the modified program normally reads commands interactively +when run, you must cause it, when started running for such interactive +use in the most ordinary way, to print or display an announcement +including an appropriate copyright notice and a notice that there is +no warranty (or else, saying that you provide a warranty) and that +users may redistribute the program under these conditions, and telling +the user how to view a copy of this License. (Exception: if the +Program itself is interactive but does not normally print such an +announcement, your work based on the Program is not required to print +an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + +**3.** You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + +**a)** Accompany it with the complete corresponding machine-readable +source code, which must be distributed under the terms of Sections 1 +and 2 above on a medium customarily used for software interchange; or, + + +**b)** Accompany it with a written offer, valid for at least three +years, to give any third party, for a charge no more than your cost of +physically performing source distribution, a complete machine-readable +copy of the corresponding source code, to be distributed under the +terms of Sections 1 and 2 above on a medium customarily used for +software interchange; or, + + +**c)** Accompany it with the information you received as to the offer +to distribute corresponding source code. (This alternative is allowed +only for noncommercial distribution and only if you received the +program in object code or executable form with such an offer, in +accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + +**4.** You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt otherwise +to copy, modify, sublicense or distribute the Program is void, and +will automatically terminate your rights under this License. However, +parties who have received copies, or rights, from you under this +License will not have their licenses terminated so long as such +parties remain in full compliance. + +**5.** You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + +**6.** Each time you redistribute the Program (or any work based on +the Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + +**7.** If, as a consequence of a court judgment or allegation of +patent infringement or for any other reason (not limited to patent +issues), conditions are imposed on you (whether by court order, +agreement or otherwise) that contradict the conditions of this +License, they do not excuse you from the conditions of this License. +If you cannot distribute so as to satisfy simultaneously your +obligations under this License and any other pertinent obligations, +then as a consequence you may not distribute the Program at all. For +example, if a patent license would not permit royalty-free +redistribution of the Program by all those who receive copies directly +or indirectly through you, then the only way you could satisfy both it +and this License would be to refrain entirely from distribution of the +Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + +**8.** If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + +**9.** The Free Software Foundation may publish revised and/or new +versions of the General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Program does not specify a +version number of this License, you may choose any version ever +published by the Free Software Foundation. + +**10.** If you wish to incorporate parts of the Program into other +free programs whose distribution conditions are different, write to +the author to ask for permission. For software which is copyrighted by +the Free Software Foundation, write to the Free Software Foundation; +we sometimes make exceptions for this. Our decision will be guided by +the two goals of preserving the free status of all derivatives of our +free software and of promoting the sharing and reuse of software +generally. + +**NO WARRANTY** + +**11.** BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + +**12.** IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + +END OF TERMS AND CONDITIONS + +## How to Apply These Terms to Your New Programs + +If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these +terms. + +To do so, attach the following notices to the program. It is safest to +attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + one line to give the program's name and an idea of what it does. + Copyright (C) yyyy name of author + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +Also add information on how to contact you by electronic and paper +mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details + type `show w'. This is free software, and you are welcome + to redistribute it under certain conditions; type `show c' + for details. + +The hypothetical commands \`show w' and \`show c' should show the +appropriate parts of the General Public License. Of course, the +commands you use may be called something other than \`show w' and +\`show c'; they could even be mouse-clicks or menu items--whatever +suits your program. + +You should also get your employer (if you work as a programmer) or +your school, if any, to sign a "copyright disclaimer" for the program, +if necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright + interest in the program `Gnomovision' + (which makes passes at compilers) written + by James Hacker. + + signature of Ty Coon, 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, +you may consider it more useful to permit linking proprietary +applications with the library. If this is what you want to do, use the +[GNU Lesser General Public +License](https://www.gnu.org/licenses/lgpl.html) instead of this +License. diff --git a/README.md b/README.md new file mode 100644 index 0000000..1a261cc --- /dev/null +++ b/README.md @@ -0,0 +1,114 @@ +# Depot + +## Introduction + +This project is also based on the desperation to sort and find my electronic +components. Some integrated circuits (ICs) accumulated in various boxes and +the question of whether I own that or the other IC, had to be painstakingly +researched. Above all, there were at one time several places where components +were stored or partly kept at a plant. +The idea was born, but it took long time to implement it. +Klosterneuburg, October 2023 Thomas Kuschel KW4NZ. + +## Workflow (since 0.0.1) + +In git we start to make a new branch named b1_basic_backend, where we start +developing our project. The first run with simply renaming entries from a +copy of the component **com_banners** did not work as expected. +So let us start at the very beginning: + +### Adding basic files for component (b1_basic_backend) + +With the git branch **b1_basic_backend** +Add the following basic six files: + +1. admin + + - src/Extension/DepotComponent.php: The main extension file for the component. + - services/provider.php: It tells Joomla how to initialize or boot the component. + - src/Controller/DisplayController.php: The default Controller for the component. + - src/View/Parts/HtmlView.php: The Html View for the "Parts" page. + - tmpl/parts/default.php: The layout file for the "Parts" page. + +2. depot.xml: XML manifest file that tells Joomla! how to install the component. + +#### Description of each file: + +##### 1. DepotComponent.php +This file contains class for the extension. The class extends MVCComponent. + +##### 2. provider.php +This is a special file that tells Joomla how to initialize the component - which +services it requires and how they should be provided. + +The service provider file registers dependencies the component will use. +Here, we have included two dependencies: + +- **DispatcherFactory** is needed to create the Dispatcher class instance, + and then Joomla will call dispatch() on this Dispatcher object, as the + next step in running the component. + +- **MVCFactory** is needed to create the Controller, View, Model and Table class + instances on behalf of the component. + + +##### 3. DisplayController.php +This is a **default controller** for the component. It simply sets its default +view and leaves the rest to its parent. + +When you view the component through URL, Joomla uses the **controller** to execute +the **task**. The task is the name of method in the controller file. +If you do not pass the controller or task in the URL, it defaults to Display +Controller and display Task. + +The default view is the name of the component. So, here we need to override the +default view to `parts`. + +##### 4. HtmlView.php +This file contains class HtmlView that extends BaseHtmlView. The BaseHtmlView is +the base class for a Joomla View. + +The **view gets the data from the model to be output by the layout file.** + +For example: +```php +$this->msg = $this->get('Msg'); +``` + +This method converts the get('Msg') call into a getMsg() call on the model, which +is the method which you have to provide in the model. + +The view file displays data using the template layout file - $tpl, which defaults +to default.php. + +##### 5. default.php +This file holds the template for the page. When no specific layout is +requested for a view, Joomla will load the template in the **default.php** file. + +```php +

Welcome to Depot Component!

+``` + +##### 6. depot.xml +This file tells Joomla how to install the component and what file are included. + +In the administration part, we include a link to the menu and include files +and folders (services, src, tmpl and so on) which are in the parent folder +admin of the component. While installing the component, these will get copied +to the Joomla administrator/components/com_depot. + +#### Installation the component +Create a **.zip** file of the com_depot directory. Then inside the Joomla +Administration upload this .zip package. + +Now you should see a new link "Depot" in the "Compnents" section of the menu. +If you click it, you should see the default "Depot" page. + +#### Language files +We create two language files for the system and the component **Depot** at +the directory /admin/language/en-GB/ naming it + +- com_depot.ini +- com_depot.sys.ini + +--- diff --git a/admin/language/en-GB/com_depot.ini b/admin/language/en-GB/com_depot.ini new file mode 100644 index 0000000..e9247b5 --- /dev/null +++ b/admin/language/en-GB/com_depot.ini @@ -0,0 +1,8 @@ +; @package Depot.Language +; @subpackage com_depot +; @author Thomas Kuschel +; @copyright (C) 2023 KW4NZ, +; @license GNU General Public License version 2 or later; see LICENSE.md +; @since 0.0.1 +; +COM_DEPOT_XML_DESCRIPTION="Depot, the component warehouse" diff --git a/admin/language/en-GB/com_depot.sys.ini b/admin/language/en-GB/com_depot.sys.ini new file mode 100644 index 0000000..8ba79ec --- /dev/null +++ b/admin/language/en-GB/com_depot.sys.ini @@ -0,0 +1,11 @@ +; @package Depot.Language +; @subpackage com_depot +; @author Thomas Kuschel +; @copyright (C) 2023 KW4NZ, +; @license GNU General Public License version 2 or later; see LICENSE.md +; @since 0.0.1 +; +COM_DEPOT_MENU="Depot" +COM_DEPOT_MENU_MANUFACTURERS="Manufacturers" +COM_DEPOT_MENU_STOCKS="Stock locations" +COM_DEPOT_XML_DESCRIPTION="Depot, the component warehouse" diff --git a/admin/services/provider.php b/admin/services/provider.php new file mode 100644 index 0000000..9e9328c --- /dev/null +++ b/admin/services/provider.php @@ -0,0 +1,39 @@ + + * @copyright (C) 2023 KW4NZ, + * @license GNU General Public License version 2 or later; see LICENSE.md + * @since 0.0.1 + */ + +use Joomla\CMS\Dispatcher\ComponentDispatcherFactoryInterface; +use Joomla\CMS\Extension\ComponentInterface; +use Joomla\CMS\Extension\Service\Provider\ComponentDispatcherFactory; +use Joomla\CMS\Extension\Service\Provider\MVCFactory; +use Joomla\CMS\MVC\Factory\MVCFactoryInterface; +use Joomla\DI\Container; +use Joomla\DI\ServiceProviderInterface; +use KW4NZ\Component\Depot\Administrator\Extension\DepotComponent; +use Joomla\CMS\Extension\MVCComponent; + +return new class implements ServiceProviderInterface +{ + public function register(Container $container) + { + $container->registerServiceProvider(new ComponentDispatcherFactory('\\KW4NZ\\Component\\Depot')); + $container->registerServiceProvider(new MVCFactory('\\KW4NZ\\Component\\Depot')); + + $container->set( + ComponentInterface::class, + function (Container $container) + { + $component = new DepotComponent($container->get(ComponentDispatcherFactoryInterface::class)); + $component->setMVCFactory($container->get(MVCFactoryInterface::class)); + + return $component; + } + ); + } +}; diff --git a/admin/sql/install.mysql.utf8.sql b/admin/sql/install.mysql.utf8.sql new file mode 100644 index 0000000..796913a --- /dev/null +++ b/admin/sql/install.mysql.utf8.sql @@ -0,0 +1,49 @@ +-- @package Depot.SQL MariaDB +-- @subpackage com_depot +-- @author Thomas Kuschel +-- @copyright (C) 2023 KW4NZ, +-- @license GNU General Public License version 2 or later; see LICENSE.md +-- @since 0.0.1 + +DROP TABLE IF EXISTS `#__depot`; +CREATE TABLE `#__depot`( + `id` SERIAL, + `component_name` VARCHAR(1024) CHARACTER SET ascii COLLATE ascii_general_ci NULL DEFAULT NULL + COMMENT 'unique component name (ASCII characters only)', + `alias` VARCHAR(1024) NOT NULL DEFAULT '', + `description` VARCHAR(4000) NOT NULL DEFAULT '', + `quantity` INT(10) UNSIGNED NOT NULL DEFAULT 0, + `quantity_exp` INT(11) NOT NULL DEFAULT 0 COMMENT 'Exponent of the quantity (10^x of the number, usually 0 i.e. 10⁰)', + `asset_id` INT(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'FK to the #__assets table.', + `created` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', + `created_by` INT(10) UNSIGNED NOT NULL DEFAULT 0, + `checked_out` INT(11) NOT NULL DEFAULT 0, + `checked_out_time` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', + `modified` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', + `modified_by` INT(10) UNSIGNED NOT NULL DEFAULT 0, + `path` VARCHAR(400) NOT NULL DEFAULT '', + `state` TINYINT(4) NOT NULL DEFAULT 0 COMMENT 'Published=1,Unpublished=0,Archived=2,Trashed=-2', + `access` TINYINT(4) NOT NULL DEFAULT 0, + `params` VARCHAR(1024) NOT NULL DEFAULT '', + `image` VARCHAR(1024) NOT NULL DEFAULT '', + `ordering` INT(11) NOT NULL DEFAULT 0, + `version` int unsigned NOT NULL DEFAULT 1, + -- references to other tables: + `category_id` INT(11) NOT NULL DEFAULT 0, + `datasheet_id` INT(11) NOT NULL DEFAULT 0, + `datasheet_alt` VARCHAR(1024) NOT NULL DEFAULT '', + `manufacturer_id` INT(11) NOT NULL DEFAULT 0, + `stock_id` INT(11) NOT NULL DEFAULT 0, + PRIMARY KEY (`id`), + KEY `idx_state` (`state`), + KEY `idx_stock_id` (`stock_id`), + KEY `idx_manufacturer` (`manufacturer_id`), + UNIQUE KEY `aliasindex` (`alias`,`manufacturer_id`,`stock_id`) +) ENGINE=InnoDB + AUTO_INCREMENT=0 + DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +INSERT INTO `#__depot` (`component_name`,`alias`,`description`,`quantity`,`created`, + `ordering`,`state`,`manufacturer_id`) VALUES + ('1N5404','1n5404','diode, rectifier 3A',9,'2023-09-25 15:00:00',1,1,1), + ('1N4148','1n4148','diode, general purpose',1234,'2023-09-25 15:15:15',2,1,2); diff --git a/admin/sql/uninstall.mysql.utf8.sql b/admin/sql/uninstall.mysql.utf8.sql new file mode 100644 index 0000000..5fc1695 --- /dev/null +++ b/admin/sql/uninstall.mysql.utf8.sql @@ -0,0 +1,8 @@ +-- @package Depot.Language +-- @subpackage com_depot +-- @author Thomas Kuschel +-- @copyright (C) 2023 KW4NZ, +-- @license GNU General Public License version 2 or later; see LICENSE.md +-- @since 0.0.1 + +DROP TABLE IF EXISTS `#__depot`; diff --git a/admin/src/Controller/DisplayController.php b/admin/src/Controller/DisplayController.php new file mode 100644 index 0000000..20fed80 --- /dev/null +++ b/admin/src/Controller/DisplayController.php @@ -0,0 +1,20 @@ + + * @copyright (C) 2023 KW4NZ, + * @license GNU General Public License version 2 or later; see LICENSE.md + * @since 0.0.1 + */ + +namespace KW4NZ\Component\Depot\Administrator\Controller; + +defined('_JEXEC') or die; + +use Joomla\CMS\MVC\Controller\BaseController; + +class DisplayController extends BaseController +{ + protected $default_view = 'parts'; +} diff --git a/admin/src/Extension/DepotComponent.php b/admin/src/Extension/DepotComponent.php new file mode 100644 index 0000000..2a25aec --- /dev/null +++ b/admin/src/Extension/DepotComponent.php @@ -0,0 +1,18 @@ + + * @copyright (C) 2023 KW4NZ, + * @license GNU General Public License version 2 or later; see LICENSE.md + * @since 0.0.1 + */ + +namespace KW4NZ\Component\Depot\Administrator\Extension; + +use Joomla\CMS\Extension\MVCComponent; + +class DepotComponent extends MVCComponent +{ + +} diff --git a/admin/src/View/Parts/HtmlView.php b/admin/src/View/Parts/HtmlView.php new file mode 100644 index 0000000..dbdb46a --- /dev/null +++ b/admin/src/View/Parts/HtmlView.php @@ -0,0 +1,23 @@ + +* @copyright (C) 2023 KW4NZ, +* @license GNU General Public License version 2 or later; see LICENSE.md +* @since 0.0.1 +*/ + +namespace KW4NZ\Component\Depot\Administrator\View\Parts; + +defined('_JEXEC') or die; + +use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; + +class HtmlView extends BaseHtmlView +{ + public function display($tpl = null) + { + parent::display($tpl); + } +} diff --git a/admin/tmpl/parts/default.php b/admin/tmpl/parts/default.php new file mode 100644 index 0000000..dce9a82 --- /dev/null +++ b/admin/tmpl/parts/default.php @@ -0,0 +1,11 @@ + + * @copyright (C) 2023 KW4NZ, + * @license GNU General Public License version 2 or later; see LICENSE.md + * @since 0.0.1 + */ +?> +

Welcome to my Depot Component!

diff --git a/depot.xml b/depot.xml new file mode 100644 index 0000000..d733e84 --- /dev/null +++ b/depot.xml @@ -0,0 +1,48 @@ + + + Depot + KW4NZ + 2023-10-02 + (C) KW4NZ Thomas Kuschel + GPL v2 +; see LICENSE.md + thomas@kuschel.at + https://kuschel.at + 0.0.1 + COM_DEPOT_XML_DESCRIPTION + KW4NZ\Component\Depot + + CODING_STANDARDS.md + LICENSE.md + README.md + + + + COM_DEPOT_MENU + + COM_DEPOT_MENU + + + services + sql + src + tmpl + + + en-GB/com_depot.ini + en-GB/com_depot.sys.ini + + + + + sql/install.mysql.utf8.sql + + + + + sql/uninstall.mysql.utf8.sql + + +