Commit 448440cc authored by Fabrice Gangler's avatar Fabrice Gangler 🎨 Committed by Fabrice Gangler
Browse files

FEAT(ui.software 721): WIP / add Software Heritage badge to software view + update software entity

# TODO
bin/cake migrations migrate

refs: 721
parent e9bc61b2
......@@ -19,6 +19,7 @@ use Cake\Utility\Text;
* @property Time $modified
* @property string $logo_directory
* @property $photo
* @property boolean $software_heritage_archived
* @property Review[] $reviews
* @property Screenshot[] $screenshots
* @property Relationship[] $relationships
......@@ -38,6 +39,7 @@ class Software extends Entity
protected $_accessible = [
'*' => true,
'id' => false,
'software_heritage_archived' => false,
'tag_string' => true,
];
......@@ -81,6 +83,73 @@ class Software extends Entity
return $average ;
}
/**
* Return the
*
* @return string
*/
protected function _getSoftwareHeritageBrowseUrl()
{
$url = '';
if($this->_properties['software_heritage_archived'] === true){
$cloneUrl = $this->_getCloneUrl();
$url = "https://archive.softwareheritage.org/browse/origin/$cloneUrl/";
}
return $url;
}
/**
* Return the
*
* @return string
*/
protected function _getSoftwareHeritageBadgeUrl()
{
$cloneUrl = $this->_getCloneUrl();
$url = "https://archive.softwareheritage.org/badge/origin/$cloneUrl/";
return $url;
}
/**
* Return the clone URL
* - For GitLab-based platforms, add the '.git' suffix
* to the url when it is not present.
*
* @return string
*/
protected function _getCloneUrl()
{
$url = trim($this->_properties['url_repository']);
if ($this->isGitLabBasedPlatform($url)) {
// if the last character is an '/', delete it
if (substr($url, -1,1) === '/') {
$url = substr($url , 0, -1);
}
// add the sufix '.git' if not present
if (substr($url, -4,4) !== '.git') {
$url .= '.git';
}
}
return $url;
}
/**
* Is GitLab-based platform ?
* = does the URL repository contain gitlab?
*
* @param string $url
* @return bool
*/
private function isGitLabBasedPlatform(string $url){
if (stristr($url, 'gitlab') !== false) {
return true;
}
return false;
}
/**
* Get software slug for using it in URL
* @return string
......
......@@ -78,6 +78,31 @@
<?= $this->Tag->display($software->tags) ?>
</ul>
</li>
<?php if (1 OR $software->software_heritage_archived) : ?>
<li>
<br>
<img width="50px" src="https://www.softwareheritage.org/wp-content/uploads/2015/08/swh-logo.png">
présent sur <em>Software Heritage</em> <br>
<a href="<?= $software->software_heritage_browse_url ?>">
<img src="<?= $software->software_heritage_badge_url ?>">
</a>
<br>
<br>
<br>
</li>
<li>
<a href="<?= $software->software_heritage_browse_url ?>">
<img width="50px" src="https://www.softwareheritage.org/wp-content/uploads/2015/08/swh-logo.png">
présent sur <em>Software Heritage</em>
</a>
<pre style="font-size: 70%">DEBUG
<br>url_repository <?= $software->url_repository ?>
<br>clone_url <?= $software->clone_url ?>
<br>SH_badge_url <?= $software->software_heritage_badge_url ?>
<br>SH_browse_url <?= $software->software_heritage_browse_url ?>
</pre>
</li>
<?php endif; ?>
<li>
<?= $this->Html->link(__d("Softwares","Edit"),
['prefix'=>false,'controller' => $this->request->controller, 'action' => "edit",$software->id],
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment