Skip to content

Fixed the way more-info urls are returned when listing all libraries #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -412,25 +412,42 @@ private function checkIfBuiltInExampleFolderExists($library)
private function getExternalLibrariesList()
{
$entityManager = $this->getDoctrine()->getManager();
$externalMeta = $entityManager->getRepository('CodebenderLibraryBundle:ExternalLibrary')->findBy(array('active' => true));
$librariesEntities = $entityManager->getRepository('CodebenderLibraryBundle:ExternalLibrary')
->findBy(['active' => true]);

$libraries = array();
foreach ($externalMeta as $library) {
$libraries = [];
foreach ($librariesEntities as $library) {
/* @var ExternalLibrary $library */
$libraryMachineName = $library->getMachineName();
if (!isset($libraries[$libraryMachineName])) {
$libraries[$libraryMachineName] = array("description" => $library->getDescription(), "humanName" => $library->getHumanName(), "examples" => array());
if (isset($libraries[$libraryMachineName])) {
continue;
}

if ($library->getOwner() !== null && $library->getRepo() !== null) {
$libraries[$libraryMachineName] = array("description" => $library->getDescription(), "humanName" => $library->getHumanName(), "url" => "http://github.com/" . $library->getOwner() . "/" . $library->getRepo(), "examples" => array());
}
$libraries[$libraryMachineName] = [
'description' => $library->getDescription(),
'humanName' => $library->getHumanName(),
'examples' => []
];
$libraryUrl = $library->getUrl();
if ($libraryUrl != '') {
$libraries[$libraryMachineName]['url'] = $libraryUrl;
}

$examples = $entityManager->getRepository('CodebenderLibraryBundle:Example')->findBy(array('library' => $library));
if ($library->getOwner() !== null && $library->getRepo() !== null) {
$libraries[$libraryMachineName]['url'] = 'https://github.com/' . $library->getOwner() . '/' . $library->getRepo();
}

$examples = $entityManager->getRepository('CodebenderLibraryBundle:Example')
->findBy(['library' => $library]);

foreach ($examples as $example) {
$names = $this->getExampleAndLibNameFromRelativePath(pathinfo($example->getPath(), PATHINFO_DIRNAME), $example->getName());
/* @var Example $example */
$names = $this->getExampleAndLibNameFromRelativePath(
pathinfo($example->getPath(), PATHINFO_DIRNAME),
$example->getName()
);

$libraries[$libraryMachineName]['examples'][] = array('name' => $names['example_name']);
$libraries[$libraryMachineName]['examples'][] = ['name' => $names['example_name']];
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,26 @@ public function load(ObjectManager $objectManager)
// Persist the new library
$objectManager->persist($binaryLbrary);

$urlTestLibrary = new ExternalLibrary();
$urlTestLibrary->setHumanName('Url Tester');
$urlTestLibrary->setMachineName('UrlTester');
$urlTestLibrary->setActive(true);
$urlTestLibrary->setVerified(false);
$urlTestLibrary->setDescription('A library used for testing that git urls work fine.');
$urlTestLibrary->setOwner('owner');
$urlTestLibrary->setRepo('repository');

$objectManager->persist($urlTestLibrary);

$urlTestLibrary2 = new ExternalLibrary();
$urlTestLibrary2->setHumanName('No Url Library');
$urlTestLibrary2->setMachineName('NoUrl');
$urlTestLibrary2->setActive(true);
$urlTestLibrary2->setVerified(false);
$urlTestLibrary2->setDescription('Another library used for testing that git urls work fine.');

$objectManager->persist($urlTestLibrary2);

/*
* After all fixture objects have been added to the ObjectManager (`persist` operation),
* it's time to flush the contents of the ObjectManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ public function testList()

// Make sure the example was found
$this->assertEquals('AnalogReadSerial', $foundExample[0]['name']);

$urlTesterLibrary = $categories['External Libraries']['UrlTester'];
$this->assertEquals('https://github.com/owner/repository', $urlTesterLibrary['url']);

// disable the library in order to avoid making the rest of the tests fail
$client->request('POST', '/' . $authorizationKey . '/toggleStatus/UrlTester');

$binaryLibrary = $categories['External Libraries']['Binary'];
$this->assertEquals('https://some/url.com', $binaryLibrary['url']);

$noUrlLibrary = $categories['External Libraries']['NoUrl'];
$this->assertArrayNotHasKey('url', $noUrlLibrary);
}


Expand Down