From e6c84f28d45730fe3dc74829b8d0a71b8933f4de Mon Sep 17 00:00:00 2001 From: bradfordcondon Date: Sat, 2 Dec 2017 20:51:37 -0500 Subject: [PATCH 1/3] generator now runs without a db connection and create basic unit test --- tests/GeneratorTest.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tests/GeneratorTest.php diff --git a/tests/GeneratorTest.php b/tests/GeneratorTest.php new file mode 100644 index 0000000..ce4bdd7 --- /dev/null +++ b/tests/GeneratorTest.php @@ -0,0 +1,34 @@ +generator = new StatonLab\FieldGenerator\Generator(); +} + protected function tearDown() + { + $this->generator = NULL; + } + +/** +*Assert that the Generator constructs +* +**/ + public function testAdd() + { + $generator = $this->generator; + + $this->assertInstanceOf("StatonLab\FieldGenerator\Generator", $generator); + + } + +} \ No newline at end of file From 9a5232bebe00a2442df2ae2a95742690db51f0f2 Mon Sep 17 00:00:00 2001 From: bradfordcondon Date: Sat, 2 Dec 2017 21:26:54 -0500 Subject: [PATCH 2/3] allow creation offline --- composer.lock | 767 ++++++++++++++++++++++++++++ s__c_output/g.fields.inc | 125 +++++ s__c_output/s__c/s__c.inc | 128 +++++ s__c_output/s__c/s__c_formatter.inc | 119 +++++ s__c_output/s__c/s__c_widget.inc | 122 +++++ src/DB.php | 33 +- src/Generator.php | 7 + src/bootstrap.php | 1 + 8 files changed, 1298 insertions(+), 4 deletions(-) create mode 100644 composer.lock create mode 100644 s__c_output/g.fields.inc create mode 100644 s__c_output/s__c/s__c.inc create mode 100644 s__c_output/s__c/s__c_formatter.inc create mode 100644 s__c_output/s__c/s__c_widget.inc diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..7b3f34f --- /dev/null +++ b/composer.lock @@ -0,0 +1,767 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "content-hash": "73fcac0cb9c94cf50e9803d61ae38ac7", + "packages": [ + { + "name": "phpunit/php-code-coverage", + "version": "2.2.4", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-code-coverage.git", + "reference": "eabf68b476ac7d0f73793aada060f1c1a9bf8979" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/eabf68b476ac7d0f73793aada060f1c1a9bf8979", + "reference": "eabf68b476ac7d0f73793aada060f1c1a9bf8979", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "phpunit/php-file-iterator": "~1.3", + "phpunit/php-text-template": "~1.2", + "phpunit/php-token-stream": "~1.3", + "sebastian/environment": "^1.3.2", + "sebastian/version": "~1.0" + }, + "require-dev": { + "ext-xdebug": ">=2.1.4", + "phpunit/phpunit": "~4" + }, + "suggest": { + "ext-dom": "*", + "ext-xdebug": ">=2.2.1", + "ext-xmlwriter": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.2.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", + "homepage": "https://github.com/sebastianbergmann/php-code-coverage", + "keywords": [ + "coverage", + "testing", + "xunit" + ], + "time": "2015-10-06T15:47:00+00:00" + }, + { + "name": "phpunit/php-file-iterator", + "version": "1.3.4", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-file-iterator.git", + "reference": "acd690379117b042d1c8af1fafd61bde001bf6bb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/acd690379117b042d1c8af1fafd61bde001bf6bb", + "reference": "acd690379117b042d1c8af1fafd61bde001bf6bb", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "autoload": { + "classmap": [ + "File/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "" + ], + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "FilterIterator implementation that filters files based on a list of suffixes.", + "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", + "keywords": [ + "filesystem", + "iterator" + ], + "time": "2013-10-10T15:34:57+00:00" + }, + { + "name": "phpunit/php-text-template", + "version": "1.2.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-text-template.git", + "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/31f8b717e51d9a2afca6c9f046f5d69fc27c8686", + "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Simple template engine.", + "homepage": "https://github.com/sebastianbergmann/php-text-template/", + "keywords": [ + "template" + ], + "time": "2015-06-21T13:50:34+00:00" + }, + { + "name": "phpunit/php-timer", + "version": "1.0.9", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-timer.git", + "reference": "3dcf38ca72b158baf0bc245e9184d3fdffa9c46f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/3dcf38ca72b158baf0bc245e9184d3fdffa9c46f", + "reference": "3dcf38ca72b158baf0bc245e9184d3fdffa9c46f", + "shasum": "" + }, + "require": { + "php": "^5.3.3 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Utility class for timing", + "homepage": "https://github.com/sebastianbergmann/php-timer/", + "keywords": [ + "timer" + ], + "time": "2017-02-26T11:10:40+00:00" + }, + { + "name": "phpunit/php-token-stream", + "version": "1.4.11", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-token-stream.git", + "reference": "e03f8f67534427a787e21a385a67ec3ca6978ea7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/e03f8f67534427a787e21a385a67ec3ca6978ea7", + "reference": "e03f8f67534427a787e21a385a67ec3ca6978ea7", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Wrapper around PHP's tokenizer extension.", + "homepage": "https://github.com/sebastianbergmann/php-token-stream/", + "keywords": [ + "tokenizer" + ], + "time": "2017-02-27T10:12:30+00:00" + }, + { + "name": "phpunit/phpunit", + "version": "4.1.x-dev", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit.git", + "reference": "43914fa040d3bc85d316fac6ae15409c68bfa105" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/43914fa040d3bc85d316fac6ae15409c68bfa105", + "reference": "43914fa040d3bc85d316fac6ae15409c68bfa105", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-json": "*", + "ext-pcre": "*", + "ext-reflection": "*", + "ext-spl": "*", + "php": ">=5.3.3", + "phpunit/php-code-coverage": "~2.0", + "phpunit/php-file-iterator": "~1.3.1", + "phpunit/php-text-template": "~1.2", + "phpunit/php-timer": "~1.0.2", + "phpunit/phpunit-mock-objects": "2.1.5", + "sebastian/comparator": "~1.0", + "sebastian/diff": "~1.1", + "sebastian/environment": "~1.0", + "sebastian/exporter": "~1.0", + "sebastian/version": "~1.0", + "symfony/yaml": "~2.0" + }, + "suggest": { + "phpunit/php-invoker": "~1.1" + }, + "bin": [ + "phpunit" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.1.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "", + "../../symfony/yaml/" + ], + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "The PHP Unit Testing framework.", + "homepage": "http://www.phpunit.de/", + "keywords": [ + "phpunit", + "testing", + "xunit" + ], + "time": "2015-02-09 06:33:19" + }, + { + "name": "phpunit/phpunit-mock-objects", + "version": "2.1.5", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", + "reference": "7878b9c41edb3afab92b85edf5f0981014a2713a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/7878b9c41edb3afab92b85edf5f0981014a2713a", + "reference": "7878b9c41edb3afab92b85edf5f0981014a2713a", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "phpunit/php-text-template": "~1.2" + }, + "require-dev": { + "phpunit/phpunit": "~4.1" + }, + "suggest": { + "ext-soap": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.1.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "" + ], + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Mock Object library for PHPUnit", + "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/", + "keywords": [ + "mock", + "xunit" + ], + "time": "2014-06-12T07:22:15+00:00" + }, + { + "name": "sebastian/comparator", + "version": "1.2.4", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/comparator.git", + "reference": "2b7424b55f5047b47ac6e5ccb20b2aea4011d9be" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/2b7424b55f5047b47ac6e5ccb20b2aea4011d9be", + "reference": "2b7424b55f5047b47ac6e5ccb20b2aea4011d9be", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "sebastian/diff": "~1.2", + "sebastian/exporter": "~1.2 || ~2.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides the functionality to compare PHP values for equality", + "homepage": "http://www.github.com/sebastianbergmann/comparator", + "keywords": [ + "comparator", + "compare", + "equality" + ], + "time": "2017-01-29T09:50:25+00:00" + }, + { + "name": "sebastian/diff", + "version": "1.4.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/diff.git", + "reference": "7f066a26a962dbe58ddea9f72a4e82874a3975a4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/7f066a26a962dbe58ddea9f72a4e82874a3975a4", + "reference": "7f066a26a962dbe58ddea9f72a4e82874a3975a4", + "shasum": "" + }, + "require": { + "php": "^5.3.3 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Kore Nordmann", + "email": "mail@kore-nordmann.de" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Diff implementation", + "homepage": "https://github.com/sebastianbergmann/diff", + "keywords": [ + "diff" + ], + "time": "2017-05-22T07:24:03+00:00" + }, + { + "name": "sebastian/environment", + "version": "1.3.8", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/environment.git", + "reference": "be2c607e43ce4c89ecd60e75c6a85c126e754aea" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/be2c607e43ce4c89ecd60e75c6a85c126e754aea", + "reference": "be2c607e43ce4c89ecd60e75c6a85c126e754aea", + "shasum": "" + }, + "require": { + "php": "^5.3.3 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.8 || ^5.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides functionality to handle HHVM/PHP environments", + "homepage": "http://www.github.com/sebastianbergmann/environment", + "keywords": [ + "Xdebug", + "environment", + "hhvm" + ], + "time": "2016-08-18T05:49:44+00:00" + }, + { + "name": "sebastian/exporter", + "version": "1.2.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/exporter.git", + "reference": "42c4c2eec485ee3e159ec9884f95b431287edde4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/42c4c2eec485ee3e159ec9884f95b431287edde4", + "reference": "42c4c2eec485ee3e159ec9884f95b431287edde4", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "sebastian/recursion-context": "~1.0" + }, + "require-dev": { + "ext-mbstring": "*", + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides the functionality to export PHP variables for visualization", + "homepage": "http://www.github.com/sebastianbergmann/exporter", + "keywords": [ + "export", + "exporter" + ], + "time": "2016-06-17T09:04:28+00:00" + }, + { + "name": "sebastian/recursion-context", + "version": "1.0.5", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/recursion-context.git", + "reference": "b19cc3298482a335a95f3016d2f8a6950f0fbcd7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/b19cc3298482a335a95f3016d2f8a6950f0fbcd7", + "reference": "b19cc3298482a335a95f3016d2f8a6950f0fbcd7", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides functionality to recursively process PHP variables", + "homepage": "http://www.github.com/sebastianbergmann/recursion-context", + "time": "2016-10-03T07:41:43+00:00" + }, + { + "name": "sebastian/version", + "version": "1.0.6", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/version.git", + "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/58b3a85e7999757d6ad81c787a1fbf5ff6c628c6", + "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6", + "shasum": "" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library that helps with managing the version number of Git-hosted PHP projects", + "homepage": "https://github.com/sebastianbergmann/version", + "time": "2015-06-21T13:59:46+00:00" + }, + { + "name": "symfony/yaml", + "version": "v2.8.31", + "source": { + "type": "git", + "url": "https://github.com/symfony/yaml.git", + "reference": "d819bf267e901727141fe828ae888486fd21236e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/yaml/zipball/d819bf267e901727141fe828ae888486fd21236e", + "reference": "d819bf267e901727141fe828ae888486fd21236e", + "shasum": "" + }, + "require": { + "php": ">=5.3.9" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.8-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Yaml\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Yaml Component", + "homepage": "https://symfony.com", + "time": "2017-11-05T15:25:56+00:00" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": { + "phpunit/phpunit": 20 + }, + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [] +} diff --git a/s__c_output/g.fields.inc b/s__c_output/g.fields.inc new file mode 100644 index 0000000..8aac63b --- /dev/null +++ b/s__c_output/g.fields.inc @@ -0,0 +1,125 @@ +data_table) AND ($bundle->data_table == 'organism')) { + // First add my term. + tripal_insert_cvterm(array( + 'id' => 's:d', + 'name' => 'c', + 'cv_name' => 'd', + 'definition' => 'f', + )); + + // Then describe the field defined by that term. + $field_name = 's__c'; + $field_type = 's__c'; + $fields[$field_name] = array( + 'field_name' => $field_name, + 'type' => $field_type, + 'cardinality' => 1, + 'locked' => FALSE, + 'storage' => array( + 'type' => 'field_chado_storage', + ), + ); + } + + return $fields; +} + +/** + * Implements hook_bundle_instances_info(). + * + * This hook tells Drupal/Tripal to create a field instance of a given field type on a + * specific Tripal Content type (otherwise known as the bundle). Make sure to implement + * hook_bundle_create_fields() to create your field type before trying to create an + * instance of that field. + * + * @param $entity_type + * This should be 'TripalEntity' for all Tripal Content. + * @param $bundle + * This object describes the Type of Tripal Entity (e.g. Organism or Gene) the field + * instances are being created for. Thus this hook is called once per Tripal Content Type on your + * site. The name of the bundle is the machine name of the type (e.g. bio_data_1) and + * the label of the bundle (e.g. Organism) is what you see in the interface. Since the + * label can be changed by site admin, we suggest checking the data_table to determine + * if this is the entity you want to add field instances to. + * @return + * An array of field instance definitions. This is where you can define the defaults + * for any settings you use in your field. Each entry in this array will be used to + * create an instance of an already existing field. + */ +function g_bundle_instances_info($entity_type, $bundle) { + $instances = array(); + + // ORGANISM. + //=============== + if (isset($bundle->data_table) AND ($bundle->data_table == 'organism')) { + $field_name = 's__c'; + $field_type = 's__c'; + $instances[$field_name] = array( + 'field_name' => $field_name, + 'entity_type' => $entity_type, + 'bundle' => $bundle->name, + 'label' => 'd', + 'description' => 'f', + 'required' => FALSE, + 'settings' => array( + 'auto_attach' => FALSE, + 'chado_table' => $bundle->data_table, + 'chado_column' => 'organism_id', + 'base_table' => $bundle->data_table, + ), + 'widget' => array( + 'type' => 's__c_widget', + 'settings' => array(), + ), + 'display' => array( + 'default' => array( + 'label' => 'hidden', + 'type' => 's__c_formatter', + 'settings' => array(), + ), + ), + ); + + } + + return $instances; +} diff --git a/s__c_output/s__c/s__c.inc b/s__c_output/s__c/s__c.inc new file mode 100644 index 0000000..9298c7a --- /dev/null +++ b/s__c_output/s__c/s__c.inc @@ -0,0 +1,128 @@ + 'field_chado_storage', + // It is expected that all fields set a 'value' in the load() function. + // In many cases, the value may be an associative array of key/value pairs. + // In order for Tripal to provide context for all data, the keys should + // be a controlled vocabulary term (e.g. rdfs:type). Keys in the load() + // function that are supported by the query() function should be + // listed here. + 'searchable_keys' => array(), + ); + + // Provide a list of instance specific settings. These can be access within + // the instanceSettingsForm. When the instanceSettingsForm is submitted + // then Drupal with automatically change these settings for the instance. + // It is recommended to put settings at the instance level whenever possible. + // If you override this variable in a child class be sure to replicate the + // term_name, term_vocab, term_accession and term_fixed keys as these are + // required for all TripalFields. + public static $default_instance_settings = array( + // The DATABASE name, as it appears in chado.db. This also builds the link-out url. In most cases this will simply be the CV name. In some cases (EDAM) this will be the SUBONTOLOGY. + 'term_vocabulary' => 's', + // The name of the term. + 'term_name' => 'c', + // The unique ID (i.e. accession) of the term. + 'term_accession' => 'd', + // Set to TRUE if the site admin is not allowed to change the term + // type, otherwise the admin can change the term mapped to a field. + 'term_fixed' => FALSE, + // Indicates if this field should be automatically attached to display + // or web services or if this field should be loaded separately. This + // is convenient for speed. Fields that are slow should for loading + // should have auto_attach set to FALSE so tha their values can be + // attached asynchronously. + 'auto_attach' => FALSE, + // The table in Chado that the instance maps to. + 'chado_table' => 'organism', + // The column of the table in Chado where the value of the field comes from. + 'chado_column' => 'organism_id', + // The base table. + 'base_table' => 'organism', + ); + + // A boolean specifying that users should not be allowed to create + // fields and instances of this field type through the UI. Such + // fields can only be created programmatically with field_create_field() + // and field_create_instance(). + public static $no_ui = FALSE; + + // A boolean specifying that the field will not contain any data. This + // should exclude the field from web services or downloads. An example + // could be a quick search field that appears on the page that redirects + // the user but otherwise provides no data. + public static $no_data = FALSE; + + /** + * Loads the field values from the underlying data store. + * + * @param $entity + * + * @return + * An array of the following format: + * $entity->{$field_name}['und'][0]['value'] = $value; + * where: + * - $entity is the entity object to which this field is attached. + * - $field_name is the name of this field + * - 'und' is the language code (in this case 'und' == undefined) + * - 0 is the cardinality. Increment by 1 when more than one item is + * available. + * - 'value' is the key indicating the value of this field. It should + * always be set. The value of the 'value' key will be the contents + * used for web services and for downloadable content. The value + * should be of the follow format types: 1) A single value (text, + * numeric, etc.) 2) An array of key value pair. 3) If multiple entries + * then cardinality should incremented and format types 1 and 2 should + * be used for each item. + * The array may contain as many other keys at the same level as 'value' + * but those keys are for internal field use and are not considered the + * value of the field. + * + * + */ + public function load($entity) { + + // ChadoFields automatically load the chado column specified in the + // default settings above. If that is all you need then you don't even + // need to implement this function. However, if you need to add any + // additional data to be used in the display, you should add it here. + parent::load($entity); + } +} \ No newline at end of file diff --git a/s__c_output/s__c/s__c_formatter.inc b/s__c_output/s__c/s__c_formatter.inc new file mode 100644 index 0000000..bdcd8d0 --- /dev/null +++ b/s__c_output/s__c/s__c_formatter.inc @@ -0,0 +1,119 @@ + 'default_value', + ); + + /** + * Provides the field's setting form. + * + * This function corresponds to the hook_field_formatter_settings_form() + * function of the Drupal Field API. + * + * The settings form appears on the 'Manage Display' page of the content + * type administration page. This function provides the form that will + * appear on that page. + * + * To add a validate function, please create a static function in the + * implementing class, and indicate that this function should be used + * in the form array that is returned by this function. + * + * This form will not be displayed if the formatter_settings_summary() + * function does not return anything. + * + * param $field + * The field structure being configured. + * param $instance + * The instance structure being configured. + * param $view_mode + * The view mode being configured. + * param $form + * The (entire) configuration form array, which will usually have no use + * here. Typically for reference only. + * param $form_state + * The form state of the (entire) configuration form. + * + * @return + * A Drupal Form array containing the settings form for this field. + */ + public function settingsForm($view_mode, $form, &$form_state) { + + } + + /** + * Provides the display for a field + * + * This function corresponds to the hook_field_formatter_view() + * function of the Drupal Field API. + * + * This function provides the display for a field when it is viewed on + * the web page. The content returned by the formatter should only include + * what is present in the $items[$delta]['values] array. This way, the + * contents that are displayed on the page, via webservices and downloaded + * into a CSV file will always be identical. The view need not show all + * of the data in the 'values' array. + * + * @param $element + * @param $entity_type + * @param $entity + * @param $langcode + * @param $items + * @param $display + * + * @return + * An element array compatible with that returned by the + * hook_field_formatter_view() function. + */ + public function view(&$element, $entity_type, $entity, $langcode, $items, $display) { + + // Get the settings + $settings = $display['settings']; + } + + /** + * Provides a summary of the formatter settings. + * + * This function corresponds to the hook_field_formatter_settings_summary() + * function of the Drupal Field API. + * + * On the 'Manage Display' page of the content type administration page, + * fields are allowed to provide a settings form. This settings form can + * be used to allow the site admin to define how the field should be + * formatted. The settings are then available for the formatter() + * function of this class. This function provides a text-based description + * of the settings for the site developer to see. It appears on the manage + * display page inline with the field. A field must always return a + * value in this function if the settings form gear button is to appear. + * + * See the hook_field_formatter_settings_summary() function for more + * information. + * + * @param $field + * @param $instance + * @param $view_mode + * + * @return string + * A string that provides a very brief summary of the field settings + * to the user. + * + */ + public function settingsSummary($view_mode) { + return ''; + } + +} \ No newline at end of file diff --git a/s__c_output/s__c/s__c_widget.inc b/s__c_output/s__c/s__c_widget.inc new file mode 100644 index 0000000..25a9a4a --- /dev/null +++ b/s__c_output/s__c/s__c_widget.inc @@ -0,0 +1,122 @@ +getSettingsFilePath($drupal_path); - $this->readSettings($settings); - $this->createConnection(); + if ($settings) { + $this->readSettings($settings); + $this->createConnection(); + } } /** @@ -84,11 +93,18 @@ protected function getSettingsFilePath($drupal_root) { $settings = "{$drupal_root}/sites/default/settings.php"; if (!file_exists($settings)) { - throw new Exception("The settings file at $settings does not exist."); + + $this->unconnected = true; + + return null; + // throw new Exception("The settings file at $settings does not exist."); } if (!is_readable($settings)) { - throw new Exception("The settings file at $settings is not readable."); + $this->unconnected = true; + + return null; + // throw new Exception("The settings file at $settings is not readable."); } return $settings; @@ -152,4 +168,13 @@ public function get() { public function count() { return intval($this->get()[0]['count']); } + + +/** +*Inform generator if there is no DB connection +* +*/ +public function checkOffline() { + return $this->unconnected; +} } \ No newline at end of file diff --git a/src/Generator.php b/src/Generator.php index 85324e1..301f9d1 100644 --- a/src/Generator.php +++ b/src/Generator.php @@ -187,6 +187,13 @@ protected function validateTerms() { $this->prompt->info('Performing DB checks to validate entries ...'); $failed = FALSE; + //if no connection, run anyway but let the user know + if ($this->db->checkOffline()) { + $this->prompt->info('No valid DB connection. Continuing without querying terms against the DB.'); + $this->prompt->info("Chosen CV Term ID {$this->db_name}:{$this->field_accession} and CV {$this->cv_name}"); + return; + } + // Validate DB $count = $this->count('chado.db', 'name', $this->db_name); if ($count <= 0) { diff --git a/src/bootstrap.php b/src/bootstrap.php index e14c4e9..3577d3c 100644 --- a/src/bootstrap.php +++ b/src/bootstrap.php @@ -8,3 +8,4 @@ include __DIR__ . '/CLIPrompt.php'; include __DIR__ . '/Colors.php'; include __DIR__ . '/Generator.php'; +include __DIR__ . '/DB.php'; From 0b3fa301909ce0741af809439dd98f83c7bcca48 Mon Sep 17 00:00:00 2001 From: bradfordcondon Date: Sat, 2 Dec 2017 21:27:38 -0500 Subject: [PATCH 3/3] successfully create field with no db connection --- s__c_output/g.fields.inc | 125 --------------------------- s__c_output/s__c/s__c.inc | 128 ---------------------------- s__c_output/s__c/s__c_formatter.inc | 119 -------------------------- s__c_output/s__c/s__c_widget.inc | 122 -------------------------- 4 files changed, 494 deletions(-) delete mode 100644 s__c_output/g.fields.inc delete mode 100644 s__c_output/s__c/s__c.inc delete mode 100644 s__c_output/s__c/s__c_formatter.inc delete mode 100644 s__c_output/s__c/s__c_widget.inc diff --git a/s__c_output/g.fields.inc b/s__c_output/g.fields.inc deleted file mode 100644 index 8aac63b..0000000 --- a/s__c_output/g.fields.inc +++ /dev/null @@ -1,125 +0,0 @@ -data_table) AND ($bundle->data_table == 'organism')) { - // First add my term. - tripal_insert_cvterm(array( - 'id' => 's:d', - 'name' => 'c', - 'cv_name' => 'd', - 'definition' => 'f', - )); - - // Then describe the field defined by that term. - $field_name = 's__c'; - $field_type = 's__c'; - $fields[$field_name] = array( - 'field_name' => $field_name, - 'type' => $field_type, - 'cardinality' => 1, - 'locked' => FALSE, - 'storage' => array( - 'type' => 'field_chado_storage', - ), - ); - } - - return $fields; -} - -/** - * Implements hook_bundle_instances_info(). - * - * This hook tells Drupal/Tripal to create a field instance of a given field type on a - * specific Tripal Content type (otherwise known as the bundle). Make sure to implement - * hook_bundle_create_fields() to create your field type before trying to create an - * instance of that field. - * - * @param $entity_type - * This should be 'TripalEntity' for all Tripal Content. - * @param $bundle - * This object describes the Type of Tripal Entity (e.g. Organism or Gene) the field - * instances are being created for. Thus this hook is called once per Tripal Content Type on your - * site. The name of the bundle is the machine name of the type (e.g. bio_data_1) and - * the label of the bundle (e.g. Organism) is what you see in the interface. Since the - * label can be changed by site admin, we suggest checking the data_table to determine - * if this is the entity you want to add field instances to. - * @return - * An array of field instance definitions. This is where you can define the defaults - * for any settings you use in your field. Each entry in this array will be used to - * create an instance of an already existing field. - */ -function g_bundle_instances_info($entity_type, $bundle) { - $instances = array(); - - // ORGANISM. - //=============== - if (isset($bundle->data_table) AND ($bundle->data_table == 'organism')) { - $field_name = 's__c'; - $field_type = 's__c'; - $instances[$field_name] = array( - 'field_name' => $field_name, - 'entity_type' => $entity_type, - 'bundle' => $bundle->name, - 'label' => 'd', - 'description' => 'f', - 'required' => FALSE, - 'settings' => array( - 'auto_attach' => FALSE, - 'chado_table' => $bundle->data_table, - 'chado_column' => 'organism_id', - 'base_table' => $bundle->data_table, - ), - 'widget' => array( - 'type' => 's__c_widget', - 'settings' => array(), - ), - 'display' => array( - 'default' => array( - 'label' => 'hidden', - 'type' => 's__c_formatter', - 'settings' => array(), - ), - ), - ); - - } - - return $instances; -} diff --git a/s__c_output/s__c/s__c.inc b/s__c_output/s__c/s__c.inc deleted file mode 100644 index 9298c7a..0000000 --- a/s__c_output/s__c/s__c.inc +++ /dev/null @@ -1,128 +0,0 @@ - 'field_chado_storage', - // It is expected that all fields set a 'value' in the load() function. - // In many cases, the value may be an associative array of key/value pairs. - // In order for Tripal to provide context for all data, the keys should - // be a controlled vocabulary term (e.g. rdfs:type). Keys in the load() - // function that are supported by the query() function should be - // listed here. - 'searchable_keys' => array(), - ); - - // Provide a list of instance specific settings. These can be access within - // the instanceSettingsForm. When the instanceSettingsForm is submitted - // then Drupal with automatically change these settings for the instance. - // It is recommended to put settings at the instance level whenever possible. - // If you override this variable in a child class be sure to replicate the - // term_name, term_vocab, term_accession and term_fixed keys as these are - // required for all TripalFields. - public static $default_instance_settings = array( - // The DATABASE name, as it appears in chado.db. This also builds the link-out url. In most cases this will simply be the CV name. In some cases (EDAM) this will be the SUBONTOLOGY. - 'term_vocabulary' => 's', - // The name of the term. - 'term_name' => 'c', - // The unique ID (i.e. accession) of the term. - 'term_accession' => 'd', - // Set to TRUE if the site admin is not allowed to change the term - // type, otherwise the admin can change the term mapped to a field. - 'term_fixed' => FALSE, - // Indicates if this field should be automatically attached to display - // or web services or if this field should be loaded separately. This - // is convenient for speed. Fields that are slow should for loading - // should have auto_attach set to FALSE so tha their values can be - // attached asynchronously. - 'auto_attach' => FALSE, - // The table in Chado that the instance maps to. - 'chado_table' => 'organism', - // The column of the table in Chado where the value of the field comes from. - 'chado_column' => 'organism_id', - // The base table. - 'base_table' => 'organism', - ); - - // A boolean specifying that users should not be allowed to create - // fields and instances of this field type through the UI. Such - // fields can only be created programmatically with field_create_field() - // and field_create_instance(). - public static $no_ui = FALSE; - - // A boolean specifying that the field will not contain any data. This - // should exclude the field from web services or downloads. An example - // could be a quick search field that appears on the page that redirects - // the user but otherwise provides no data. - public static $no_data = FALSE; - - /** - * Loads the field values from the underlying data store. - * - * @param $entity - * - * @return - * An array of the following format: - * $entity->{$field_name}['und'][0]['value'] = $value; - * where: - * - $entity is the entity object to which this field is attached. - * - $field_name is the name of this field - * - 'und' is the language code (in this case 'und' == undefined) - * - 0 is the cardinality. Increment by 1 when more than one item is - * available. - * - 'value' is the key indicating the value of this field. It should - * always be set. The value of the 'value' key will be the contents - * used for web services and for downloadable content. The value - * should be of the follow format types: 1) A single value (text, - * numeric, etc.) 2) An array of key value pair. 3) If multiple entries - * then cardinality should incremented and format types 1 and 2 should - * be used for each item. - * The array may contain as many other keys at the same level as 'value' - * but those keys are for internal field use and are not considered the - * value of the field. - * - * - */ - public function load($entity) { - - // ChadoFields automatically load the chado column specified in the - // default settings above. If that is all you need then you don't even - // need to implement this function. However, if you need to add any - // additional data to be used in the display, you should add it here. - parent::load($entity); - } -} \ No newline at end of file diff --git a/s__c_output/s__c/s__c_formatter.inc b/s__c_output/s__c/s__c_formatter.inc deleted file mode 100644 index bdcd8d0..0000000 --- a/s__c_output/s__c/s__c_formatter.inc +++ /dev/null @@ -1,119 +0,0 @@ - 'default_value', - ); - - /** - * Provides the field's setting form. - * - * This function corresponds to the hook_field_formatter_settings_form() - * function of the Drupal Field API. - * - * The settings form appears on the 'Manage Display' page of the content - * type administration page. This function provides the form that will - * appear on that page. - * - * To add a validate function, please create a static function in the - * implementing class, and indicate that this function should be used - * in the form array that is returned by this function. - * - * This form will not be displayed if the formatter_settings_summary() - * function does not return anything. - * - * param $field - * The field structure being configured. - * param $instance - * The instance structure being configured. - * param $view_mode - * The view mode being configured. - * param $form - * The (entire) configuration form array, which will usually have no use - * here. Typically for reference only. - * param $form_state - * The form state of the (entire) configuration form. - * - * @return - * A Drupal Form array containing the settings form for this field. - */ - public function settingsForm($view_mode, $form, &$form_state) { - - } - - /** - * Provides the display for a field - * - * This function corresponds to the hook_field_formatter_view() - * function of the Drupal Field API. - * - * This function provides the display for a field when it is viewed on - * the web page. The content returned by the formatter should only include - * what is present in the $items[$delta]['values] array. This way, the - * contents that are displayed on the page, via webservices and downloaded - * into a CSV file will always be identical. The view need not show all - * of the data in the 'values' array. - * - * @param $element - * @param $entity_type - * @param $entity - * @param $langcode - * @param $items - * @param $display - * - * @return - * An element array compatible with that returned by the - * hook_field_formatter_view() function. - */ - public function view(&$element, $entity_type, $entity, $langcode, $items, $display) { - - // Get the settings - $settings = $display['settings']; - } - - /** - * Provides a summary of the formatter settings. - * - * This function corresponds to the hook_field_formatter_settings_summary() - * function of the Drupal Field API. - * - * On the 'Manage Display' page of the content type administration page, - * fields are allowed to provide a settings form. This settings form can - * be used to allow the site admin to define how the field should be - * formatted. The settings are then available for the formatter() - * function of this class. This function provides a text-based description - * of the settings for the site developer to see. It appears on the manage - * display page inline with the field. A field must always return a - * value in this function if the settings form gear button is to appear. - * - * See the hook_field_formatter_settings_summary() function for more - * information. - * - * @param $field - * @param $instance - * @param $view_mode - * - * @return string - * A string that provides a very brief summary of the field settings - * to the user. - * - */ - public function settingsSummary($view_mode) { - return ''; - } - -} \ No newline at end of file diff --git a/s__c_output/s__c/s__c_widget.inc b/s__c_output/s__c/s__c_widget.inc deleted file mode 100644 index 25a9a4a..0000000 --- a/s__c_output/s__c/s__c_widget.inc +++ /dev/null @@ -1,122 +0,0 @@ -