1: <?php
2:
3: namespace cli_db;
4:
5: require_once ROOT . 'classes/AbstractTable.php';
6:
7: class Feature extends AbstractTable {
8:
9: 10: 11:
12: public static function getKeys() {
13: return array(
14: 'id' => array(
15: 'colname' => 'FeatureId',
16: 'actions' => array(
17: 'details' => 'required',
18: 'add_synonym' => 'required',
19: 'remove_synonym' => 'required',
20: ),
21: 'description' => 'feature id',
22: 'short_name' => '-f'
23: ),
24: 'name' => array(
25: 'colname' => 'Name',
26: 'actions' => array(
27: 'list' => 'required',
28: ),
29: 'description' => 'search filter, may contain wildcards, e.g. "*comp21449*"'
30: ),
31: 'synonym' => array(
32: 'actions' => array(
33: 'add_synonym' => 'required',
34: 'remove_synonym' => 'required',
35: ),
36: 'description' => 'synonym to be created'
37: ),
38: 'bibsonomy_internal_link' => array(
39: 'short_name' => '-b',
40: 'actions' => array(
41: 'add_synonym' => 'required',
42: ),
43: 'description' => 'bibsonomy "internal link", you can find this on the publication post page. looks like this: [[publication/<resource>/<username>]]'
44: ),
45: 'bibsonomy_api_key' => array(
46: 'short_name' => '-k',
47: 'actions' => array(
48: 'add_synonym' => 'required',
49: ),
50: 'description' => 'you can find your api key at http://www.bibsonomy.org/settings?selTab=1'
51: ),
52: 'bibsonomy_username' => array(
53: 'short_name' => '-u',
54: 'actions' => array(
55: 'add_synonym' => 'required',
56: ),
57: 'description' => 'bibsonomy user name'
58: ),
59: 'type' => array(
60: 'actions' => array(
61: 'add_synonym' => 'required',
62: 'remove_synonym' => 'required',
63: ),
64: 'description' => "'symbol' or 'fullname'. defaults to 'symbol'",
65: 'choices' => array('symbol', 'fullname'),
66: 'default' => 'symbol',
67: 'short_name' => '-t'
68: ),
69: );
70: }
71:
72: 73: 74:
75: public static function CLI_commandDescription() {
76: return 'Manipulate Features.';
77: }
78:
79: 80: 81:
82: public static function CLI_commandName() {
83: return 'feature';
84: }
85:
86: 87: 88:
89: public static function CLI_longHelp() {
90:
91: }
92:
93: 94: 95:
96: public static function getSubCommands() {
97: return array('details', 'list', 'add_synonym', 'remove_synonym');
98: }
99:
100: 101: 102:
103: public static function getPropelClass() {
104: return '\\cli_db\\propel\\Feature';
105: }
106:
107: 108: 109: 110:
111: protected static function command_list($options, $keys) {
112:
113: $featureq = new propel\FeatureQuery();
114:
115: $featureq->filterByName($options['name']);
116:
117: $table_keys = array_keys(array_filter($keys, function($val) {
118: return isset($val['colname']);
119: }));
120: $results = self::prepareQueryResult($featureq->find());
121: self::printTable($table_keys, $results);
122: }
123:
124: 125: 126: 127: 128:
129: protected static function command_add_synonym($options, $keys) {
130: $featureq = new propel\FeatureQuery();
131: $feature = $featureq->findOneByFeatureId($options['id']);
132:
133: if ($feature == null)
134: trigger_error(sprintf('No Feature found for id %d', $options['id']), E_USER_ERROR);
135:
136: $pub = Publication::getPropelPubFromBibsonomy($options['bibsonomy_internal_link'], $options['bibsonomy_username'], $options['bibsonomy_api_key']);
137:
138: $typeq = new propel\CvtermQuery();
139: $type = $typeq->findOneByName($options['type']);
140:
141: $synonymq = new propel\SynonymQuery();
142: $synonymq->filterByTypeId($type->getCvtermId());
143: $synonymq->filterByName($options['synonym']);
144:
145: $synonym = $synonymq->findOne();
146: if ($synonym == null) {
147: $synonym = new propel\Synonym();
148: $synonym->setName($options['synonym']);
149: $synonym->setTypeId($type->getCvtermId());
150: $synonym->setSynonymSgml('');
151: }
152:
153:
154: $feature_synonyms = $synonym->getFeatureSynonymsJoinFeature();
155: foreach ($feature_synonyms as $feature_synonym) {
156: if ($feature_synonym->getFeature()->getReleaseName() == $feature->getReleaseName()) {
157: trigger_error('This release already contains a feature with this synonym.'
158: . ' You can\'t add the same synonym twice to an assembly release.', E_USER_ERROR);
159: }
160: }
161: if ($options['type'] == 'symbol') {
162: $feature_synonyms2 = propel\FeatureSynonymQuery::create()->findByFeatureId($options['id']);
163: foreach ($feature_synonyms2 as $feature_synonym) {
164: if ($feature_synonym->getSynonym()->getTypeId() == $type->getCvtermId()) {
165: trigger_error('This feature is already annotated a symbol.'
166: . 'While you can as many fullname synonyms as you wish, each feature can only have one symbol!', E_USER_ERROR);
167: }
168: }
169: }
170:
171: $feature_synonym = new propel\FeatureSynonym();
172:
173: $feature_synonym->setFeatureId($options['id']);
174: $feature_synonym->setSynonym($synonym);
175:
176: $feature_synonym->setPub($pub);
177:
178: $feature_synonym->save();
179: print "Synonym created successfully.\n";
180: }
181:
182: 183: 184: 185: 186:
187: protected static function command_remove_synonym($options, $keys) {
188: $typeq = new propel\CvtermQuery();
189: $type = $typeq->findOneByName($options['type']);
190:
191: $synonymq = new propel\SynonymQuery();
192: $synonymq->filterByTypeId($type->getCvtermId());
193: $synonymq->filterByName($options['synonym']);
194:
195: $synonym = $synonymq->findOne();
196: if ($synonym == null) {
197: trigger_error('Synonym not found.', E_USER_ERROR);
198: }
199:
200:
201: $feature_synonyms = $synonym->getFeatureSynonyms();
202: foreach ($feature_synonyms as $feature_synonym) {
203: if ($feature_synonym->getFeatureId() == $options['id']) {
204: if (count($feature_synonyms == 1))
205: $synonym->delete();
206: else
207: $feature_synonym->delete();
208: print 'Deleted successfully.';
209: }
210: }
211:
212: trigger_error('Combination of synonym and feature not found!.', E_USER_ERROR);
213: }
214:
215: }
216:
217: ?>
218: