Skip to content

Commit

Permalink
Squashed commit of version 1.1.0 from develop branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Jefferson49 committed Sep 27, 2022
1 parent 1e0f353 commit e0b38e2
Show file tree
Hide file tree
Showing 51 changed files with 5,351 additions and 765 deletions.
128 changes: 108 additions & 20 deletions CallNumberCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@

namespace Jefferson49\Webtrees\Module\RepositoryHierarchyNamespace;

use Cissee\WebtreesExt\MoreI18N;
use Fisharebest\Webtrees\Date;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Source;
use Fisharebest\Webtrees\Tree;

use function md5;
use Fisharebest\Webtrees\Repository;

class CallNumberCategory {

Expand Down Expand Up @@ -81,6 +84,9 @@ class CallNumberCategory {
//List of related sub categories. Provides a recursive structure for a hierarchy of sub categories
private array $sub_categories = [];

//Overall date range of the category
private ?Date $overall_date_range = null;


/**
* Constructor.
Expand Down Expand Up @@ -162,7 +168,7 @@ public function getFrontEndName(bool $get_full_name = false): string {
}

if (strpos($name, CallNumberCategory::EMPTY_CATEGORY_NAME) !== false) {
return I18N::translate('Sources without call number');
return MoreI18N::xlate('Sources without call number');
} elseif (strpos($name, CallNumberCategory::DEFAULT_CATEGORY_NAME) !== false) {
return I18N::translate('Default call number category');
} else {
Expand Down Expand Up @@ -206,7 +212,81 @@ public function getSources(): array {
return $this->sources;
}

/**
* Get sub categories
*
* @return array
*/
public function getSubCategories(): array {
return $this->sub_categories;
}

/**
* Get overall date range
*
* @return Date
*/
public function getOverallDateRange(): ?Date {
return $this->overall_date_range;
}

/**
* Add source
*
* @param Source
*/
public function addSource(Source $source) {
array_push($this->sources, $source);
}

/**
* Add sub category
*
* @param CallNumberCategory
*/
public function addSubCategory(CallNumberCategory $sub_category) {
array_push($this->sub_categories, $sub_category);
}

/**
* Calculate date range
*
* @param CallNumberCategory
*
* @return Date
*/
public function calculateDateRange(): ?Date {

$date_ranges = [];

//Collect all date ranges for sub categories
$sub_categories = $this->getSubCategories();

foreach($sub_categories as $sub_category){

$date_range = $sub_category->calculateDateRange();
if($date_range !== null) {
array_push($date_ranges, $date_range);
}
}

//Collect all date ranges for sources
$sources = $this->sources;

foreach($sources as $source) {

$date_range = Functions::getDateRangeForSource($source);
if($date_range !== null) {
array_push($date_ranges, $date_range);
}
}

$this->overall_date_range = Functions::getOverallDateRange($date_ranges);

return $this->overall_date_range;
}

/**
* Add truncated call number for a source to the truncated call numbers list
*
* @param Source
Expand All @@ -233,30 +313,38 @@ public function getTruncatedCallNumber(Source $source): string {
}

/**
* Get sub categories
* Get call number for a source in a repository
*
* @return array
*/
public function getSubCategories(): array {
return $this->sub_categories;
}

/**
* Add source
* @param Source $source
* @param Repository $repository
* @param bool $truncated
*
* @param Source
* @return string
*/
public function addSource(Source $source) {
array_push($this->sources, $source);
public function getCallNumber(Source $source, Repository $repository, bool $truncated = false): string{

if($truncated) {
return $this->getTruncatedCallNumber($source);
} else {
return Functions::getCallNumberForSource($source, $repository);
}
}

/**
* Add sub category
/**
* Display date range
*
* @param CallNumberCategory
*/
public function addSubCategory(CallNumberCategory $sub_category) {
array_push($this->sub_categories, $sub_category);
}
* @param string $delimiter [ISO 8601 allows: '/' odr '--']
*
* @return string
*/
public function displayISODateRange(string $delimiter = '/'): string {

if(($this->overall_date_range !== null) && $this->overall_date_range->isOK()) {
{
return Functions::getISOformatForDateRange($this->overall_date_range, $delimiter );
}
}
return '';
}

}
11 changes: 5 additions & 6 deletions CallNumberFixAction.php → CallNumberDataFix.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@

namespace Jefferson49\Webtrees\Module\RepositoryHierarchyNamespace;

use Fisharebest\Webtrees\Http\ViewResponseTrait;
use Cissee\WebtreesExt\MoreI18N;
use Fisharebest\Webtrees\Http\RequestHandlers\PendingChanges;
use Fisharebest\Webtrees\Http\ViewResponseTrait;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Module\ModuleDataFixInterface;
use Fisharebest\Webtrees\Services\ModuleService;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Validator;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
Expand All @@ -40,12 +41,10 @@
/**
* Run data-fix for call number categories
*/
class CallNumberFixAction implements RequestHandlerInterface
class CallNumberDataFix implements RequestHandlerInterface
{
use ViewResponseTrait;

protected const MODULE_NAME = '_fix_call_numbers_';

private ModuleService $module_service;

/**
Expand Down Expand Up @@ -91,7 +90,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface
}

//Default: continue with general data fix selection
$title = I18N::translate('Data fixes') . '' . e($tree->title());
$title = MoreI18N::xlate('Data fixes') . '' . e($tree->title());
$data_fixes = $this->module_service->findByInterface(ModuleDataFixInterface::class, false, true);

return $this->viewResponse('admin/data-fix-select', [
Expand Down
15 changes: 14 additions & 1 deletion CreateSourceModalAction.php → CreateSourceModal.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

namespace Jefferson49\Webtrees\Module\RepositoryHierarchyNamespace;

use Fisharebest\Webtrees\Auth;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Validator;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
Expand All @@ -36,7 +38,7 @@
/**
* Process a form to create a new source.
*/
class CreateSourceModalAction implements RequestHandlerInterface
class CreateSourceModal implements RequestHandlerInterface
{
/**
* @param ServerRequestInterface $request
Expand All @@ -46,9 +48,20 @@ class CreateSourceModalAction implements RequestHandlerInterface
public function handle(ServerRequestInterface $request): ResponseInterface
{
$tree = Validator::attributes($request)->tree();
$user = Validator::attributes($request)->user();
$source_repository = Validator::attributes($request)->string('xref');
$source_call_number = Validator::attributes($request)->string('source_call_number');

//If no user is logged in, show error text
if (Auth::accessLevel($tree, $user) === Auth::PRIV_PRIVATE) {
$error_text = I18N::translate('Currently, you do not have the user rights to create new sources. In order to create new sources, you need to be logged in as a user.');

return response(view(RepositoryHierarchy::MODULE_NAME . '::modals/message', [
'title' => I18N::translate('Create new sources'),
'text' => $error_text,
]));
}

return response(view(RepositoryHierarchy::MODULE_NAME . '::modals/create-source', [
'tree' => $tree,
'source_repository' => $source_repository,
Expand Down
Loading

0 comments on commit e0b38e2

Please sign in to comment.