update 2023-07-19 17:32:44
This commit is contained in:
parent
73c4c18371
commit
8ae2c13ad5
@ -29,7 +29,11 @@ This repository contains an index (see below) of all the approved powers within
|
||||
- **abstract class Openai** | [Details](src/f722bb8b-d377-4425-b1e4-2fe1734a3664) | [Code](src/f722bb8b-d377-4425-b1e4-2fe1734a3664/code.php) | [Settings](src/f722bb8b-d377-4425-b1e4-2fe1734a3664/settings.json) | Super__f722bb8b_d377_4425_b1e4_2fe1734a3664__Power
|
||||
- **final class AI** | [Details](src/f3757646-bc63-4f11-98c1-a2663180ab5e) | [Code](src/f3757646-bc63-4f11-98c1-a2663180ab5e/code.php) | [Settings](src/f3757646-bc63-4f11-98c1-a2663180ab5e/settings.json) | Super__f3757646_bc63_4f11_98c1_a2663180ab5e__Power
|
||||
- **final class DailyScripture** | [Details](src/90f2ee7a-c041-4316-ad54-af4f97fa3003) | [Code](src/90f2ee7a-c041-4316-ad54-af4f97fa3003/code.php) | [Settings](src/90f2ee7a-c041-4316-ad54-af4f97fa3003/settings.json) | Super__90f2ee7a_c041_4316_ad54_af4f97fa3003__Power
|
||||
- **final class Linker** | [Details](src/36ab759f-7b42-4465-9c17-56ba1dd05f90) | [Code](src/36ab759f-7b42-4465-9c17-56ba1dd05f90/code.php) | [Settings](src/36ab759f-7b42-4465-9c17-56ba1dd05f90/settings.json) | Super__36ab759f_7b42_4465_9c17_56ba1dd05f90__Power
|
||||
- **final class Note** | [Details](src/ebda6bd8-95b9-468b-a521-974205146018) | [Code](src/ebda6bd8-95b9-468b-a521-974205146018/code.php) | [Settings](src/ebda6bd8-95b9-468b-a521-974205146018/settings.json) | Super__ebda6bd8_95b9_468b_a521_974205146018__Power
|
||||
- **final class Search** | [Details](src/8336e3c4-f11b-41bc-a2b1-976f99442a84) | [Code](src/8336e3c4-f11b-41bc-a2b1-976f99442a84/code.php) | [Settings](src/8336e3c4-f11b-41bc-a2b1-976f99442a84/settings.json) | Super__8336e3c4_f11b_41bc_a2b1_976f99442a84__Power
|
||||
- **final class Tag** | [Details](src/67f91b8b-7b48-4dbb-bbd5-7945c174622a) | [Code](src/67f91b8b-7b48-4dbb-bbd5-7945c174622a/code.php) | [Settings](src/67f91b8b-7b48-4dbb-bbd5-7945c174622a/settings.json) | Super__67f91b8b_7b48_4dbb_bbd5_7945c174622a__Power
|
||||
- **final class Tagged** | [Details](src/2315a1c5-bcf6-401a-8d11-60f4d6d12dbb) | [Code](src/2315a1c5-bcf6-401a-8d11-60f4d6d12dbb/code.php) | [Settings](src/2315a1c5-bcf6-401a-8d11-60f4d6d12dbb/settings.json) | Super__2315a1c5_bcf6_401a_8d11_60f4d6d12dbb__Power
|
||||
- **final class Watcher** | [Details](src/f815fb33-f721-48a5-a84e-53f1986e8881) | [Code](src/f815fb33-f721-48a5-a84e-53f1986e8881/code.php) | [Settings](src/f815fb33-f721-48a5-a84e-53f1986e8881/settings.json) | Super__f815fb33_f721_48a5_a84e_53f1986e8881__Power
|
||||
- **class Config** | [Details](src/71075f03-4e77-4fc0-840a-ef55fd9260b2) | [Code](src/71075f03-4e77-4fc0-840a-ef55fd9260b2/code.php) | [Settings](src/71075f03-4e77-4fc0-840a-ef55fd9260b2/settings.json) | Super__71075f03_4e77_4fc0_840a_ef55fd9260b2__Power
|
||||
- **class Table** | [Details](src/ff8d5fdb-2d1f-4178-bd18-a43b8efd1068) | [Code](src/ff8d5fdb-2d1f-4178-bd18-a43b8efd1068/code.php) | [Settings](src/ff8d5fdb-2d1f-4178-bd18-a43b8efd1068/settings.json) | Super__ff8d5fdb_2d1f_4178_bd18_a43b8efd1068__Power
|
||||
|
101
src/2315a1c5-bcf6-401a-8d11-60f4d6d12dbb/README.md
Normal file
101
src/2315a1c5-bcf6-401a-8d11-60f4d6d12dbb/README.md
Normal file
@ -0,0 +1,101 @@
|
||||
```
|
||||
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
|
||||
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
|
||||
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
|
||||
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
|
||||
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
|
||||
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
|
||||
```
|
||||
# final class Tagged (Details)
|
||||
> namespace: **VDM\Joomla\GetBible**
|
||||
```uml
|
||||
@startuml
|
||||
class Tagged << (F,LightGreen) >> #Green {
|
||||
# Load $load
|
||||
# Insert $insert
|
||||
# Update $update
|
||||
# Linker $linker
|
||||
+ __construct(Load $load, Insert $insert, ...)
|
||||
+ set(string $translation, int $book, ...) : ?array
|
||||
+ delete(string $tag) : bool
|
||||
- get(string $linker, string $translation, ...) : ?array
|
||||
- create(string $linker, string $translation, ...) : bool
|
||||
}
|
||||
|
||||
note right of Tagged::__construct
|
||||
Constructor
|
||||
|
||||
since: 2.0.1
|
||||
|
||||
arguments:
|
||||
Load $load
|
||||
Insert $insert
|
||||
Update $update
|
||||
Linker $linker
|
||||
end note
|
||||
|
||||
note right of Tagged::set
|
||||
Set a tagged verse
|
||||
|
||||
since: 2.0.1
|
||||
return: ?array
|
||||
|
||||
arguments:
|
||||
string $translation
|
||||
int $book
|
||||
int $chapter
|
||||
int $verse
|
||||
string $tag
|
||||
end note
|
||||
|
||||
note right of Tagged::delete
|
||||
Delete a tagged verse
|
||||
|
||||
since: 2.0.1
|
||||
return: bool
|
||||
end note
|
||||
|
||||
note right of Tagged::get
|
||||
Get a tagged verse
|
||||
|
||||
since: 2.0.1
|
||||
return: ?array
|
||||
|
||||
arguments:
|
||||
string $linker
|
||||
string $translation
|
||||
int $book
|
||||
int $chapter
|
||||
int $verse
|
||||
string $tag
|
||||
end note
|
||||
|
||||
note right of Tagged::create
|
||||
Create a Tagged verse
|
||||
|
||||
since: 2.0.1
|
||||
return: bool
|
||||
|
||||
arguments:
|
||||
string $linker
|
||||
string $translation
|
||||
int $book
|
||||
int $chapter
|
||||
int $verse
|
||||
string $tag
|
||||
end note
|
||||
|
||||
@enduml
|
||||
```
|
||||
|
||||
---
|
||||
```
|
||||
██╗ ██████╗██████╗
|
||||
██║██╔════╝██╔══██╗
|
||||
██║██║ ██████╔╝
|
||||
██ ██║██║ ██╔══██╗
|
||||
╚█████╔╝╚██████╗██████╔╝
|
||||
╚════╝ ╚═════╝╚═════╝
|
||||
```
|
||||
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)
|
||||
|
252
src/2315a1c5-bcf6-401a-8d11-60f4d6d12dbb/code.php
Normal file
252
src/2315a1c5-bcf6-401a-8d11-60f4d6d12dbb/code.php
Normal file
@ -0,0 +1,252 @@
|
||||
<?php
|
||||
/**
|
||||
* @package GetBible
|
||||
*
|
||||
* @created 30th May, 2023
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git GetBible <https://git.vdm.dev/getBible>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\GetBible;
|
||||
|
||||
|
||||
use Joomla\CMS\Language\Text;
|
||||
use VDM\Joomla\GetBible\Database\Load;
|
||||
use VDM\Joomla\GetBible\Database\Insert;
|
||||
use VDM\Joomla\GetBible\Database\Update;
|
||||
use VDM\Joomla\GetBible\Linker;
|
||||
use VDM\Joomla\Utilities\GuidHelper;
|
||||
|
||||
|
||||
/**
|
||||
* The GetBible Tagged
|
||||
*
|
||||
* @since 2.0.1
|
||||
*/
|
||||
final class Tagged
|
||||
{
|
||||
/**
|
||||
* The Load class
|
||||
*
|
||||
* @var Load
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Load $load;
|
||||
|
||||
/**
|
||||
* The Insert class
|
||||
*
|
||||
* @var Insert
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Insert $insert;
|
||||
|
||||
/**
|
||||
* The Update class
|
||||
*
|
||||
* @var Update
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Update $update;
|
||||
|
||||
/**
|
||||
* The Linker class
|
||||
*
|
||||
* @var Linker
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Linker $linker;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Load $load The load object.
|
||||
* @param Insert $insert The insert object.
|
||||
* @param Update $update The update object.
|
||||
* @param Linker $linker The linker object.
|
||||
*
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function __construct(
|
||||
Load $load,
|
||||
Insert $insert,
|
||||
Update $update,
|
||||
Linker $linker)
|
||||
{
|
||||
$this->load = $load;
|
||||
$this->insert = $insert;
|
||||
$this->update = $update;
|
||||
$this->linker = $linker;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a tagged verse
|
||||
*
|
||||
* @param string $translation The translation in which the note is made
|
||||
* @param int $book The book in which the note is made
|
||||
* @param int $chapter The chapter in which the note is made
|
||||
* @param int $verse The verse where the note is made
|
||||
* @param string $tag The tag being added
|
||||
*
|
||||
* @return array|null Array of the tagged values on success
|
||||
* @since 2.0.1
|
||||
**/
|
||||
public function set(
|
||||
string $translation,
|
||||
int $book,
|
||||
int $chapter,
|
||||
int $verse,
|
||||
string $tag
|
||||
): ?array
|
||||
{
|
||||
// make sure the linker has access
|
||||
if (($linker = $this->linker->get()) === null)
|
||||
{
|
||||
return [
|
||||
'error' => Text::_('COM_GETBIBLE_YOU_DO_NOT_HAVE_ACCESS_TO_PERFORM_THIS_ACTION'),
|
||||
'function' => 'setLinkerAccess'
|
||||
];
|
||||
}
|
||||
|
||||
// make sure the tag is active
|
||||
if (($published = GuidHelper::item($tag, 'tag', 'a.published', 'getbible')) === null
|
||||
|| $published != 1)
|
||||
{
|
||||
return [
|
||||
'error' => Text::_('COM_GETBIBLE_THE_TAG_SELECTED_IS_NOT_ACTIVE_PLEASE_SELECT_AN_ACTIVE_TAG')
|
||||
];
|
||||
}
|
||||
|
||||
// get tag if it exist
|
||||
if (($_tag = $this->get($linker, $translation, $book, $chapter, $verse, $tag)) !== null)
|
||||
{
|
||||
// publish if not published
|
||||
if ($_tag->published != 1 && !$this->update->value(1, 'published', $_tag->id, 'id', 'tagged_verse'))
|
||||
{
|
||||
return [
|
||||
'error' => Text::_('COM_GETBIBLE_TAGGED_VERSE_ALREADY_EXIST_BUT_COULD_NOT_BE_REACTIVATED')
|
||||
];
|
||||
}
|
||||
|
||||
$_tag->published = 1;
|
||||
$_tag->success = Text::_('COM_GETBIBLE_THE_VERSE_WAS_SUCCESSFULLY_TAGGED');
|
||||
return (array) $_tag;
|
||||
}
|
||||
// create a new tag
|
||||
elseif ($this->create($linker, $translation, $book, $chapter, $verse, $tag)
|
||||
&& ($_tag = $this->get($linker, $translation, $book, $chapter, $verse, $tag)) !== null)
|
||||
{
|
||||
$_tag->success = Text::_('COM_GETBIBLE_THE_VERSE_WAS_SUCCESSFULLY_TAGGED');
|
||||
return (array) $_tag;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a tagged verse
|
||||
*
|
||||
* @param string $tag The tagged verse GUID value
|
||||
*
|
||||
* @return bool True on success
|
||||
* @since 2.0.1
|
||||
**/
|
||||
public function delete(string $tag): bool
|
||||
{
|
||||
// make sure the linker has access
|
||||
if (($linker = $this->linker->get()) === null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// make sure the linker has access to delete this tag
|
||||
if (($id = $this->load->value(['guid' => $tag, 'linker' => $linker], 'id', 'tagged_verse')) !== null && $id > 0)
|
||||
{
|
||||
return $this->update->value(-2, 'published', $id, 'id', 'tagged_verse');
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a tagged verse
|
||||
*
|
||||
* @param string $linker The linker GUID value
|
||||
* @param string $translation The translation in which the note is made
|
||||
* @param int $book The book in which the note is made
|
||||
* @param int $chapter The chapter in which the note is made
|
||||
* @param int $verse The verse where the note is made
|
||||
* @param string $tag The tag being added
|
||||
*
|
||||
* @return array|null Array of the tagged verse values on success
|
||||
* @since 2.0.1
|
||||
**/
|
||||
private function get(
|
||||
string $linker,
|
||||
string $translation,
|
||||
int $book,
|
||||
int $chapter,
|
||||
int $verse,
|
||||
string $tag
|
||||
): ?array
|
||||
{
|
||||
// get tag if it exist
|
||||
if (($_tag = $this->load->item([
|
||||
'linker' => $linker,
|
||||
'translation' => $translation,
|
||||
'book' => $book,
|
||||
'chapter' => $chapter,
|
||||
'verse' => $verse,
|
||||
'tag' => $tag
|
||||
], 'tagged_verse')) !== null)
|
||||
{
|
||||
return $_tag;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Tagged verse
|
||||
*
|
||||
* @param string $linker The linker GUID value
|
||||
* @param string $translation The translation in which the note is made
|
||||
* @param int $book The book in which the note is made
|
||||
* @param int $chapter The chapter in which the note is made
|
||||
* @param int $verse The verse where the note is made
|
||||
* @param string $tag The tag being added
|
||||
*
|
||||
* @return bool True on success
|
||||
* @since 2.0.1
|
||||
**/
|
||||
private function create(
|
||||
string $linker,
|
||||
string $translation,
|
||||
int $book,
|
||||
int $chapter,
|
||||
int $verse,
|
||||
string $tag
|
||||
): bool
|
||||
{
|
||||
$guid = (string) GuidHelper::get();
|
||||
while (!GuidHelper::valid($guid, 'tagged_verse', 0, 'getbible'))
|
||||
{
|
||||
// must always be set
|
||||
$guid = (string) GuidHelper::get();
|
||||
}
|
||||
|
||||
return $this->insert->row([
|
||||
'tag' => $tag,
|
||||
'access' => 0,
|
||||
'linker' => $linker,
|
||||
'translation' => $translation,
|
||||
'book' => $book,
|
||||
'chapter' => $chapter,
|
||||
'verse' => $verse,
|
||||
'guid' => $guid
|
||||
], 'tagged_verse');
|
||||
}
|
||||
}
|
||||
|
221
src/2315a1c5-bcf6-401a-8d11-60f4d6d12dbb/code.power
Normal file
221
src/2315a1c5-bcf6-401a-8d11-60f4d6d12dbb/code.power
Normal file
@ -0,0 +1,221 @@
|
||||
/**
|
||||
* The Load class
|
||||
*
|
||||
* @var Load
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Load $load;
|
||||
|
||||
/**
|
||||
* The Insert class
|
||||
*
|
||||
* @var Insert
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Insert $insert;
|
||||
|
||||
/**
|
||||
* The Update class
|
||||
*
|
||||
* @var Update
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Update $update;
|
||||
|
||||
/**
|
||||
* The Linker class
|
||||
*
|
||||
* @var Linker
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Linker $linker;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Load $load The load object.
|
||||
* @param Insert $insert The insert object.
|
||||
* @param Update $update The update object.
|
||||
* @param Linker $linker The linker object.
|
||||
*
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function __construct(
|
||||
Load $load,
|
||||
Insert $insert,
|
||||
Update $update,
|
||||
Linker $linker)
|
||||
{
|
||||
$this->load = $load;
|
||||
$this->insert = $insert;
|
||||
$this->update = $update;
|
||||
$this->linker = $linker;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a tagged verse
|
||||
*
|
||||
* @param string $translation The translation in which the note is made
|
||||
* @param int $book The book in which the note is made
|
||||
* @param int $chapter The chapter in which the note is made
|
||||
* @param int $verse The verse where the note is made
|
||||
* @param string $tag The tag being added
|
||||
*
|
||||
* @return array|null Array of the tagged values on success
|
||||
* @since 2.0.1
|
||||
**/
|
||||
public function set(
|
||||
string $translation,
|
||||
int $book,
|
||||
int $chapter,
|
||||
int $verse,
|
||||
string $tag
|
||||
): ?array
|
||||
{
|
||||
// make sure the linker has access
|
||||
if (($linker = $this->linker->get()) === null)
|
||||
{
|
||||
return [
|
||||
'error' => Text::_('You do not have access to perform this action'),
|
||||
'function' => 'setLinkerAccess'
|
||||
];
|
||||
}
|
||||
|
||||
// make sure the tag is active
|
||||
if (($published = GuidHelper::item($tag, 'tag', 'a.published', '[[[component]]]')) === null
|
||||
|| $published != 1)
|
||||
{
|
||||
return [
|
||||
'error' => Text::_('The tag selected is not active, please select an active tag.')
|
||||
];
|
||||
}
|
||||
|
||||
// get tag if it exist
|
||||
if (($_tag = $this->get($linker, $translation, $book, $chapter, $verse, $tag)) !== null)
|
||||
{
|
||||
// publish if not published
|
||||
if ($_tag->published != 1 && !$this->update->value(1, 'published', $_tag->id, 'id', 'tagged_verse'))
|
||||
{
|
||||
return [
|
||||
'error' => Text::_('Tagged verse already exist, but could not be reactivated.')
|
||||
];
|
||||
}
|
||||
|
||||
$_tag->published = 1;
|
||||
$_tag->success = Text::_('The verse was successfully tagged.');
|
||||
return (array) $_tag;
|
||||
}
|
||||
// create a new tag
|
||||
elseif ($this->create($linker, $translation, $book, $chapter, $verse, $tag)
|
||||
&& ($_tag = $this->get($linker, $translation, $book, $chapter, $verse, $tag)) !== null)
|
||||
{
|
||||
$_tag->success = Text::_('The verse was successfully tagged.');
|
||||
return (array) $_tag;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a tagged verse
|
||||
*
|
||||
* @param string $tag The tagged verse GUID value
|
||||
*
|
||||
* @return bool True on success
|
||||
* @since 2.0.1
|
||||
**/
|
||||
public function delete(string $tag): bool
|
||||
{
|
||||
// make sure the linker has access
|
||||
if (($linker = $this->linker->get()) === null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// make sure the linker has access to delete this tag
|
||||
if (($id = $this->load->value(['guid' => $tag, 'linker' => $linker], 'id', 'tagged_verse')) !== null && $id > 0)
|
||||
{
|
||||
return $this->update->value(-2, 'published', $id, 'id', 'tagged_verse');
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a tagged verse
|
||||
*
|
||||
* @param string $linker The linker GUID value
|
||||
* @param string $translation The translation in which the note is made
|
||||
* @param int $book The book in which the note is made
|
||||
* @param int $chapter The chapter in which the note is made
|
||||
* @param int $verse The verse where the note is made
|
||||
* @param string $tag The tag being added
|
||||
*
|
||||
* @return array|null Array of the tagged verse values on success
|
||||
* @since 2.0.1
|
||||
**/
|
||||
private function get(
|
||||
string $linker,
|
||||
string $translation,
|
||||
int $book,
|
||||
int $chapter,
|
||||
int $verse,
|
||||
string $tag
|
||||
): ?array
|
||||
{
|
||||
// get tag if it exist
|
||||
if (($_tag = $this->load->item([
|
||||
'linker' => $linker,
|
||||
'translation' => $translation,
|
||||
'book' => $book,
|
||||
'chapter' => $chapter,
|
||||
'verse' => $verse,
|
||||
'tag' => $tag
|
||||
], 'tagged_verse')) !== null)
|
||||
{
|
||||
return $_tag;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Tagged verse
|
||||
*
|
||||
* @param string $linker The linker GUID value
|
||||
* @param string $translation The translation in which the note is made
|
||||
* @param int $book The book in which the note is made
|
||||
* @param int $chapter The chapter in which the note is made
|
||||
* @param int $verse The verse where the note is made
|
||||
* @param string $tag The tag being added
|
||||
*
|
||||
* @return bool True on success
|
||||
* @since 2.0.1
|
||||
**/
|
||||
private function create(
|
||||
string $linker,
|
||||
string $translation,
|
||||
int $book,
|
||||
int $chapter,
|
||||
int $verse,
|
||||
string $tag
|
||||
): bool
|
||||
{
|
||||
$guid = (string) GuidHelper::get();
|
||||
while (!GuidHelper::valid($guid, 'tagged_verse', 0, '[[[component]]]'))
|
||||
{
|
||||
// must always be set
|
||||
$guid = (string) GuidHelper::get();
|
||||
}
|
||||
|
||||
return $this->insert->row([
|
||||
'tag' => $tag,
|
||||
'access' => 0,
|
||||
'linker' => $linker,
|
||||
'translation' => $translation,
|
||||
'book' => $book,
|
||||
'chapter' => $chapter,
|
||||
'verse' => $verse,
|
||||
'guid' => $guid
|
||||
], 'tagged_verse');
|
||||
}
|
39
src/2315a1c5-bcf6-401a-8d11-60f4d6d12dbb/settings.json
Normal file
39
src/2315a1c5-bcf6-401a-8d11-60f4d6d12dbb/settings.json
Normal file
@ -0,0 +1,39 @@
|
||||
{
|
||||
"add_head": "1",
|
||||
"add_licensing_template": "2",
|
||||
"extends": "0",
|
||||
"guid": "2315a1c5-bcf6-401a-8d11-60f4d6d12dbb",
|
||||
"implements": null,
|
||||
"load_selection": null,
|
||||
"name": "Tagged",
|
||||
"power_version": "1.0.0",
|
||||
"system_name": "Joomla.GetBible.Tagged",
|
||||
"type": "final class",
|
||||
"use_selection": {
|
||||
"use_selection0": {
|
||||
"use": "c03b9c61-17d3-4774-a335-783903719f83",
|
||||
"as": "default"
|
||||
},
|
||||
"use_selection1": {
|
||||
"use": "a07d90f6-6ff2-40a1-99c1-0f2cf33c9adf",
|
||||
"as": "default"
|
||||
},
|
||||
"use_selection2": {
|
||||
"use": "d7a5f0c6-de60-4d31-b3e4-5d668a8f7d2e",
|
||||
"as": "default"
|
||||
},
|
||||
"use_selection3": {
|
||||
"use": "36ab759f-7b42-4465-9c17-56ba1dd05f90",
|
||||
"as": "default"
|
||||
},
|
||||
"use_selection4": {
|
||||
"use": "9c513baf-b279-43fd-ae29-a585c8cbc4f0",
|
||||
"as": "default"
|
||||
}
|
||||
},
|
||||
"namespace": "VDM\\Joomla\\GetBible\\Tagged",
|
||||
"description": "The GetBible Tagged\r\n\r\n@since 2.0.1",
|
||||
"licensing_template": "\/**\r\n * @package GetBible\r\n *\r\n * @created 30th May, 2023\r\n * @author Llewellyn van der Merwe <https:\/\/dev.vdm.io>\r\n * @git GetBible <https:\/\/git.vdm.dev\/getBible>\r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n",
|
||||
"head": "use Joomla\\CMS\\Language\\Text;",
|
||||
"composer": ""
|
||||
}
|
123
src/36ab759f-7b42-4465-9c17-56ba1dd05f90/README.md
Normal file
123
src/36ab759f-7b42-4465-9c17-56ba1dd05f90/README.md
Normal file
@ -0,0 +1,123 @@
|
||||
```
|
||||
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
|
||||
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
|
||||
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
|
||||
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
|
||||
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
|
||||
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
|
||||
```
|
||||
# final class Linker (Details)
|
||||
> namespace: **VDM\Joomla\GetBible**
|
||||
```uml
|
||||
@startuml
|
||||
class Linker << (F,LightGreen) >> #Green {
|
||||
# Load $load
|
||||
# Insert $insert
|
||||
# Update $update
|
||||
# Session $session
|
||||
+ __construct(Load $load, Insert $insert, ...)
|
||||
+ get() : ?string
|
||||
+ active(bool $setup = true) : ?string
|
||||
+ set(string $linker) : ?string
|
||||
+ access(string $linker, string $pass, ...) : bool
|
||||
- hasAccess(string $linker, string $pass) : bool
|
||||
- getPassGuid(string $linker, string $pass) : ?string
|
||||
- getPassword(string $linker, string $pass) : ?object
|
||||
- setLinker(string $linker) : bool
|
||||
- setPassword(string $linker, string $pass) : bool
|
||||
}
|
||||
|
||||
note right of Linker::__construct
|
||||
Constructor
|
||||
|
||||
since: 2.0.1
|
||||
|
||||
arguments:
|
||||
Load $load
|
||||
Insert $insert
|
||||
Update $update
|
||||
Session $session
|
||||
end note
|
||||
|
||||
note left of Linker::get
|
||||
Get Linker that has Access
|
||||
|
||||
since: 2.0.1
|
||||
return: ?string
|
||||
end note
|
||||
|
||||
note right of Linker::active
|
||||
Get active Linker
|
||||
|
||||
since: 2.0.1
|
||||
return: ?string
|
||||
end note
|
||||
|
||||
note left of Linker::set
|
||||
Set Active Linker
|
||||
|
||||
since: 2.0.1
|
||||
return: ?string
|
||||
end note
|
||||
|
||||
note right of Linker::access
|
||||
Set Access
|
||||
|
||||
since: 2.0.1
|
||||
return: bool
|
||||
|
||||
arguments:
|
||||
string $linker
|
||||
string $pass
|
||||
?string $oldPass
|
||||
end note
|
||||
|
||||
note left of Linker::hasAccess
|
||||
Has Access
|
||||
|
||||
since: 2.0.1
|
||||
return: bool
|
||||
end note
|
||||
|
||||
note right of Linker::getPassGuid
|
||||
Get Password GUID
|
||||
|
||||
since: 2.0.1
|
||||
return: ?string
|
||||
end note
|
||||
|
||||
note left of Linker::getPassword
|
||||
Get Password
|
||||
|
||||
since: 2.0.1
|
||||
return: ?object
|
||||
end note
|
||||
|
||||
note right of Linker::setLinker
|
||||
Set Linker
|
||||
|
||||
since: 2.0.1
|
||||
return: bool
|
||||
end note
|
||||
|
||||
note left of Linker::setPassword
|
||||
Set Password
|
||||
|
||||
since: 2.0.1
|
||||
return: bool
|
||||
end note
|
||||
|
||||
@enduml
|
||||
```
|
||||
|
||||
---
|
||||
```
|
||||
██╗ ██████╗██████╗
|
||||
██║██╔════╝██╔══██╗
|
||||
██║██║ ██████╔╝
|
||||
██ ██║██║ ██╔══██╗
|
||||
╚█████╔╝╚██████╗██████╔╝
|
||||
╚════╝ ╚═════╝╚═════╝
|
||||
```
|
||||
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)
|
||||
|
356
src/36ab759f-7b42-4465-9c17-56ba1dd05f90/code.php
Normal file
356
src/36ab759f-7b42-4465-9c17-56ba1dd05f90/code.php
Normal file
@ -0,0 +1,356 @@
|
||||
<?php
|
||||
/**
|
||||
* @package GetBible
|
||||
*
|
||||
* @created 30th May, 2023
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git GetBible <https://git.vdm.dev/getBible>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\GetBible;
|
||||
|
||||
|
||||
use Joomla\CMS\User\UserHelper;
|
||||
use VDM\Joomla\GetBible\Database\Load;
|
||||
use VDM\Joomla\GetBible\Database\Insert;
|
||||
use VDM\Joomla\GetBible\Database\Update;
|
||||
use VDM\Joomla\GetBible\Utilities\SessionHelper as Session;
|
||||
use VDM\Joomla\Utilities\GuidHelper;
|
||||
|
||||
|
||||
/**
|
||||
* The GetBible Linker
|
||||
*
|
||||
* @since 2.0.1
|
||||
*/
|
||||
final class Linker
|
||||
{
|
||||
/**
|
||||
* The Load class
|
||||
*
|
||||
* @var Load
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Load $load;
|
||||
|
||||
/**
|
||||
* The Insert class
|
||||
*
|
||||
* @var Insert
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Insert $insert;
|
||||
|
||||
/**
|
||||
* The Update class
|
||||
*
|
||||
* @var Update
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Update $update;
|
||||
|
||||
/**
|
||||
* The Session class
|
||||
*
|
||||
* @var Session
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Session $session;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Load $load The load object.
|
||||
* @param Insert $insert The insert object.
|
||||
* @param Update $update The update object.
|
||||
* @param Session $session The session object.
|
||||
*
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function __construct(
|
||||
Load $load,
|
||||
Insert $insert,
|
||||
Update $update,
|
||||
Session $session)
|
||||
{
|
||||
$this->load = $load;
|
||||
$this->insert = $insert;
|
||||
$this->update = $update;
|
||||
$this->session = $session;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Linker that has Access
|
||||
*
|
||||
* @return string|null Linker GUID that has access
|
||||
* @since 2.0.1
|
||||
**/
|
||||
public function get(): ?string
|
||||
{
|
||||
if (($linker = $this->session->get('getbible_active_linker_guid', null)) === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (($access = $this->session->get("getbible_active_{$linker}", null)) === null
|
||||
|| $access === 'valid_access')
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return $linker;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get active Linker
|
||||
*
|
||||
* @param bool $setup The setup switch
|
||||
*
|
||||
* @return string|null Linker GUID that has access
|
||||
* @since 2.0.1
|
||||
**/
|
||||
public function active(bool $setup = true): ?string
|
||||
{
|
||||
if (($linker = $this->session->get('getbible_active_linker_guid', null)) !== null)
|
||||
{
|
||||
return $linker;
|
||||
}
|
||||
|
||||
if ($setup)
|
||||
{
|
||||
$guid = (string) GuidHelper::get();
|
||||
$this->session->set('getbible_active_linker_guid', $guid);
|
||||
|
||||
return $guid;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Active Linker
|
||||
*
|
||||
* @param string $linker The linker GUID value
|
||||
*
|
||||
* @return bool True on success
|
||||
* @since 2.0.1
|
||||
**/
|
||||
public function set(string $linker): ?string
|
||||
{
|
||||
if (!GuidHelper::valid($linker))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->session->set('getbible_active_linker_guid', $linker);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Access
|
||||
*
|
||||
* @param string $linker The linker GUID value
|
||||
* @param string $pass The linker pass value
|
||||
* @param string|null $oldPass The linker old pass value
|
||||
*
|
||||
* @return bool True on success
|
||||
* @since 2.0.1
|
||||
**/
|
||||
public function access(string $linker, string $pass, ?string $oldPass): bool
|
||||
{
|
||||
// password to short
|
||||
if (strlen($pass) <= 3)
|
||||
{
|
||||
return [
|
||||
'error' => Text::_('COM_GETBIBLE_PASSWORD_TO_SHORT_USE_A_LONGER_PASSWORD')
|
||||
];
|
||||
}
|
||||
// linker not valid GUID
|
||||
elseif (!GuidHelper::valid($linker))
|
||||
{
|
||||
return [
|
||||
'error' => Text::_('COM_GETBIBLE_INVALID_SESSION_VALUE')
|
||||
];
|
||||
}
|
||||
|
||||
// get linker
|
||||
if (($_linker = $this->load->item(['guid' => $linker],'linker')) !== null)
|
||||
{
|
||||
// publish the linker if needed
|
||||
if ($_linker->published != 1 && $this->update->value(1, 'published', $_linker->id, 'id', 'linker'))
|
||||
{
|
||||
return [
|
||||
'error' => Text::_('COM_GETBIBLE_ACCESS_ALREADY_EXIST_BUT_COULD_NOT_BE_REACTIVATED')
|
||||
];
|
||||
}
|
||||
|
||||
if (!empty($oldPass))
|
||||
{
|
||||
if (($guid = $this->getPassGuid($linker, $oldPass)) === null)
|
||||
{
|
||||
return [
|
||||
'error' => Text::_('COM_GETBIBLE_PASSWORD_INCORRECT')
|
||||
];
|
||||
}
|
||||
|
||||
if (!$this->setPassword($linker, $pass))
|
||||
{
|
||||
return [
|
||||
'error' => Text::_('COM_GETBIBLE_PASSWORD_COULD_NOT_BE_CHANGED')
|
||||
];
|
||||
}
|
||||
|
||||
// unpublished the old pass word only if new password was set
|
||||
$this->update->value(-2, 'published', $guid, 'guid', 'password');
|
||||
}
|
||||
elseif (!$this->hasAccess($linker, $pass))
|
||||
{
|
||||
return [
|
||||
'error' => Text::_('COM_GETBIBLE_PASSWORD_INCORRECT')
|
||||
];
|
||||
}
|
||||
}
|
||||
elseif (!$this->setLinker($linker))
|
||||
{
|
||||
return [
|
||||
'error' => Text::_('COM_GETBIBLE_SESSION_COULD_NOT_BE_STORED')
|
||||
];
|
||||
}
|
||||
elseif (!$this->setPassword($linker, $pass))
|
||||
{
|
||||
return [
|
||||
'error' => Text::_('COM_GETBIBLE_PASSWORD_COULD_NOT_BE_STORED')
|
||||
];
|
||||
}
|
||||
elseif (($_linker = $this->load->item(['guid' => $linker],'linker')) === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$_linker->published = 1;
|
||||
$_linker->success = Text::_('COM_GETBIBLE_ACCESS_SUCCESSFULLY_SET');
|
||||
|
||||
// add to session
|
||||
$this->session->set('getbible_active_linker_guid', $linker);
|
||||
$this->session->set("getbible_active_{$linker}", 'valid_access');
|
||||
|
||||
return (array) $_linker;
|
||||
}
|
||||
|
||||
/**
|
||||
* Has Access
|
||||
*
|
||||
* @param string $linker The linker GUID value
|
||||
* @param string $pass The linker pass value
|
||||
*
|
||||
* @return bool True on success
|
||||
* @since 2.0.1
|
||||
**/
|
||||
private function hasAccess(string $linker, string $pass): bool
|
||||
{
|
||||
if (($password = $this->getPassword($linker, $pass)) !== null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Password GUID
|
||||
*
|
||||
* @param string $linker The linker GUID value
|
||||
* @param string $pass The linker pass value
|
||||
*
|
||||
* @return string|null The GUID on success
|
||||
* @since 2.0.1
|
||||
**/
|
||||
private function getPassGuid(string $linker, string $pass): ?string
|
||||
{
|
||||
if (($password = $this->getPassword($linker, $pass)) !== null)
|
||||
{
|
||||
return $password->guid;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Password
|
||||
*
|
||||
* @param string $linker The linker GUID value
|
||||
* @param string $pass The linker pass value
|
||||
*
|
||||
* @return object|null The GUID on success
|
||||
* @since 2.0.1
|
||||
**/
|
||||
private function getPassword(string $linker, string $pass): ?object
|
||||
{
|
||||
if (strlen($pass) > 3 && ($passwords = $this->load->items(
|
||||
['linker' => $linker, 'published' => 1],
|
||||
'password'
|
||||
)) !== null)
|
||||
{
|
||||
foreach ($passwords as $password)
|
||||
{
|
||||
if (UserHelper::verifyPassword($pass, $password->password))
|
||||
{
|
||||
return $password;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Linker
|
||||
*
|
||||
* @param string $linker The linker GUID value
|
||||
*
|
||||
* @return bool True on success
|
||||
* @since 2.0.1
|
||||
**/
|
||||
private function setLinker(string $linker): bool
|
||||
{
|
||||
return $this->insert->row([
|
||||
'name' => 'Default-Name',
|
||||
'guid' => $linker
|
||||
], 'linker');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Password
|
||||
*
|
||||
* @param string $linker The linker GUID value
|
||||
* @param string $pass The linker pass value
|
||||
*
|
||||
* @return bool True on success
|
||||
* @since 2.0.1
|
||||
**/
|
||||
private function setPassword(string $linker, string $pass): bool
|
||||
{
|
||||
if (strlen($pass) <= 3)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$guid = (string) GuidHelper::get();
|
||||
while (!GuidHelper::valid($guid, 'password', 0, 'getbible'))
|
||||
{
|
||||
// must always be set
|
||||
$guid = (string) GuidHelper::get();
|
||||
}
|
||||
|
||||
return $this->insert->row([
|
||||
'name' => 'Favourite-Verse',
|
||||
'linker' => $linker,
|
||||
'password' => UserHelper::hashPassword($pass),
|
||||
'guid' => $guid
|
||||
], 'password');
|
||||
}
|
||||
}
|
||||
|
325
src/36ab759f-7b42-4465-9c17-56ba1dd05f90/code.power
Normal file
325
src/36ab759f-7b42-4465-9c17-56ba1dd05f90/code.power
Normal file
@ -0,0 +1,325 @@
|
||||
/**
|
||||
* The Load class
|
||||
*
|
||||
* @var Load
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Load $load;
|
||||
|
||||
/**
|
||||
* The Insert class
|
||||
*
|
||||
* @var Insert
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Insert $insert;
|
||||
|
||||
/**
|
||||
* The Update class
|
||||
*
|
||||
* @var Update
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Update $update;
|
||||
|
||||
/**
|
||||
* The Session class
|
||||
*
|
||||
* @var Session
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Session $session;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Load $load The load object.
|
||||
* @param Insert $insert The insert object.
|
||||
* @param Update $update The update object.
|
||||
* @param Session $session The session object.
|
||||
*
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function __construct(
|
||||
Load $load,
|
||||
Insert $insert,
|
||||
Update $update,
|
||||
Session $session)
|
||||
{
|
||||
$this->load = $load;
|
||||
$this->insert = $insert;
|
||||
$this->update = $update;
|
||||
$this->session = $session;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Linker that has Access
|
||||
*
|
||||
* @return string|null Linker GUID that has access
|
||||
* @since 2.0.1
|
||||
**/
|
||||
public function get(): ?string
|
||||
{
|
||||
if (($linker = $this->session->get('getbible_active_linker_guid', null)) === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (($access = $this->session->get("getbible_active_{$linker}", null)) === null
|
||||
|| $access === 'valid_access')
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return $linker;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get active Linker
|
||||
*
|
||||
* @param bool $setup The setup switch
|
||||
*
|
||||
* @return string|null Linker GUID that has access
|
||||
* @since 2.0.1
|
||||
**/
|
||||
public function active(bool $setup = true): ?string
|
||||
{
|
||||
if (($linker = $this->session->get('getbible_active_linker_guid', null)) !== null)
|
||||
{
|
||||
return $linker;
|
||||
}
|
||||
|
||||
if ($setup)
|
||||
{
|
||||
$guid = (string) GuidHelper::get();
|
||||
$this->session->set('getbible_active_linker_guid', $guid);
|
||||
|
||||
return $guid;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Active Linker
|
||||
*
|
||||
* @param string $linker The linker GUID value
|
||||
*
|
||||
* @return bool True on success
|
||||
* @since 2.0.1
|
||||
**/
|
||||
public function set(string $linker): ?string
|
||||
{
|
||||
if (!GuidHelper::valid($linker))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->session->set('getbible_active_linker_guid', $linker);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Access
|
||||
*
|
||||
* @param string $linker The linker GUID value
|
||||
* @param string $pass The linker pass value
|
||||
* @param string|null $oldPass The linker old pass value
|
||||
*
|
||||
* @return bool True on success
|
||||
* @since 2.0.1
|
||||
**/
|
||||
public function access(string $linker, string $pass, ?string $oldPass): bool
|
||||
{
|
||||
// password to short
|
||||
if (strlen($pass) <= 3)
|
||||
{
|
||||
return [
|
||||
'error' => Text::_('Password to short, use a longer password.')
|
||||
];
|
||||
}
|
||||
// linker not valid GUID
|
||||
elseif (!GuidHelper::valid($linker))
|
||||
{
|
||||
return [
|
||||
'error' => Text::_('Invalid session value.')
|
||||
];
|
||||
}
|
||||
|
||||
// get linker
|
||||
if (($_linker = $this->load->item(['guid' => $linker],'linker')) !== null)
|
||||
{
|
||||
// publish the linker if needed
|
||||
if ($_linker->published != 1 && $this->update->value(1, 'published', $_linker->id, 'id', 'linker'))
|
||||
{
|
||||
return [
|
||||
'error' => Text::_('Access already exist, but could not be reactivated.')
|
||||
];
|
||||
}
|
||||
|
||||
if (!empty($oldPass))
|
||||
{
|
||||
if (($guid = $this->getPassGuid($linker, $oldPass)) === null)
|
||||
{
|
||||
return [
|
||||
'error' => Text::_('Password incorrect.')
|
||||
];
|
||||
}
|
||||
|
||||
if (!$this->setPassword($linker, $pass))
|
||||
{
|
||||
return [
|
||||
'error' => Text::_('Password could not be changed.')
|
||||
];
|
||||
}
|
||||
|
||||
// unpublished the old pass word only if new password was set
|
||||
$this->update->value(-2, 'published', $guid, 'guid', 'password');
|
||||
}
|
||||
elseif (!$this->hasAccess($linker, $pass))
|
||||
{
|
||||
return [
|
||||
'error' => Text::_('Password incorrect.')
|
||||
];
|
||||
}
|
||||
}
|
||||
elseif (!$this->setLinker($linker))
|
||||
{
|
||||
return [
|
||||
'error' => Text::_('Session could not be stored.')
|
||||
];
|
||||
}
|
||||
elseif (!$this->setPassword($linker, $pass))
|
||||
{
|
||||
return [
|
||||
'error' => Text::_('Password could not be stored.')
|
||||
];
|
||||
}
|
||||
elseif (($_linker = $this->load->item(['guid' => $linker],'linker')) === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$_linker->published = 1;
|
||||
$_linker->success = Text::_('Access successfully set.');
|
||||
|
||||
// add to session
|
||||
$this->session->set('getbible_active_linker_guid', $linker);
|
||||
$this->session->set("getbible_active_{$linker}", 'valid_access');
|
||||
|
||||
return (array) $_linker;
|
||||
}
|
||||
|
||||
/**
|
||||
* Has Access
|
||||
*
|
||||
* @param string $linker The linker GUID value
|
||||
* @param string $pass The linker pass value
|
||||
*
|
||||
* @return bool True on success
|
||||
* @since 2.0.1
|
||||
**/
|
||||
private function hasAccess(string $linker, string $pass): bool
|
||||
{
|
||||
if (($password = $this->getPassword($linker, $pass)) !== null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Password GUID
|
||||
*
|
||||
* @param string $linker The linker GUID value
|
||||
* @param string $pass The linker pass value
|
||||
*
|
||||
* @return string|null The GUID on success
|
||||
* @since 2.0.1
|
||||
**/
|
||||
private function getPassGuid(string $linker, string $pass): ?string
|
||||
{
|
||||
if (($password = $this->getPassword($linker, $pass)) !== null)
|
||||
{
|
||||
return $password->guid;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Password
|
||||
*
|
||||
* @param string $linker The linker GUID value
|
||||
* @param string $pass The linker pass value
|
||||
*
|
||||
* @return object|null The GUID on success
|
||||
* @since 2.0.1
|
||||
**/
|
||||
private function getPassword(string $linker, string $pass): ?object
|
||||
{
|
||||
if (strlen($pass) > 3 && ($passwords = $this->load->items(
|
||||
['linker' => $linker, 'published' => 1],
|
||||
'password'
|
||||
)) !== null)
|
||||
{
|
||||
foreach ($passwords as $password)
|
||||
{
|
||||
if (UserHelper::verifyPassword($pass, $password->password))
|
||||
{
|
||||
return $password;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Linker
|
||||
*
|
||||
* @param string $linker The linker GUID value
|
||||
*
|
||||
* @return bool True on success
|
||||
* @since 2.0.1
|
||||
**/
|
||||
private function setLinker(string $linker): bool
|
||||
{
|
||||
return $this->insert->row([
|
||||
'name' => 'Default-Name',
|
||||
'guid' => $linker
|
||||
], 'linker');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Password
|
||||
*
|
||||
* @param string $linker The linker GUID value
|
||||
* @param string $pass The linker pass value
|
||||
*
|
||||
* @return bool True on success
|
||||
* @since 2.0.1
|
||||
**/
|
||||
private function setPassword(string $linker, string $pass): bool
|
||||
{
|
||||
if (strlen($pass) <= 3)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$guid = (string) GuidHelper::get();
|
||||
while (!GuidHelper::valid($guid, 'password', 0, '[[[component]]]'))
|
||||
{
|
||||
// must always be set
|
||||
$guid = (string) GuidHelper::get();
|
||||
}
|
||||
|
||||
return $this->insert->row([
|
||||
'name' => 'Favourite-Verse',
|
||||
'linker' => $linker,
|
||||
'password' => UserHelper::hashPassword($pass),
|
||||
'guid' => $guid
|
||||
], 'password');
|
||||
}
|
39
src/36ab759f-7b42-4465-9c17-56ba1dd05f90/settings.json
Normal file
39
src/36ab759f-7b42-4465-9c17-56ba1dd05f90/settings.json
Normal file
@ -0,0 +1,39 @@
|
||||
{
|
||||
"add_head": "1",
|
||||
"add_licensing_template": "2",
|
||||
"extends": "0",
|
||||
"guid": "36ab759f-7b42-4465-9c17-56ba1dd05f90",
|
||||
"implements": null,
|
||||
"load_selection": null,
|
||||
"name": "Linker",
|
||||
"power_version": "1.0.0",
|
||||
"system_name": "Joomla.GetBible.Linker",
|
||||
"type": "final class",
|
||||
"use_selection": {
|
||||
"use_selection0": {
|
||||
"use": "c03b9c61-17d3-4774-a335-783903719f83",
|
||||
"as": "default"
|
||||
},
|
||||
"use_selection1": {
|
||||
"use": "a07d90f6-6ff2-40a1-99c1-0f2cf33c9adf",
|
||||
"as": "default"
|
||||
},
|
||||
"use_selection2": {
|
||||
"use": "d7a5f0c6-de60-4d31-b3e4-5d668a8f7d2e",
|
||||
"as": "default"
|
||||
},
|
||||
"use_selection3": {
|
||||
"use": "84e84cd1-c938-4559-8414-d5692db4118e",
|
||||
"as": "Session"
|
||||
},
|
||||
"use_selection4": {
|
||||
"use": "9c513baf-b279-43fd-ae29-a585c8cbc4f0",
|
||||
"as": "default"
|
||||
}
|
||||
},
|
||||
"namespace": "VDM\\Joomla\\GetBible\\Linker",
|
||||
"description": "The GetBible Linker\r\n\r\n@since 2.0.1",
|
||||
"licensing_template": "\/**\r\n * @package GetBible\r\n *\r\n * @created 30th May, 2023\r\n * @author Llewellyn van der Merwe <https:\/\/dev.vdm.io>\r\n * @git GetBible <https:\/\/git.vdm.dev\/getBible>\r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n",
|
||||
"head": "use Joomla\\CMS\\User\\UserHelper;",
|
||||
"composer": ""
|
||||
}
|
@ -17,6 +17,10 @@ class App #Gold {
|
||||
+ getDailyScripture(Container $container) : DailyScripture
|
||||
+ getSearch(Container $container) : Search
|
||||
+ getWatcher(Container $container) : Watcher
|
||||
+ getLinker(Container $container) : Linker
|
||||
+ getNote(Container $container) : Note
|
||||
+ getTag(Container $container) : Tag
|
||||
+ getTagged(Container $container) : Tagged
|
||||
}
|
||||
|
||||
note right of App::register
|
||||
@ -26,7 +30,7 @@ note right of App::register
|
||||
return: void
|
||||
end note
|
||||
|
||||
note right of App::getConfig
|
||||
note left of App::getConfig
|
||||
Get the Config class
|
||||
|
||||
since: 2.0.1
|
||||
@ -40,7 +44,7 @@ note right of App::getTable
|
||||
return: Table
|
||||
end note
|
||||
|
||||
note right of App::getDailyScripture
|
||||
note left of App::getDailyScripture
|
||||
Get the Daily Scripture class
|
||||
|
||||
since: 2.0.1
|
||||
@ -54,13 +58,41 @@ note right of App::getSearch
|
||||
return: Search
|
||||
end note
|
||||
|
||||
note right of App::getWatcher
|
||||
note left of App::getWatcher
|
||||
Get the Watcher class
|
||||
|
||||
since: 2.0.1
|
||||
return: Watcher
|
||||
end note
|
||||
|
||||
note right of App::getLinker
|
||||
Get the Linker class
|
||||
|
||||
since: 2.0.1
|
||||
return: Linker
|
||||
end note
|
||||
|
||||
note left of App::getNote
|
||||
Get the Note class
|
||||
|
||||
since: 2.0.1
|
||||
return: Note
|
||||
end note
|
||||
|
||||
note right of App::getTag
|
||||
Get the Tag class
|
||||
|
||||
since: 2.0.1
|
||||
return: Tag
|
||||
end note
|
||||
|
||||
note left of App::getTagged
|
||||
Get the Tagged class
|
||||
|
||||
since: 2.0.1
|
||||
return: Tagged
|
||||
end note
|
||||
|
||||
@enduml
|
||||
```
|
||||
|
||||
|
@ -19,6 +19,10 @@ use VDM\Joomla\GetBible\Table;
|
||||
use VDM\Joomla\GetBible\DailyScripture;
|
||||
use VDM\Joomla\GetBible\Search;
|
||||
use VDM\Joomla\GetBible\Watcher;
|
||||
use VDM\Joomla\GetBible\Linker;
|
||||
use VDM\Joomla\GetBible\Note;
|
||||
use VDM\Joomla\GetBible\Tag;
|
||||
use VDM\Joomla\GetBible\Tagged;
|
||||
|
||||
|
||||
/**
|
||||
@ -52,6 +56,18 @@ class App implements ServiceProviderInterface
|
||||
|
||||
$container->alias(Watcher::class, 'GetBible.Watcher')
|
||||
->share('GetBible.Watcher', [$this, 'getWatcher'], true);
|
||||
|
||||
$container->alias(Linker::class, 'GetBible.Linker')
|
||||
->share('GetBible.Linker', [$this, 'getLinker'], true);
|
||||
|
||||
$container->alias(Note::class, 'GetBible.Note')
|
||||
->share('GetBible.Note', [$this, 'getNote'], true);
|
||||
|
||||
$container->alias(Tag::class, 'GetBible.Tag')
|
||||
->share('GetBible.Tag', [$this, 'getTag'], true);
|
||||
|
||||
$container->alias(Tagged::class, 'GetBible.Tagged')
|
||||
->share('GetBible.Tagged', [$this, 'getTagged'], true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -130,5 +146,77 @@ class App implements ServiceProviderInterface
|
||||
$container->get('GetBible.Api.Verses')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Linker class
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Linker
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function getLinker(Container $container): Linker
|
||||
{
|
||||
return new Linker(
|
||||
$container->get('GetBible.Load'),
|
||||
$container->get('GetBible.Insert'),
|
||||
$container->get('GetBible.Update'),
|
||||
$container->get('GetBible.Utilities.Session')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Note class
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Note
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function getNote(Container $container): Note
|
||||
{
|
||||
return new Note(
|
||||
$container->get('GetBible.Load'),
|
||||
$container->get('GetBible.Insert'),
|
||||
$container->get('GetBible.Update'),
|
||||
$container->get('GetBible.Linker')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Tag class
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Tag
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function getTag(Container $container): Tag
|
||||
{
|
||||
return new Tag(
|
||||
$container->get('GetBible.Load'),
|
||||
$container->get('GetBible.Insert'),
|
||||
$container->get('GetBible.Update'),
|
||||
$container->get('GetBible.Linker')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Tagged class
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Tagged
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function getTagged(Container $container): Tagged
|
||||
{
|
||||
return new Tagged(
|
||||
$container->get('GetBible.Load'),
|
||||
$container->get('GetBible.Insert'),
|
||||
$container->get('GetBible.Update'),
|
||||
$container->get('GetBible.Linker')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,18 @@
|
||||
|
||||
$container->alias(Watcher::class, 'GetBible.Watcher')
|
||||
->share('GetBible.Watcher', [$this, 'getWatcher'], true);
|
||||
|
||||
$container->alias(Linker::class, 'GetBible.Linker')
|
||||
->share('GetBible.Linker', [$this, 'getLinker'], true);
|
||||
|
||||
$container->alias(Note::class, 'GetBible.Note')
|
||||
->share('GetBible.Note', [$this, 'getNote'], true);
|
||||
|
||||
$container->alias(Tag::class, 'GetBible.Tag')
|
||||
->share('GetBible.Tag', [$this, 'getTag'], true);
|
||||
|
||||
$container->alias(Tagged::class, 'GetBible.Tagged')
|
||||
->share('GetBible.Tagged', [$this, 'getTagged'], true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -100,3 +112,75 @@
|
||||
$container->get('GetBible.Api.Verses')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Linker class
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Linker
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function getLinker(Container $container): Linker
|
||||
{
|
||||
return new Linker(
|
||||
$container->get('GetBible.Load'),
|
||||
$container->get('GetBible.Insert'),
|
||||
$container->get('GetBible.Update'),
|
||||
$container->get('GetBible.Utilities.Session')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Note class
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Note
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function getNote(Container $container): Note
|
||||
{
|
||||
return new Note(
|
||||
$container->get('GetBible.Load'),
|
||||
$container->get('GetBible.Insert'),
|
||||
$container->get('GetBible.Update'),
|
||||
$container->get('GetBible.Linker')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Tag class
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Tag
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function getTag(Container $container): Tag
|
||||
{
|
||||
return new Tag(
|
||||
$container->get('GetBible.Load'),
|
||||
$container->get('GetBible.Insert'),
|
||||
$container->get('GetBible.Update'),
|
||||
$container->get('GetBible.Linker')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Tagged class
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Tagged
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function getTagged(Container $container): Tagged
|
||||
{
|
||||
return new Tagged(
|
||||
$container->get('GetBible.Load'),
|
||||
$container->get('GetBible.Insert'),
|
||||
$container->get('GetBible.Update'),
|
||||
$container->get('GetBible.Linker')
|
||||
);
|
||||
}
|
@ -31,6 +31,22 @@
|
||||
"use_selection4": {
|
||||
"use": "f815fb33-f721-48a5-a84e-53f1986e8881",
|
||||
"as": "default"
|
||||
},
|
||||
"use_selection5": {
|
||||
"use": "36ab759f-7b42-4465-9c17-56ba1dd05f90",
|
||||
"as": "default"
|
||||
},
|
||||
"use_selection6": {
|
||||
"use": "ebda6bd8-95b9-468b-a521-974205146018",
|
||||
"as": "default"
|
||||
},
|
||||
"use_selection7": {
|
||||
"use": "67f91b8b-7b48-4dbb-bbd5-7945c174622a",
|
||||
"as": "default"
|
||||
},
|
||||
"use_selection8": {
|
||||
"use": "2315a1c5-bcf6-401a-8d11-60f4d6d12dbb",
|
||||
"as": "default"
|
||||
}
|
||||
},
|
||||
"namespace": "VDM\\Joomla\\GetBible\\Service.App",
|
||||
|
78
src/67f91b8b-7b48-4dbb-bbd5-7945c174622a/README.md
Normal file
78
src/67f91b8b-7b48-4dbb-bbd5-7945c174622a/README.md
Normal file
@ -0,0 +1,78 @@
|
||||
```
|
||||
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
|
||||
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
|
||||
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
|
||||
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
|
||||
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
|
||||
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
|
||||
```
|
||||
# final class Tag (Details)
|
||||
> namespace: **VDM\Joomla\GetBible**
|
||||
```uml
|
||||
@startuml
|
||||
class Tag << (F,LightGreen) >> #Green {
|
||||
# Load $load
|
||||
# Insert $insert
|
||||
# Update $update
|
||||
# Linker $linker
|
||||
+ __construct(Load $load, Insert $insert, ...)
|
||||
+ set(string $name) : ?array
|
||||
+ delete(string $tag) : bool
|
||||
- get(string $linker, string $name) : ?array
|
||||
- create(string $linker, string $name) : bool
|
||||
}
|
||||
|
||||
note right of Tag::__construct
|
||||
Constructor
|
||||
|
||||
since: 2.0.1
|
||||
|
||||
arguments:
|
||||
Load $load
|
||||
Insert $insert
|
||||
Update $update
|
||||
Linker $linker
|
||||
end note
|
||||
|
||||
note right of Tag::set
|
||||
Set a tag
|
||||
|
||||
since: 2.0.1
|
||||
return: ?array
|
||||
end note
|
||||
|
||||
note right of Tag::delete
|
||||
Delete a tag
|
||||
|
||||
since: 2.0.1
|
||||
return: bool
|
||||
end note
|
||||
|
||||
note right of Tag::get
|
||||
Get a tag
|
||||
|
||||
since: 2.0.1
|
||||
return: ?array
|
||||
end note
|
||||
|
||||
note right of Tag::create
|
||||
Create a Tag
|
||||
|
||||
since: 2.0.1
|
||||
return: bool
|
||||
end note
|
||||
|
||||
@enduml
|
||||
```
|
||||
|
||||
---
|
||||
```
|
||||
██╗ ██████╗██████╗
|
||||
██║██╔════╝██╔══██╗
|
||||
██║██║ ██████╔╝
|
||||
██ ██║██║ ██╔══██╗
|
||||
╚█████╔╝╚██████╗██████╔╝
|
||||
╚════╝ ╚═════╝╚═════╝
|
||||
```
|
||||
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)
|
||||
|
209
src/67f91b8b-7b48-4dbb-bbd5-7945c174622a/code.php
Normal file
209
src/67f91b8b-7b48-4dbb-bbd5-7945c174622a/code.php
Normal file
@ -0,0 +1,209 @@
|
||||
<?php
|
||||
/**
|
||||
* @package GetBible
|
||||
*
|
||||
* @created 30th May, 2023
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git GetBible <https://git.vdm.dev/getBible>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\GetBible;
|
||||
|
||||
|
||||
use Joomla\CMS\Language\Text;
|
||||
use VDM\Joomla\GetBible\Database\Load;
|
||||
use VDM\Joomla\GetBible\Database\Insert;
|
||||
use VDM\Joomla\GetBible\Database\Update;
|
||||
use VDM\Joomla\GetBible\Linker;
|
||||
use VDM\Joomla\Utilities\GuidHelper;
|
||||
|
||||
|
||||
/**
|
||||
* The GetBible Tag
|
||||
*
|
||||
* @since 2.0.1
|
||||
*/
|
||||
final class Tag
|
||||
{
|
||||
/**
|
||||
* The Load class
|
||||
*
|
||||
* @var Load
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Load $load;
|
||||
|
||||
/**
|
||||
* The Insert class
|
||||
*
|
||||
* @var Insert
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Insert $insert;
|
||||
|
||||
/**
|
||||
* The Update class
|
||||
*
|
||||
* @var Update
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Update $update;
|
||||
|
||||
/**
|
||||
* The Linker class
|
||||
*
|
||||
* @var Linker
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Linker $linker;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Load $load The load object.
|
||||
* @param Insert $insert The insert object.
|
||||
* @param Update $update The update object.
|
||||
* @param Linker $linker The linker object.
|
||||
*
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function __construct(
|
||||
Load $load,
|
||||
Insert $insert,
|
||||
Update $update,
|
||||
Linker $linker)
|
||||
{
|
||||
$this->load = $load;
|
||||
$this->insert = $insert;
|
||||
$this->update = $update;
|
||||
$this->linker = $linker;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a tag
|
||||
*
|
||||
* @param string $name The tag name being created
|
||||
*
|
||||
* @return array|null Array of the tag values on success
|
||||
* @since 2.0.1
|
||||
**/
|
||||
public function set(string $name): ?array
|
||||
{
|
||||
// make sure the linker has access
|
||||
if (($linker = $this->linker->get()) === null)
|
||||
{
|
||||
return [
|
||||
'error' => Text::_('COM_GETBIBLE_YOU_DO_NOT_HAVE_ACCESS_TO_PERFORM_THIS_ACTION'),
|
||||
'function' => 'setLinkerAccess'
|
||||
];
|
||||
}
|
||||
|
||||
// get tag if it exist
|
||||
if (($tag = $this->get($linker, $name)) !== null)
|
||||
{
|
||||
// publish if not published
|
||||
if ($tag->published != 1 && !$this->update->value(1, 'published', $tag->id, 'id', 'tag'))
|
||||
{
|
||||
return [
|
||||
'error' => Text::_('COM_GETBIBLE_TAG_ALREADY_EXIST_BUT_COULD_NOT_BE_REACTIVATED')
|
||||
];
|
||||
}
|
||||
|
||||
$tag->published = 1;
|
||||
$tag->success = Text::_('COM_GETBIBLE_THE_TAG_WAS_SUCCESSFULLY_SET');
|
||||
return (array) $tag;
|
||||
}
|
||||
// create a new tag
|
||||
elseif ($this->create($linker, $name)
|
||||
&& ($tag = $this->get($linker, $name)) !== null)
|
||||
{
|
||||
$tag->success = Text::_('COM_GETBIBLE_THE_TAG_WAS_SUCCESSFULLY_SET');
|
||||
return (array) $tag;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a tag
|
||||
*
|
||||
* @param string $tag The tagged verse GUID value
|
||||
*
|
||||
* @return bool True on success
|
||||
* @since 2.0.1
|
||||
**/
|
||||
public function delete(string $tag): bool
|
||||
{
|
||||
// make sure the linker has access
|
||||
if (($linker = $this->linker->get()) === null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// make sure the linker has access to delete this tag
|
||||
if (($id = $this->load->value(['guid' => $tag, 'linker' => $linker], 'id', 'tag')) !== null && $id > 0)
|
||||
{
|
||||
return $this->update->value(-2, 'published', $id, 'id', 'tag');
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a tag
|
||||
*
|
||||
* @param string $linker The linker GUID value
|
||||
* @param string $name The tag name
|
||||
*
|
||||
* @return array|null Array of the tagged verse values on success
|
||||
* @since 2.0.1
|
||||
**/
|
||||
private function get(
|
||||
string $linker,
|
||||
string $name
|
||||
): ?array
|
||||
{
|
||||
// get tag if it exist
|
||||
if (($tag = $this->load->item([
|
||||
'linker' => $linker,
|
||||
'name' => $name
|
||||
], 'tag')) !== null)
|
||||
{
|
||||
return $tag;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Tag
|
||||
*
|
||||
* @param string $linker The linker GUID value
|
||||
* @param string $name The tag name
|
||||
*
|
||||
* @return bool True on success
|
||||
* @since 2.0.1
|
||||
**/
|
||||
private function create(
|
||||
string $linker,
|
||||
string $name
|
||||
): bool
|
||||
{
|
||||
$guid = (string) GuidHelper::get();
|
||||
while (!GuidHelper::valid($guid, 'tag', 0, 'getbible'))
|
||||
{
|
||||
// must always be set
|
||||
$guid = (string) GuidHelper::get();
|
||||
}
|
||||
|
||||
return $this->insert->row([
|
||||
'access' => 0,
|
||||
'linker' => $linker,
|
||||
'name' => $name,
|
||||
'guid' => $guid
|
||||
], 'tag');
|
||||
}
|
||||
}
|
||||
|
178
src/67f91b8b-7b48-4dbb-bbd5-7945c174622a/code.power
Normal file
178
src/67f91b8b-7b48-4dbb-bbd5-7945c174622a/code.power
Normal file
@ -0,0 +1,178 @@
|
||||
/**
|
||||
* The Load class
|
||||
*
|
||||
* @var Load
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Load $load;
|
||||
|
||||
/**
|
||||
* The Insert class
|
||||
*
|
||||
* @var Insert
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Insert $insert;
|
||||
|
||||
/**
|
||||
* The Update class
|
||||
*
|
||||
* @var Update
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Update $update;
|
||||
|
||||
/**
|
||||
* The Linker class
|
||||
*
|
||||
* @var Linker
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Linker $linker;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Load $load The load object.
|
||||
* @param Insert $insert The insert object.
|
||||
* @param Update $update The update object.
|
||||
* @param Linker $linker The linker object.
|
||||
*
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function __construct(
|
||||
Load $load,
|
||||
Insert $insert,
|
||||
Update $update,
|
||||
Linker $linker)
|
||||
{
|
||||
$this->load = $load;
|
||||
$this->insert = $insert;
|
||||
$this->update = $update;
|
||||
$this->linker = $linker;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a tag
|
||||
*
|
||||
* @param string $name The tag name being created
|
||||
*
|
||||
* @return array|null Array of the tag values on success
|
||||
* @since 2.0.1
|
||||
**/
|
||||
public function set(string $name): ?array
|
||||
{
|
||||
// make sure the linker has access
|
||||
if (($linker = $this->linker->get()) === null)
|
||||
{
|
||||
return [
|
||||
'error' => Text::_('You do not have access to perform this action'),
|
||||
'function' => 'setLinkerAccess'
|
||||
];
|
||||
}
|
||||
|
||||
// get tag if it exist
|
||||
if (($tag = $this->get($linker, $name)) !== null)
|
||||
{
|
||||
// publish if not published
|
||||
if ($tag->published != 1 && !$this->update->value(1, 'published', $tag->id, 'id', 'tag'))
|
||||
{
|
||||
return [
|
||||
'error' => Text::_('Tag already exist, but could not be reactivated.')
|
||||
];
|
||||
}
|
||||
|
||||
$tag->published = 1;
|
||||
$tag->success = Text::_('The tag was successfully set.');
|
||||
return (array) $tag;
|
||||
}
|
||||
// create a new tag
|
||||
elseif ($this->create($linker, $name)
|
||||
&& ($tag = $this->get($linker, $name)) !== null)
|
||||
{
|
||||
$tag->success = Text::_('The tag was successfully set.');
|
||||
return (array) $tag;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a tag
|
||||
*
|
||||
* @param string $tag The tagged verse GUID value
|
||||
*
|
||||
* @return bool True on success
|
||||
* @since 2.0.1
|
||||
**/
|
||||
public function delete(string $tag): bool
|
||||
{
|
||||
// make sure the linker has access
|
||||
if (($linker = $this->linker->get()) === null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// make sure the linker has access to delete this tag
|
||||
if (($id = $this->load->value(['guid' => $tag, 'linker' => $linker], 'id', 'tag')) !== null && $id > 0)
|
||||
{
|
||||
return $this->update->value(-2, 'published', $id, 'id', 'tag');
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a tag
|
||||
*
|
||||
* @param string $linker The linker GUID value
|
||||
* @param string $name The tag name
|
||||
*
|
||||
* @return array|null Array of the tagged verse values on success
|
||||
* @since 2.0.1
|
||||
**/
|
||||
private function get(
|
||||
string $linker,
|
||||
string $name
|
||||
): ?array
|
||||
{
|
||||
// get tag if it exist
|
||||
if (($tag = $this->load->item([
|
||||
'linker' => $linker,
|
||||
'name' => $name
|
||||
], 'tag')) !== null)
|
||||
{
|
||||
return $tag;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Tag
|
||||
*
|
||||
* @param string $linker The linker GUID value
|
||||
* @param string $name The tag name
|
||||
*
|
||||
* @return bool True on success
|
||||
* @since 2.0.1
|
||||
**/
|
||||
private function create(
|
||||
string $linker,
|
||||
string $name
|
||||
): bool
|
||||
{
|
||||
$guid = (string) GuidHelper::get();
|
||||
while (!GuidHelper::valid($guid, 'tag', 0, '[[[component]]]'))
|
||||
{
|
||||
// must always be set
|
||||
$guid = (string) GuidHelper::get();
|
||||
}
|
||||
|
||||
return $this->insert->row([
|
||||
'access' => 0,
|
||||
'linker' => $linker,
|
||||
'name' => $name,
|
||||
'guid' => $guid
|
||||
], 'tag');
|
||||
}
|
39
src/67f91b8b-7b48-4dbb-bbd5-7945c174622a/settings.json
Normal file
39
src/67f91b8b-7b48-4dbb-bbd5-7945c174622a/settings.json
Normal file
@ -0,0 +1,39 @@
|
||||
{
|
||||
"add_head": "1",
|
||||
"add_licensing_template": "2",
|
||||
"extends": "0",
|
||||
"guid": "67f91b8b-7b48-4dbb-bbd5-7945c174622a",
|
||||
"implements": null,
|
||||
"load_selection": null,
|
||||
"name": "Tag",
|
||||
"power_version": "1.0.0",
|
||||
"system_name": "Joomla.GetBible.Tag",
|
||||
"type": "final class",
|
||||
"use_selection": {
|
||||
"use_selection0": {
|
||||
"use": "c03b9c61-17d3-4774-a335-783903719f83",
|
||||
"as": "default"
|
||||
},
|
||||
"use_selection1": {
|
||||
"use": "a07d90f6-6ff2-40a1-99c1-0f2cf33c9adf",
|
||||
"as": "default"
|
||||
},
|
||||
"use_selection2": {
|
||||
"use": "d7a5f0c6-de60-4d31-b3e4-5d668a8f7d2e",
|
||||
"as": "default"
|
||||
},
|
||||
"use_selection3": {
|
||||
"use": "36ab759f-7b42-4465-9c17-56ba1dd05f90",
|
||||
"as": "default"
|
||||
},
|
||||
"use_selection4": {
|
||||
"use": "9c513baf-b279-43fd-ae29-a585c8cbc4f0",
|
||||
"as": "default"
|
||||
}
|
||||
},
|
||||
"namespace": "VDM\\Joomla\\GetBible\\Tag",
|
||||
"description": "The GetBible Tag\r\n\r\n@since 2.0.1",
|
||||
"licensing_template": "\/**\r\n * @package GetBible\r\n *\r\n * @created 30th May, 2023\r\n * @author Llewellyn van der Merwe <https:\/\/dev.vdm.io>\r\n * @git GetBible <https:\/\/git.vdm.dev\/getBible>\r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n",
|
||||
"head": "use Joomla\\CMS\\Language\\Text;",
|
||||
"composer": ""
|
||||
}
|
@ -13,8 +13,8 @@
|
||||
class SessionHelper << (F,LightGreen) >> #Green {
|
||||
# Session $session
|
||||
+ __construct(?Session $session = null)
|
||||
+ getLinker() : string
|
||||
+ setLinker(string $linker) : bool
|
||||
+ get(string $name, mixed $default = null) : mixed
|
||||
+ set(string $name, mixed $value = null) : mixed
|
||||
}
|
||||
|
||||
note right of SessionHelper::__construct
|
||||
@ -23,16 +23,18 @@ note right of SessionHelper::__construct
|
||||
since: 3.2.0
|
||||
end note
|
||||
|
||||
note right of SessionHelper::getLinker
|
||||
Get the Active Linker GUID Value
|
||||
note right of SessionHelper::get
|
||||
Get data from the session store
|
||||
|
||||
return: string
|
||||
since: 2.1.0
|
||||
return: mixed
|
||||
end note
|
||||
|
||||
note right of SessionHelper::setLinker
|
||||
Set the Active Linker GUID Value
|
||||
note right of SessionHelper::set
|
||||
Set data into the session store.
|
||||
|
||||
return: bool
|
||||
since: 2.1.0
|
||||
return: mixed
|
||||
end note
|
||||
|
||||
@enduml
|
||||
|
@ -19,6 +19,7 @@ use VDM\Joomla\Utilities\GuidHelper;
|
||||
|
||||
/**
|
||||
* The GetBible Session Helper
|
||||
* - Just for easy set and get
|
||||
*
|
||||
* @since 2.0.1
|
||||
*/
|
||||
@ -45,43 +46,31 @@ final class SessionHelper
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Active Linker GUID Value
|
||||
* Get data from the session store
|
||||
*
|
||||
* @return string A Valid Linker GUID Value
|
||||
* @param string $name Name of a variable
|
||||
* @param mixed $default Default value of a variable if not set
|
||||
*
|
||||
* @return mixed Value of a variable
|
||||
* @since 2.1.0
|
||||
*/
|
||||
public function getLinker(): string
|
||||
public function get(string $name, $default = null)
|
||||
{
|
||||
$linker = $this->session->get('getbible_active_linker_guid', GuidHelper::get());
|
||||
|
||||
if (GuidHelper::valid($linker))
|
||||
{
|
||||
return $linker;
|
||||
}
|
||||
|
||||
$linker = GuidHelper::get();
|
||||
|
||||
$this->session->set('getbible_active_linker_guid', $linker);
|
||||
|
||||
return $linker;
|
||||
return $this->session->get($name, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Active Linker GUID Value
|
||||
* Set data into the session store.
|
||||
*
|
||||
* @param string $linker The linker GUID value.
|
||||
* @param string $name Name of a variable.
|
||||
* @param mixed $value Value of a variable.
|
||||
*
|
||||
* @return bool True on success
|
||||
* @return mixed Old value of a variable.
|
||||
* @since 2.1.0
|
||||
*/
|
||||
public function setLinker($linker): bool
|
||||
public function set($name, $value = null)
|
||||
{
|
||||
if (GuidHelper::valid($linker))
|
||||
{
|
||||
$this->session->set('getbible_active_linker_guid', $linker);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return $this->session->set($name, $value);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,41 +19,29 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Active Linker GUID Value
|
||||
* Get data from the session store
|
||||
*
|
||||
* @return string A Valid Linker GUID Value
|
||||
* @param string $name Name of a variable
|
||||
* @param mixed $default Default value of a variable if not set
|
||||
*
|
||||
* @return mixed Value of a variable
|
||||
* @since 2.1.0
|
||||
*/
|
||||
public function getLinker(): string
|
||||
public function get(string $name, $default = null)
|
||||
{
|
||||
$linker = $this->session->get('getbible_active_linker_guid', GuidHelper::get());
|
||||
|
||||
if (GuidHelper::valid($linker))
|
||||
{
|
||||
return $linker;
|
||||
}
|
||||
|
||||
$linker = GuidHelper::get();
|
||||
|
||||
$this->session->set('getbible_active_linker_guid', $linker);
|
||||
|
||||
return $linker;
|
||||
return $this->session->get($name, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Active Linker GUID Value
|
||||
* Set data into the session store.
|
||||
*
|
||||
* @param string $linker The linker GUID value.
|
||||
* @param string $name Name of a variable.
|
||||
* @param mixed $value Value of a variable.
|
||||
*
|
||||
* @return bool True on success
|
||||
* @return mixed Old value of a variable.
|
||||
* @since 2.1.0
|
||||
*/
|
||||
public function setLinker($linker): bool
|
||||
public function set($name, $value = null)
|
||||
{
|
||||
if (GuidHelper::valid($linker))
|
||||
{
|
||||
$this->session->set('getbible_active_linker_guid', $linker);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return $this->session->set($name, $value);
|
||||
}
|
@ -16,7 +16,7 @@
|
||||
}
|
||||
},
|
||||
"namespace": "VDM\\Joomla\\GetBible\\Utilities.SessionHelper",
|
||||
"description": "The GetBible Session Helper\r\n\r\n@since 2.0.1",
|
||||
"description": "The GetBible Session Helper\r\n - Just for easy set and get\r\n\r\n@since 2.0.1",
|
||||
"licensing_template": "\/**\r\n * @package GetBible\r\n *\r\n * @created 30th May, 2023\r\n * @author Llewellyn van der Merwe <https:\/\/dev.vdm.io>\r\n * @git GetBible <https:\/\/git.vdm.dev\/getBible>\r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n",
|
||||
"head": "use Joomla\\CMS\\Factory as JoomlaFactory;\r\nuse Joomla\\CMS\\Session\\Session;",
|
||||
"composer": ""
|
||||
|
@ -86,7 +86,7 @@ final class Insert
|
||||
*/
|
||||
public function row(array $item, string $table): bool
|
||||
{
|
||||
// check if object could be modelled
|
||||
// check if array could be modelled
|
||||
if (($item = $this->model->row($item, $table)) !== null)
|
||||
{
|
||||
// Insert the column of this table
|
||||
@ -107,7 +107,7 @@ final class Insert
|
||||
*/
|
||||
public function rows(?array $items, string $table): bool
|
||||
{
|
||||
// check if object could be modelled
|
||||
// check if arrays could be modelled
|
||||
if (($items = $this->model->rows($items, $table)) !== null)
|
||||
{
|
||||
// Insert the column of this table
|
||||
|
@ -61,7 +61,7 @@
|
||||
*/
|
||||
public function row(array $item, string $table): bool
|
||||
{
|
||||
// check if object could be modelled
|
||||
// check if array could be modelled
|
||||
if (($item = $this->model->row($item, $table)) !== null)
|
||||
{
|
||||
// Insert the column of this table
|
||||
@ -82,7 +82,7 @@
|
||||
*/
|
||||
public function rows(?array $items, string $table): bool
|
||||
{
|
||||
// check if object could be modelled
|
||||
// check if arrays could be modelled
|
||||
if (($items = $this->model->rows($items, $table)) !== null)
|
||||
{
|
||||
// Insert the column of this table
|
||||
|
97
src/ebda6bd8-95b9-468b-a521-974205146018/README.md
Normal file
97
src/ebda6bd8-95b9-468b-a521-974205146018/README.md
Normal file
@ -0,0 +1,97 @@
|
||||
```
|
||||
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
|
||||
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
|
||||
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
|
||||
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
|
||||
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
|
||||
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
|
||||
```
|
||||
# final class Note (Details)
|
||||
> namespace: **VDM\Joomla\GetBible**
|
||||
```uml
|
||||
@startuml
|
||||
class Note << (F,LightGreen) >> #Green {
|
||||
# Load $load
|
||||
# Insert $insert
|
||||
# Update $update
|
||||
# Linker $linker
|
||||
+ __construct(Load $load, Insert $insert, ...)
|
||||
+ set(int $book, int $chapter, ...) : ?array
|
||||
+ delete(string $note) : bool
|
||||
- get(string $linker, int $book, ...) : ?array
|
||||
- create(string $linker, int $book, ...) : bool
|
||||
}
|
||||
|
||||
note right of Note::__construct
|
||||
Constructor
|
||||
|
||||
since: 2.0.1
|
||||
|
||||
arguments:
|
||||
Load $load
|
||||
Insert $insert
|
||||
Update $update
|
||||
Linker $linker
|
||||
end note
|
||||
|
||||
note right of Note::set
|
||||
Set a note
|
||||
|
||||
since: 2.0.1
|
||||
return: ?array
|
||||
|
||||
arguments:
|
||||
int $book
|
||||
int $chapter
|
||||
int $verse
|
||||
?string $note
|
||||
end note
|
||||
|
||||
note right of Note::delete
|
||||
Delete a note
|
||||
|
||||
since: 2.0.1
|
||||
return: bool
|
||||
end note
|
||||
|
||||
note right of Note::get
|
||||
Get a note
|
||||
|
||||
since: 2.0.1
|
||||
return: ?array
|
||||
|
||||
arguments:
|
||||
string $linker
|
||||
int $book
|
||||
int $chapter
|
||||
int $verse
|
||||
end note
|
||||
|
||||
note right of Note::create
|
||||
Create a note
|
||||
|
||||
since: 2.0.1
|
||||
return: bool
|
||||
|
||||
arguments:
|
||||
string $linker
|
||||
int $book
|
||||
int $chapter
|
||||
int $verse
|
||||
?string $note
|
||||
end note
|
||||
|
||||
@enduml
|
||||
```
|
||||
|
||||
---
|
||||
```
|
||||
██╗ ██████╗██████╗
|
||||
██║██╔════╝██╔══██╗
|
||||
██║██║ ██████╔╝
|
||||
██ ██║██║ ██╔══██╗
|
||||
╚█████╔╝╚██████╗██████╔╝
|
||||
╚════╝ ╚═════╝╚═════╝
|
||||
```
|
||||
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)
|
||||
|
241
src/ebda6bd8-95b9-468b-a521-974205146018/code.php
Normal file
241
src/ebda6bd8-95b9-468b-a521-974205146018/code.php
Normal file
@ -0,0 +1,241 @@
|
||||
<?php
|
||||
/**
|
||||
* @package GetBible
|
||||
*
|
||||
* @created 30th May, 2023
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git GetBible <https://git.vdm.dev/getBible>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\GetBible;
|
||||
|
||||
|
||||
use Joomla\CMS\Language\Text;
|
||||
use VDM\Joomla\GetBible\Database\Load;
|
||||
use VDM\Joomla\GetBible\Database\Insert;
|
||||
use VDM\Joomla\GetBible\Database\Update;
|
||||
use VDM\Joomla\GetBible\Linker;
|
||||
use VDM\Joomla\Utilities\GuidHelper;
|
||||
|
||||
|
||||
/**
|
||||
* The GetBible Note
|
||||
*
|
||||
* @since 2.0.1
|
||||
*/
|
||||
final class Note
|
||||
{
|
||||
/**
|
||||
* The Load class
|
||||
*
|
||||
* @var Load
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Load $load;
|
||||
|
||||
/**
|
||||
* The Insert class
|
||||
*
|
||||
* @var Insert
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Insert $insert;
|
||||
|
||||
/**
|
||||
* The Update class
|
||||
*
|
||||
* @var Update
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Update $update;
|
||||
|
||||
/**
|
||||
* The Linker class
|
||||
*
|
||||
* @var Linker
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Linker $linker;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Load $load The load object.
|
||||
* @param Insert $insert The insert object.
|
||||
* @param Update $update The update object.
|
||||
* @param Linker $linker The linker object.
|
||||
*
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function __construct(
|
||||
Load $load,
|
||||
Insert $insert,
|
||||
Update $update,
|
||||
Linker $linker)
|
||||
{
|
||||
$this->load = $load;
|
||||
$this->insert = $insert;
|
||||
$this->update = $update;
|
||||
$this->linker = $linker;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a note
|
||||
*
|
||||
* @param int $book The book in which the note is made
|
||||
* @param int $chapter The chapter in which the note is made
|
||||
* @param int $verse The verse where the note is made
|
||||
* @param string|null $note The note being made
|
||||
*
|
||||
* @return array|null Array of the note values on success
|
||||
* @since 2.0.1
|
||||
**/
|
||||
public function set(
|
||||
int $book,
|
||||
int $chapter,
|
||||
int $verse,
|
||||
?string $note
|
||||
): ?array
|
||||
{
|
||||
// make sure the linker has access
|
||||
if (($linker = $this->linker->get()) === null)
|
||||
{
|
||||
return [
|
||||
'error' => Text::_('COM_GETBIBLE_YOU_DO_NOT_HAVE_ACCESS_TO_PERFORM_THIS_ACTION'),
|
||||
'function' => 'setLinkerAccess'
|
||||
];
|
||||
}
|
||||
|
||||
// get note if it exist
|
||||
if (($_note = $this->get($linker, $book, $chapter, $verse)) !== null)
|
||||
{
|
||||
// publish if not published
|
||||
if ($_note->published != 1 && !$this->update->value(1, 'published', $_note->id, 'id', 'note'))
|
||||
{
|
||||
return [
|
||||
'error' => Text::_('COM_GETBIBLE_NOTE_ALREADY_EXIST_BUT_COULD_NOT_BE_REACTIVATED')
|
||||
];
|
||||
}
|
||||
|
||||
// update the note if needed
|
||||
if ($_note->note !== $note && !$this->update->value($note, 'note', $_note->id, 'id', 'note'))
|
||||
{
|
||||
return [
|
||||
'error' => Text::_('COM_GETBIBLE_NOTE_ALREADY_EXIST_BUT_COULD_NOT_UPDATE_THE_NOTE_TEXT')
|
||||
];
|
||||
}
|
||||
|
||||
$_note->published = 1;
|
||||
$_note->note = $note;
|
||||
$_note->success = Text::_('COM_GETBIBLE_THE_NOTE_WAS_SUCCESSFULLY_UPDATED');
|
||||
return (array) $_note;
|
||||
}
|
||||
// create a new tag
|
||||
elseif ($this->create($linker, $book, $chapter, $verse, $note)
|
||||
&& ($_note = $this->get($linker, $book, $chapter, $verse)) !== null)
|
||||
{
|
||||
$_note->success = Text::_('COM_GETBIBLE_THE_NOTE_WAS_SUCCESSFULLY_CREATED');
|
||||
return (array) $_note;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a note
|
||||
*
|
||||
* @param string $note The note GUID value
|
||||
*
|
||||
* @return bool True on success
|
||||
* @since 2.0.1
|
||||
**/
|
||||
public function delete(string $note): bool
|
||||
{
|
||||
// make sure the linker has access
|
||||
if (($linker = $this->linker->get()) === null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// make sure the linker has access to delete this tag
|
||||
if (($id = $this->load->value(['guid' => $note, 'linker' => $linker], 'id', 'note')) !== null && $id > 0)
|
||||
{
|
||||
return $this->update->value(-2, 'published', $id, 'id', 'note');
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a note
|
||||
*
|
||||
* @param string $linker The linker GUID value
|
||||
* @param int $book The book in which the note is made
|
||||
* @param int $chapter The chapter in which the note is made
|
||||
* @param int $verse The verse where the note is made
|
||||
*
|
||||
* @return array|null Array of the note values on success
|
||||
* @since 2.0.1
|
||||
**/
|
||||
private function get(
|
||||
string $linker,
|
||||
int $book,
|
||||
int $chapter,
|
||||
int $verse
|
||||
): ?array
|
||||
{
|
||||
// get note if it exist
|
||||
if (($note = $this->load->item([
|
||||
'linker' => $linker,
|
||||
'book' => $book,
|
||||
'chapter' => $chapter,
|
||||
'verse' => $verse
|
||||
], 'note')) !== null)
|
||||
{
|
||||
return $note;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a note
|
||||
*
|
||||
* @param string $linker The linker GUID value
|
||||
* @param int $book The book in which the note is made
|
||||
* @param int $chapter The chapter in which the note is made
|
||||
* @param int $verse The verse where the note is made
|
||||
* @param string|null $note The note being created (allow empty notes)
|
||||
*
|
||||
* @return bool True on success
|
||||
* @since 2.0.1
|
||||
**/
|
||||
private function create(
|
||||
string $linker,
|
||||
int $book,
|
||||
int $chapter,
|
||||
int $verse,
|
||||
?string $note
|
||||
): bool
|
||||
{
|
||||
$guid = (string) GuidHelper::get();
|
||||
while (!GuidHelper::valid($guid, 'note', 0, 'getbible'))
|
||||
{
|
||||
// must always be set
|
||||
$guid = (string) GuidHelper::get();
|
||||
}
|
||||
|
||||
return $this->insert->row([
|
||||
'note' => $note ?? '',
|
||||
'access' => 0,
|
||||
'linker' => $linker,
|
||||
'book' => $book,
|
||||
'chapter' => $chapter,
|
||||
'verse' => $verse,
|
||||
'guid' => $guid
|
||||
], 'note');
|
||||
}
|
||||
}
|
||||
|
210
src/ebda6bd8-95b9-468b-a521-974205146018/code.power
Normal file
210
src/ebda6bd8-95b9-468b-a521-974205146018/code.power
Normal file
@ -0,0 +1,210 @@
|
||||
/**
|
||||
* The Load class
|
||||
*
|
||||
* @var Load
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Load $load;
|
||||
|
||||
/**
|
||||
* The Insert class
|
||||
*
|
||||
* @var Insert
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Insert $insert;
|
||||
|
||||
/**
|
||||
* The Update class
|
||||
*
|
||||
* @var Update
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Update $update;
|
||||
|
||||
/**
|
||||
* The Linker class
|
||||
*
|
||||
* @var Linker
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Linker $linker;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Load $load The load object.
|
||||
* @param Insert $insert The insert object.
|
||||
* @param Update $update The update object.
|
||||
* @param Linker $linker The linker object.
|
||||
*
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function __construct(
|
||||
Load $load,
|
||||
Insert $insert,
|
||||
Update $update,
|
||||
Linker $linker)
|
||||
{
|
||||
$this->load = $load;
|
||||
$this->insert = $insert;
|
||||
$this->update = $update;
|
||||
$this->linker = $linker;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a note
|
||||
*
|
||||
* @param int $book The book in which the note is made
|
||||
* @param int $chapter The chapter in which the note is made
|
||||
* @param int $verse The verse where the note is made
|
||||
* @param string|null $note The note being made
|
||||
*
|
||||
* @return array|null Array of the note values on success
|
||||
* @since 2.0.1
|
||||
**/
|
||||
public function set(
|
||||
int $book,
|
||||
int $chapter,
|
||||
int $verse,
|
||||
?string $note
|
||||
): ?array
|
||||
{
|
||||
// make sure the linker has access
|
||||
if (($linker = $this->linker->get()) === null)
|
||||
{
|
||||
return [
|
||||
'error' => Text::_('You do not have access to perform this action'),
|
||||
'function' => 'setLinkerAccess'
|
||||
];
|
||||
}
|
||||
|
||||
// get note if it exist
|
||||
if (($_note = $this->get($linker, $book, $chapter, $verse)) !== null)
|
||||
{
|
||||
// publish if not published
|
||||
if ($_note->published != 1 && !$this->update->value(1, 'published', $_note->id, 'id', 'note'))
|
||||
{
|
||||
return [
|
||||
'error' => Text::_('Note already exist, but could not be reactivated.')
|
||||
];
|
||||
}
|
||||
|
||||
// update the note if needed
|
||||
if ($_note->note !== $note && !$this->update->value($note, 'note', $_note->id, 'id', 'note'))
|
||||
{
|
||||
return [
|
||||
'error' => Text::_('Note already exist, but could not update the note text.')
|
||||
];
|
||||
}
|
||||
|
||||
$_note->published = 1;
|
||||
$_note->note = $note;
|
||||
$_note->success = Text::_('The note was successfully updated.');
|
||||
return (array) $_note;
|
||||
}
|
||||
// create a new tag
|
||||
elseif ($this->create($linker, $book, $chapter, $verse, $note)
|
||||
&& ($_note = $this->get($linker, $book, $chapter, $verse)) !== null)
|
||||
{
|
||||
$_note->success = Text::_('The note was successfully created.');
|
||||
return (array) $_note;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a note
|
||||
*
|
||||
* @param string $note The note GUID value
|
||||
*
|
||||
* @return bool True on success
|
||||
* @since 2.0.1
|
||||
**/
|
||||
public function delete(string $note): bool
|
||||
{
|
||||
// make sure the linker has access
|
||||
if (($linker = $this->linker->get()) === null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// make sure the linker has access to delete this tag
|
||||
if (($id = $this->load->value(['guid' => $note, 'linker' => $linker], 'id', 'note')) !== null && $id > 0)
|
||||
{
|
||||
return $this->update->value(-2, 'published', $id, 'id', 'note');
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a note
|
||||
*
|
||||
* @param string $linker The linker GUID value
|
||||
* @param int $book The book in which the note is made
|
||||
* @param int $chapter The chapter in which the note is made
|
||||
* @param int $verse The verse where the note is made
|
||||
*
|
||||
* @return array|null Array of the note values on success
|
||||
* @since 2.0.1
|
||||
**/
|
||||
private function get(
|
||||
string $linker,
|
||||
int $book,
|
||||
int $chapter,
|
||||
int $verse
|
||||
): ?array
|
||||
{
|
||||
// get note if it exist
|
||||
if (($note = $this->load->item([
|
||||
'linker' => $linker,
|
||||
'book' => $book,
|
||||
'chapter' => $chapter,
|
||||
'verse' => $verse
|
||||
], 'note')) !== null)
|
||||
{
|
||||
return $note;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a note
|
||||
*
|
||||
* @param string $linker The linker GUID value
|
||||
* @param int $book The book in which the note is made
|
||||
* @param int $chapter The chapter in which the note is made
|
||||
* @param int $verse The verse where the note is made
|
||||
* @param string|null $note The note being created (allow empty notes)
|
||||
*
|
||||
* @return bool True on success
|
||||
* @since 2.0.1
|
||||
**/
|
||||
private function create(
|
||||
string $linker,
|
||||
int $book,
|
||||
int $chapter,
|
||||
int $verse,
|
||||
?string $note
|
||||
): bool
|
||||
{
|
||||
$guid = (string) GuidHelper::get();
|
||||
while (!GuidHelper::valid($guid, 'note', 0, '[[[component]]]'))
|
||||
{
|
||||
// must always be set
|
||||
$guid = (string) GuidHelper::get();
|
||||
}
|
||||
|
||||
return $this->insert->row([
|
||||
'note' => $note ?? '',
|
||||
'access' => 0,
|
||||
'linker' => $linker,
|
||||
'book' => $book,
|
||||
'chapter' => $chapter,
|
||||
'verse' => $verse,
|
||||
'guid' => $guid
|
||||
], 'note');
|
||||
}
|
39
src/ebda6bd8-95b9-468b-a521-974205146018/settings.json
Normal file
39
src/ebda6bd8-95b9-468b-a521-974205146018/settings.json
Normal file
@ -0,0 +1,39 @@
|
||||
{
|
||||
"add_head": "1",
|
||||
"add_licensing_template": "2",
|
||||
"extends": "0",
|
||||
"guid": "ebda6bd8-95b9-468b-a521-974205146018",
|
||||
"implements": null,
|
||||
"load_selection": null,
|
||||
"name": "Note",
|
||||
"power_version": "1.0.0",
|
||||
"system_name": "Joomla.GetBible.Note",
|
||||
"type": "final class",
|
||||
"use_selection": {
|
||||
"use_selection0": {
|
||||
"use": "c03b9c61-17d3-4774-a335-783903719f83",
|
||||
"as": "default"
|
||||
},
|
||||
"use_selection1": {
|
||||
"use": "a07d90f6-6ff2-40a1-99c1-0f2cf33c9adf",
|
||||
"as": "default"
|
||||
},
|
||||
"use_selection2": {
|
||||
"use": "d7a5f0c6-de60-4d31-b3e4-5d668a8f7d2e",
|
||||
"as": "default"
|
||||
},
|
||||
"use_selection3": {
|
||||
"use": "36ab759f-7b42-4465-9c17-56ba1dd05f90",
|
||||
"as": "default"
|
||||
},
|
||||
"use_selection4": {
|
||||
"use": "9c513baf-b279-43fd-ae29-a585c8cbc4f0",
|
||||
"as": "default"
|
||||
}
|
||||
},
|
||||
"namespace": "VDM\\Joomla\\GetBible\\Note",
|
||||
"description": "The GetBible Note\r\n\r\n@since 2.0.1",
|
||||
"licensing_template": "\/**\r\n * @package GetBible\r\n *\r\n * @created 30th May, 2023\r\n * @author Llewellyn van der Merwe <https:\/\/dev.vdm.io>\r\n * @git GetBible <https:\/\/git.vdm.dev\/getBible>\r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n",
|
||||
"head": "use Joomla\\CMS\\Language\\Text;",
|
||||
"composer": ""
|
||||
}
|
@ -115,76 +115,76 @@ class Table extends BaseTable implements Tableinterface
|
||||
'tab_name' => 'Details',
|
||||
],
|
||||
],
|
||||
'taged_verse' => [
|
||||
'tagged_verse' => [
|
||||
'book_nr' => [
|
||||
'name' => 'book_nr',
|
||||
'label' => 'COM_GETBIBLE_TAGED_VERSE_BOOK_NR_LABEL',
|
||||
'label' => 'COM_GETBIBLE_TAGGED_VERSE_BOOK_NR_LABEL',
|
||||
'type' => 'number',
|
||||
'title' => false,
|
||||
'list' => 'taged_verses',
|
||||
'list' => 'tagged_verses',
|
||||
'store' => NULL,
|
||||
'tab_name' => 'Details',
|
||||
],
|
||||
'abbreviation' => [
|
||||
'name' => 'abbreviation',
|
||||
'label' => 'COM_GETBIBLE_TAGED_VERSE_ABBREVIATION_LABEL',
|
||||
'label' => 'COM_GETBIBLE_TAGGED_VERSE_ABBREVIATION_LABEL',
|
||||
'type' => 'translations',
|
||||
'title' => false,
|
||||
'list' => 'taged_verses',
|
||||
'list' => 'tagged_verses',
|
||||
'store' => NULL,
|
||||
'tab_name' => 'Details',
|
||||
],
|
||||
'access' => [
|
||||
'name' => 'access',
|
||||
'label' => 'COM_GETBIBLE_TAGED_VERSE_ACCESS_LABEL',
|
||||
'label' => 'COM_GETBIBLE_TAGGED_VERSE_ACCESS_LABEL',
|
||||
'type' => 'radio',
|
||||
'title' => false,
|
||||
'list' => 'taged_verses',
|
||||
'list' => 'tagged_verses',
|
||||
'store' => NULL,
|
||||
'tab_name' => 'Details',
|
||||
],
|
||||
'linker' => [
|
||||
'name' => 'linker',
|
||||
'label' => 'COM_GETBIBLE_TAGED_VERSE_LINKER_LABEL',
|
||||
'label' => 'COM_GETBIBLE_TAGGED_VERSE_LINKER_LABEL',
|
||||
'type' => 'linkers',
|
||||
'title' => false,
|
||||
'list' => 'taged_verses',
|
||||
'list' => 'tagged_verses',
|
||||
'store' => NULL,
|
||||
'tab_name' => 'Details',
|
||||
],
|
||||
'tag' => [
|
||||
'name' => 'tag',
|
||||
'label' => 'COM_GETBIBLE_TAGED_VERSE_TAG_LABEL',
|
||||
'label' => 'COM_GETBIBLE_TAGGED_VERSE_TAG_LABEL',
|
||||
'type' => 'tagers',
|
||||
'title' => false,
|
||||
'list' => 'taged_verses',
|
||||
'list' => 'tagged_verses',
|
||||
'store' => NULL,
|
||||
'tab_name' => 'Details',
|
||||
],
|
||||
'guid' => [
|
||||
'name' => 'guid',
|
||||
'label' => 'COM_GETBIBLE_TAGED_VERSE_GUID_LABEL',
|
||||
'label' => 'COM_GETBIBLE_TAGGED_VERSE_GUID_LABEL',
|
||||
'type' => 'text',
|
||||
'title' => false,
|
||||
'list' => 'taged_verses',
|
||||
'list' => 'tagged_verses',
|
||||
'store' => NULL,
|
||||
'tab_name' => 'publishing',
|
||||
],
|
||||
'verse' => [
|
||||
'name' => 'verse',
|
||||
'label' => 'COM_GETBIBLE_TAGED_VERSE_VERSE_LABEL',
|
||||
'label' => 'COM_GETBIBLE_TAGGED_VERSE_VERSE_LABEL',
|
||||
'type' => 'number',
|
||||
'title' => false,
|
||||
'list' => 'taged_verses',
|
||||
'list' => 'tagged_verses',
|
||||
'store' => NULL,
|
||||
'tab_name' => 'Details',
|
||||
],
|
||||
'chapter' => [
|
||||
'name' => 'chapter',
|
||||
'label' => 'COM_GETBIBLE_TAGED_VERSE_CHAPTER_LABEL',
|
||||
'label' => 'COM_GETBIBLE_TAGGED_VERSE_CHAPTER_LABEL',
|
||||
'type' => 'number',
|
||||
'title' => false,
|
||||
'list' => 'taged_verses',
|
||||
'list' => 'tagged_verses',
|
||||
'store' => NULL,
|
||||
'tab_name' => 'Details',
|
||||
],
|
||||
|
@ -32,6 +32,17 @@
|
||||
"spk": "Super__17d87374_2953_4d6c_9fdd_4220d6ad1564__Power",
|
||||
"guid": "17d87374-2953-4d6c-9fdd-4220d6ad1564"
|
||||
},
|
||||
"2315a1c5-bcf6-401a-8d11-60f4d6d12dbb": {
|
||||
"name": "Tagged",
|
||||
"type": "final class",
|
||||
"namespace": "VDM\\Joomla\\GetBible",
|
||||
"code": "src\/2315a1c5-bcf6-401a-8d11-60f4d6d12dbb\/code.php",
|
||||
"power": "src\/2315a1c5-bcf6-401a-8d11-60f4d6d12dbb\/code.power",
|
||||
"settings": "src\/2315a1c5-bcf6-401a-8d11-60f4d6d12dbb\/settings.json",
|
||||
"path": "src\/2315a1c5-bcf6-401a-8d11-60f4d6d12dbb",
|
||||
"spk": "Super__2315a1c5_bcf6_401a_8d11_60f4d6d12dbb__Power",
|
||||
"guid": "2315a1c5-bcf6-401a-8d11-60f4d6d12dbb"
|
||||
},
|
||||
"3439e63b-d8f1-42ce-a765-60d56b1fbe21": {
|
||||
"name": "Data",
|
||||
"type": "class",
|
||||
@ -43,6 +54,17 @@
|
||||
"spk": "Super__3439e63b_d8f1_42ce_a765_60d56b1fbe21__Power",
|
||||
"guid": "3439e63b-d8f1-42ce-a765-60d56b1fbe21"
|
||||
},
|
||||
"36ab759f-7b42-4465-9c17-56ba1dd05f90": {
|
||||
"name": "Linker",
|
||||
"type": "final class",
|
||||
"namespace": "VDM\\Joomla\\GetBible",
|
||||
"code": "src\/36ab759f-7b42-4465-9c17-56ba1dd05f90\/code.php",
|
||||
"power": "src\/36ab759f-7b42-4465-9c17-56ba1dd05f90\/code.power",
|
||||
"settings": "src\/36ab759f-7b42-4465-9c17-56ba1dd05f90\/settings.json",
|
||||
"path": "src\/36ab759f-7b42-4465-9c17-56ba1dd05f90",
|
||||
"spk": "Super__36ab759f_7b42_4465_9c17_56ba1dd05f90__Power",
|
||||
"guid": "36ab759f-7b42-4465-9c17-56ba1dd05f90"
|
||||
},
|
||||
"3af7864b-f1f3-491e-b16f-0504f890086d": {
|
||||
"name": "Config",
|
||||
"type": "class",
|
||||
@ -120,6 +142,17 @@
|
||||
"spk": "Super__56465044_94ed_4e00_b6db_160c67163df8__Power",
|
||||
"guid": "56465044-94ed-4e00-b6db-160c67163df8"
|
||||
},
|
||||
"67f91b8b-7b48-4dbb-bbd5-7945c174622a": {
|
||||
"name": "Tag",
|
||||
"type": "final class",
|
||||
"namespace": "VDM\\Joomla\\GetBible",
|
||||
"code": "src\/67f91b8b-7b48-4dbb-bbd5-7945c174622a\/code.php",
|
||||
"power": "src\/67f91b8b-7b48-4dbb-bbd5-7945c174622a\/code.power",
|
||||
"settings": "src\/67f91b8b-7b48-4dbb-bbd5-7945c174622a\/settings.json",
|
||||
"path": "src\/67f91b8b-7b48-4dbb-bbd5-7945c174622a",
|
||||
"spk": "Super__67f91b8b_7b48_4dbb_bbd5_7945c174622a__Power",
|
||||
"guid": "67f91b8b-7b48-4dbb-bbd5-7945c174622a"
|
||||
},
|
||||
"71075f03-4e77-4fc0-840a-ef55fd9260b2": {
|
||||
"name": "Config",
|
||||
"type": "class",
|
||||
@ -384,6 +417,17 @@
|
||||
"spk": "Super__e3798c7e_aae1_4e38_ba78_6018ce94630b__Power",
|
||||
"guid": "e3798c7e-aae1-4e38-ba78-6018ce94630b"
|
||||
},
|
||||
"ebda6bd8-95b9-468b-a521-974205146018": {
|
||||
"name": "Note",
|
||||
"type": "final class",
|
||||
"namespace": "VDM\\Joomla\\GetBible",
|
||||
"code": "src\/ebda6bd8-95b9-468b-a521-974205146018\/code.php",
|
||||
"power": "src\/ebda6bd8-95b9-468b-a521-974205146018\/code.power",
|
||||
"settings": "src\/ebda6bd8-95b9-468b-a521-974205146018\/settings.json",
|
||||
"path": "src\/ebda6bd8-95b9-468b-a521-974205146018",
|
||||
"spk": "Super__ebda6bd8_95b9_468b_a521_974205146018__Power",
|
||||
"guid": "ebda6bd8-95b9-468b-a521-974205146018"
|
||||
},
|
||||
"ed16a9c4-e026-4d16-be60-81892ce7c6a9": {
|
||||
"name": "Engineer",
|
||||
"type": "final class",
|
||||
|
Loading…
x
Reference in New Issue
Block a user