Overview

Namespaces

  • cli_db
    • propel
      • map
      • om
  • cli_import
  • LoggedPDO
  • None
  • PHP
  • webservices
    • cart
    • combisearch
    • details
      • annotations
        • feature
    • graphs
      • barplot
      • genome
    • listing
    • queue

Classes

  • AbstractTable
  • Acquisition
  • Analysis
  • Assay
  • Biomaterial
  • Contact
  • Feature
  • Organism
  • Protocol
  • Publication
  • Quantification

Interfaces

  • Table
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php
  2: 
  3: namespace cli_db;
  4: 
  5: require_once SHARED . '/classes/CLI_Command.php';
  6: 
  7: class Publication extends AbstractTable {
  8: 
  9:     /**
 10:      * @inheritDoc
 11:      */
 12:     public static function getKeys() {
 13:         return array(
 14:             'id' => array(
 15:                 'colname' => 'PubId',
 16:                 'actions' => array(
 17:                     'details' => 'required',
 18:                     'delete' => 'required',
 19:                 ),
 20:                 'description' => 'publication id'
 21:             ),
 22:             'title' => array('colname' => 'Title'),
 23:             'volumetitle' => array('colname' => 'Volumetitle'),
 24:             'miniref' => array('colname' => 'Miniref'),
 25:             'bibsonomy_internal_link' => array(
 26:                 'short_name' => '-b',
 27:                 'actions' => array(
 28:                     'link_bibsonomy' => 'required',
 29:                 ),
 30:                 'description' => 'bibsonomy "internal link", you can find this on the publication post page. looks like this: [[publication/<resource>/<username>]]'
 31:             ),
 32:             'bibsonomy_api_key' => array(
 33:                 'short_name' => '-k',
 34:                 'actions' => array(
 35:                     'link_bibsonomy' => 'required',
 36:                 ),
 37:                 'description' => 'you can find your api key at http://www.bibsonomy.org/settings?selTab=1'
 38:             ),
 39:             'bibsonomy_username' => array(
 40:                 'short_name' => '-u',
 41:                 'actions' => array(
 42:                     'link_bibsonomy' => 'required',
 43:                 ),
 44:                 'description' => 'bibsonomy user name'
 45:             ),
 46:             'feature_id' => array(
 47:                 'short_name' => '-f',
 48:                 'actions' => array(
 49:                     'link_bibsonomy' => 'required',
 50:                 ),
 51:                 'description' => 'feature id.'
 52:             ),
 53:             'unlink_feature_id' => array(
 54:                 'short_name' => '-f',
 55:                 'actions' => array(
 56:                     'delete' => 'optional',
 57:                 ),
 58:                 'description' => 'feature id. if you specify this option, the publication will only be unlinked from the given feature. if the given feature was the last feature, the publication will be deleted nonetheless.'
 59:             )
 60:         );
 61:     }
 62: 
 63:     /**
 64:      * @inheritDoc
 65:      */
 66:     public static function CLI_commandDescription() {
 67:         return 'Add or remove publications.';
 68:     }
 69: 
 70:     /**
 71:      * @inheritDoc
 72:      */
 73:     public static function CLI_commandName() {
 74:         return 'publication';
 75:     }
 76: 
 77:     /**
 78:      * @inheritDoc
 79:      */
 80:     public static function CLI_longHelp() {
 81:         
 82:     }
 83: 
 84:     /**
 85:      * @inheritDoc
 86:      */
 87:     public static function getSubCommands() {
 88:         return array('link_bibsonomy', 'delete', 'details', 'list');
 89:     }
 90: 
 91:     /**
 92:      * @inheritDoc
 93:      */
 94:     public static function getPropelClass() {
 95:         return '\\cli_db\\propel\\Pub';
 96:     }
 97: 
 98:     /**
 99:      * reads from given bibsonomy link, using username and api key. returns <b>unsaved</b> \cli_db\propel\Pub instance
100:      * @param String $bibsonomy_link
101:      * @param String $username
102:      * @param String $api_key
103:      * @return \cli_db\propel\Pub unsaved instance
104:      */
105:     public static function getPropelPubFromBibsonomy($bibsonomy_link, $username, $api_key) {
106:         $matches = null;
107:         if (!preg_match('{^\[\[(?<type>.*)/(?<resource>.*)/(?<user>.*)\]\]$}', $bibsonomy_link, $matches)) {
108:             trigger_error('wrong format for option --bibsonomy_internal_link', E_USER_ERROR);
109:         }
110: 
111:         $url = sprintf('http://www.bibsonomy.org/api/posts?resource=%s&resourcetype=bibtex', $matches['resource']);
112: 
113:         $curl = curl_init();
114:         curl_setopt($curl, CURLOPT_URL, $url);
115:         curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
116:         curl_setopt($curl, CURLOPT_USERPWD, sprintf('%s:%s', $username, $api_key));
117:         curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
118: 
119:         $xmlStr = curl_exec($curl);
120:         curl_close($curl);
121: 
122: 
123:         //<editor-fold defaultstate="collapsed" desc="bibtexType xsd, see http://www.bibsonomy.org/help/doc/xmlschema.html">
124:         /**
125:          * lines marked with * get stored to DB
126:           <xsd:complexType name="BibtexType">
127:          * <xsd:attribute name="title" type="xsd:string" use="required"/>
128:           <xsd:attribute name="bibtexKey" type="xsd:string" use="required"/>
129:           <xsd:attribute name="bKey" type="xsd:string"/>
130:           <xsd:attribute name="misc" type="xsd:string"/>
131:           <xsd:attribute name="bibtexAbstract" type="xsd:string"/>
132:          * <xsd:attribute name="entrytype" type="xsd:string" use="required"/>
133:           <xsd:attribute name="address" type="xsd:string"/>
134:           <xsd:attribute name="annote" type="xsd:string"/>
135:          * <xsd:attribute name="author" type="xsd:string"/>
136:           <xsd:attribute name="booktitle" type="xsd:string"/>
137:           <xsd:attribute name="chapter" type="xsd:string"/>
138:           <xsd:attribute name="crossref" type="xsd:string"/>
139:           <xsd:attribute name="edition" type="xsd:string"/>
140:           <xsd:attribute name="editor" type="xsd:string"/>
141:           <xsd:attribute name="howpublished" type="xsd:string"/>
142:           <xsd:attribute name="institution" type="xsd:string"/>
143:           <xsd:attribute name="organization" type="xsd:string"/>
144:          * <xsd:attribute name="journal" type="xsd:string"/>
145:           <xsd:attribute name="note" type="xsd:string"/>
146:          * <xsd:attribute name="number" type="xsd:string"/>
147:          * <xsd:attribute name="pages" type="xsd:string"/>
148:          * <xsd:attribute name="publisher" type="xsd:string"/>
149:           <xsd:attribute name="school" type="xsd:string"/>
150:          * <xsd:attribute name="series" type="xsd:string"/>
151:          * <xsd:attribute name="volume" type="xsd:string"/>
152:           <xsd:attribute name="day" type="xsd:string"/>
153:           <xsd:attribute name="month" type="xsd:string"/>
154:          * <xsd:attribute name="year" type="xsd:string" use="required"/>
155:           <xsd:attribute name="type" type="xsd:string"/>
156:           <!-- <xsd:attribute name="scraperId" type="xsd:positiveInteger"/>  -->
157:           <xsd:attribute name="url" type="xsd:string"/>
158:           <xsd:attribute name="privnote" type="xsd:string"/>
159: 
160:           <!-- hash value identifying this resource -->
161:           <xsd:attribute name="intrahash" type="xsd:string"/>
162:           <xsd:attribute name="interhash" type="xsd:string"/>
163:           <!-- link to all posts of this bibtex -->
164:           <xsd:attribute name="href" type="xsd:anyURI"/>
165:           </xsd:complexType>
166:          */
167:         //</editor-fold>
168: 
169:         $bibsonomy = new \SimpleXMLElement($xmlStr);
170:         if ($bibsonomy['stat'] == 'fail') {
171:             trigger_error($bibsonomy->error, E_USER_ERROR);
172:         }
173: 
174: 
175:         if (count($bibsonomy->posts->post) != 1) {
176:             trigger_error(sprintf('Bibsonomy post %s not found!', $bibsonomy_link), E_USER_ERROR);
177:         }
178:         $bibtex = $bibsonomy->posts->post->bibtex;
179: 
180:         $uniquename = sprintf('bibsonomy_%s', $matches['resource']);
181: 
182:         $pubq = new propel\PubQuery();
183:         $pub = $pubq->findOneByUniquename($uniquename);
184:         if ($pub == null) {
185:             $pub = new propel\Pub();
186:             $pub->setTitle($bibtex['title']);
187:             $pub->setUniquename($uniquename);
188:             $pub->setVolumeTitle($bibtex['journal']);
189:             $pub->setVolume($bibtex['volume']);
190:             $pub->setSeriesName($bibtex['series']);
191:             $pub->setIssue($bibtex['number']);
192:             $pub->setPyear($bibtex['year']);
193:             $pub->setPages($bibtex['pages']);
194:             $pub->setMiniref(sprintf('http://www.bibsonomy.org/bibtex/%s/%s', $bibtex['intrahash'], $matches['user']));
195:             $pub->setPublisher($bibtex['publisher']);
196:             $typequery = new propel\CvtermQuery();
197:             $type = $typequery->findOneByName($bibtex['entrytype']);
198:             if ($type != null) {
199:                 $pub->setTypeId($type->getPrimaryKey());
200:             } else {
201:                 trigger_error(sprintf('type %s not found in cvterm, proceeding without type', $bibtex['entrytype']), E_USER_WARNING);
202:             }
203: 
204:             $authors = explode(' and ', $bibtex['author']);
205:             $i = 0;
206:             foreach ($authors as $author) {
207:                 $authnames = explode(',', $author, 2);
208:                 $surname = $authnames[0];
209:                 $givennames = isset($authnames[1]) ? $authnames[1] : '';
210: 
211:                 $pubauthor = new propel\Pubauthor();
212:                 $pubauthor->setGivennames($givennames);
213:                 $pubauthor->setSurname($surname);
214:                 $pubauthor->setRank($i++);
215: 
216:                 $pub->addPubauthor($pubauthor);
217:             }
218:         }
219:         return $pub;
220:     }
221: 
222:     /**
223:      * links a publication against this feature
224:      * @param Array $options user-specified command line parameters
225:      * @param Array $keys result from self::getKeys()
226:      */
227:     public static function command_link_bibsonomy($options, $keys) {
228:         $pub = self::getPropelPubFromBibsonomy($options['bibsonomy_internal_link'], $options['bibsonomy_username'], $options['bibsonomy_api_key']);
229: 
230:         $fq = new propel\FeatureQuery();
231:         $feature = $fq->findOneByFeatureId($options['feature_id']);
232: 
233:         $feature_pub = new propel\FeaturePub();
234:         $feature_pub->setFeature($feature);
235: 
236:         $pub->addFeaturePub($feature_pub);
237: 
238:         $pub->save();
239: 
240:         printf("successfully added Pub '%s' to Feature '%s'\n", $pub->getTitle(), $feature->getUniquename());
241:     }
242: 
243:     /**
244:      * removes given publication from this feature
245:      * @param Array $options user-specified command line parameters
246:      * @param Array $keys result from self::getKeys()
247:      * @return nothing
248:      */
249:     protected static function command_delete($options, $keys) {
250:         $pubq = new propel\PubQuery();
251:         $pub = $pubq->findOneByPubId($options['id']);
252:         if ($pub == null) {
253:             trigger_error(sprintf("No Publication found for ID %d. Exiting.\n", $options['id']), E_USER_ERROR);
254:         }
255:         $featurepubs = $pub->getFeaturePubs();
256:         if (isset($options['unlink_feature_id']) && count($featurepubs) > 1) {
257:             foreach ($featurepubs as $featurepub) {
258:                 if ($featurepub->getFeatureId() == $options['unlink_feature_id'])
259:                     break;
260:             }
261:             if ($featurepub->getFeatureId() != $options['unlink_feature_id']) {
262:                 trigger_error(printf("No Link from Publication %d to Feature %d found. Exiting.\n", $options['id'], $options['unlink_feature_id']), E_USER_ERROR);
263:             }
264:             if (!self::command_delete_confirm($options, sprintf("Delete Link from Publication %d  to Feature %d.\n", $options['id'], $options['unlink_feature_id']))) {
265:                 return;
266:             }
267:             $featurepub->delete();
268:             printf("Row successfully deleted.\n");
269:             return;
270:         }
271:         if (!self::command_delete_confirm($options, sprintf("This Publication is linked to %d Features.\n", count($featurepubs)))) {
272:             return;
273:         }
274:         $pub->delete();
275:         printf("Row successfully deleted.\n");
276:     }
277: 
278: }
279: 
280: ?>
281: 
tbro API documentation generated by ApiGen 2.8.0