12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691 |
- <?php
- function tripal_library_help($path, $arg) {
- $output = '';
- switch ($path) {
- case "admin/help#tripal_library":
- $output = '<p>'.
- t("Displays links to nodes created on this date").
- '</p>';
- break;
- }
- return $output;
- }
- function tripal_library_node_info() {
- $nodes = array();
- $nodes['chado_library'] = array(
- 'name' => t('Library'),
- 'module' => 'chado_library',
- 'description' => t('A library from the chado database'),
- 'has_title' => FALSE,
- 'title_label' => t('Library'),
- 'has_body' => FALSE,
- 'body_label' => t('Library Description'),
- 'locked' => TRUE
- );
- return $nodes;
- }
- function tripal_library_perm(){
- return array(
- 'access chado_library content',
- 'create chado_library content',
- 'delete chado_library content',
- 'edit chado_library content',
- );
- }
- function chado_library_access($op, $node, $account) {
- if ($op == 'create') {
- return user_access('create chado_library content', $account);
- }
- if ($op == 'update') {
- if (user_access('edit chado_library content', $account)) {
- return TRUE;
- }
- }
- if ($op == 'delete') {
- if (user_access('delete chado_library content', $account)) {
- return TRUE;
- }
- }
- if ($op == 'view') {
- if (user_access('access chado_library content', $account)) {
- return TRUE;
- }
- }
- return FALSE;
- }
- function tripal_library_menu() {
- $items = array();
-
- $items['admin/tripal/tripal_library'] = array(
- 'title' => 'Libraries',
- 'description' => 'Basic Description of Tripal Library Module Functionality',
- 'page callback' => 'tripal_library_module_description_page',
- 'access arguments' => array('access administration pages'),
- 'type' => MENU_NORMAL_ITEM,
- );
-
- $items['admin/tripal/tripal_library/configuration'] = array(
- 'title' => 'Configuration',
- 'description' => 'Manage integration of Chado libraries including associated features.',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_library_admin'),
- 'access arguments' => array('access administration pages'),
- 'type' => MENU_NORMAL_ITEM,
- );
-
-
- $items['chado_sync_libraries'] = array(
- 'title' => t('Sync Data'),
- 'page callback' => 'tripal_library_sync_libraries',
- 'access arguments' => array('access administration pages'),
- 'type' => MENU_CALLBACK
- );
-
- $items['libraries'] = array(
- 'menu_name' => ('primary-links'),
- 'title' => t('DNA Libraries'),
- 'page callback' => 'tripal_library_show_libraries',
- 'access arguments' => array('access chado_library content'),
- 'type' => MENU_NORMAL_ITEM
- );
- $items['node/%/libraries'] = array(
- 'title' => t('Libraries'),
- 'page callback' => 'get_tripal_library_organism_libraries',
- 'page arguments' => array(1),
- 'access callback' => 'tripal_library_node_has_menu',
- 'access arguments' => array('access chado_library content',1),
- 'type' => MENU_LOCAL_TASK | MENU_NORMAL_ITEM
- );
- return $items;
- }
-
- function tripal_library_views_api() {
- return array(
- 'api' => 2.0,
- );
- }
- function tripal_library_node_has_menu($type,$vid){
-
- $sql = 'SELECT organism_id FROM {chado_organism} WHERE vid = %d';
- $result = db_query($sql, $vid);
-
- $box_status =variable_get("tripal_library-box-libraries","menu_off");
-
-
- if($org_id = db_fetch_object($result)){
- if(strcmp($box_status,"menu_on")==0){
- return user_access($type);
- }
- } else {
- return FALSE;
- }
- }
- function tripal_library_module_description_page() {
- $text = '';
-
- $text .= '<h3>Description:</h3>';
- $text .= '<p>TODO: Basic Description of this module including mention/link to the chado module</p>';
- $text .= '<h3>Post Installation Instructions:</h3>';
- $text .= '<p>TODO: Describe any post installation intructions here. You shouldalways include setting user permissions.</p>';
-
-
- $text .= '<h3>Features of this Module:</h3>';
- $text .= '<p>TODO: Discuss the Features of this module including links. Some features to consider are creating content, details pages/node content, editing/deleteing, basic listings and vies integration. See admin/tripal/tripal_stock for an example.</p>';
-
- return $text;
- }
- function tripal_library_admin () {
- $form = array();
-
-
-
- $active_jobs = FALSE;
- if(tripal_get_module_active_jobs('tripal_library')){
- $active_jobs = TRUE;
- }
-
- if(!$active_jobs){
- get_tripal_library_admin_form_sync_set ($form);
- get_tripal_library_admin_form_reindex_set($form);
- get_tripal_library_admin_form_taxonomy_set($form);
- get_tripal_library_admin_form_cleanup_set($form);
- get_tripal_library_admin_form_menu_set($form);
- } else {
- $form['notice'] = array(
- '#type' => 'fieldset',
- '#title' => t('Library Management Temporarily Unavailable')
- );
- $form['notice']['message'] = array(
- '#value' => t('Currently, library management jobs are waiting or are running. . Managemment features have been hidden until these jobs complete. Please check back later once these jobs have finished. You can view the status of pending jobs in the Tripal jobs page.'),
- );
- }
- return system_settings_form($form);
- }
- function tripal_library_nodeapi(&$node, $op, $teaser, $page) {
- switch ($op) {
-
-
- case 'view':
-
- $types_to_show = array('chado_organism', 'chado_feature');
-
- if (!in_array($node->type, $types_to_show, TRUE)) {
- break;
- }
-
- if (!$teaser) {
-
- if($node->build_mode == NODE_BUILD_SEARCH_INDEX){
- $node->content['tripal_library_index_version'] = array(
- '#value' => theme('tripal_library_search_index',$node),
- '#weight' => 4,
- );
- } else if ($node->build_mode == NODE_BUILD_SEARCH_RESULT) {
- $node->content['tripal_library_index_version'] = array(
- '#value' => theme('tripal_library_search_result',$node),
- '#weight' => 4,
- );
- } else {
-
- $node->content['tripal_library_node_addition'] = array(
- '#value' => theme('tripal_library_node_libraries', $node),
- '#weight' => 4
- );
- }
- }
- }
- }
- function tripal_library_theme () {
- return array(
- 'tripal_library_library_table' => array (
- 'arguments' => array('libraries'),
- ),
- 'tripal_library_search_index' => array (
- 'arguments' => array('node'),
- ),
- 'tripal_library_search_result' => array (
- 'arguments' => array('node'),
- ),
- 'tripal_library_node_libraries' => array (
- 'arguments' => array('node'),
- )
- );
- }
- function theme_tripal_library_search_result ($node) {
- if ($node->type == 'chado_organism') {
- $content = "";
-
- $previous_db = tripal_db_set_active('chado');
- $sql = "SELECT * FROM {library} L ".
- "WHERE L.Organism_id = $node->organism_id";
- $libraries = array();
- $results = db_query($sql);
- while($library = db_fetch_object($results)){
-
- $sql = "SELECT * FROM {libraryprop} LP ".
- " INNER JOIN CVTerm CVT ON CVT.cvterm_id = LP.type_id ".
- "WHERE LP.library_id = $library->library_id ".
- " AND CVT.name = 'library_description'";
- $desc = db_fetch_object(db_query($sql));
- $library->description = $desc->value;
- $libraries[] = $library;
- }
- tripal_db_set_active($previous_db);
- if(count($libraries) > 0){
- foreach ($libraries as $library){
- $content .= "Library: $library->name. ";
- $content .= "$library->description";
- };
- }
-
- } else if ($node->type == 'chado_feature') {
- $content = "";
- $organism_id = $node->feature->organism_id;
- $previous_db = tripal_db_set_active('chado');
- $sql = "SELECT * FROM {library} L ".
- " INNER JOIN Library_feature LF ON L.library_id = LF.library_id ".
- "WHERE LF.feature_id = " . $node->feature->feature_id;
- $libraries = array();
- $results = db_query($sql);
- while($library = db_fetch_object($results)){
- $libraries[] = $library;
- }
- tripal_db_set_active($previous_db);
- if(count($libraries) > 0){
- $lib_additions = array();
- foreach ($libraries as $library){
- $content .= "Library: ".$library->name;
- };
- }
- }
- return $content;
- }
- function theme_tripal_library_search_index ($node) {
- if ($node->type == 'chado_organism') {
- $content = "";
-
- $previous_db = tripal_db_set_active('chado');
- $sql = "SELECT * FROM {library} L ".
- "WHERE L.Organism_id = $node->organism_id";
- $libraries = array();
- $results = db_query($sql);
- while($library = db_fetch_object($results)){
-
- $sql = "SELECT * FROM {libraryprop} LP ".
- " INNER JOIN CVTerm CVT ON CVT.cvterm_id = LP.type_id ".
- "WHERE LP.library_id = $library->library_id ".
- " AND CVT.name = 'library_description'";
- $desc = db_fetch_object(db_query($sql));
- $library->description = $desc->value;
- $libraries[] = $library;
- }
- tripal_db_set_active($previous_db);
- if(count($libraries) > 0){
- foreach ($libraries as $library){
- $content .= "$library->name ";
- $content .= "$library->description";
- };
- }
-
- } else if ($node->type == 'chado_feature') {
- $content = "";
- $organism_id = $node->feature->organism_id;
- $previous_db = tripal_db_set_active('chado');
- $sql = "SELECT * FROM {library} L ".
- " INNER JOIN Library_feature LF ON L.library_id = LF.library_id ".
- "WHERE LF.feature_id = " . $node->feature->feature_id;
- $libraries = array();
- $results = db_query($sql);
- while($library = db_fetch_object($results)){
- $libraries[] = $library;
- }
- tripal_db_set_active($previous_db);
- if(count($libraries) > 0){
- $lib_additions = array();
- foreach ($libraries as $library){
- $content .= $library->name;
- };
- }
- }
- return $content;
- }
- function theme_tripal_library_node_libraries($node) {
- $content = "";
-
-
-
-
- if ($node->type == 'chado_organism' && $node->organism_id) {
- $box_status = variable_get("tripal_library-box-libraries","menu_off");
-
- if(strcmp($box_status,"menu_off")==0){
- return get_tripal_library_organism_libraries($node->nid);
- }
- }
-
-
-
- else if ($node->type == 'chado_feature' && $node->feature->feature_id) {
- $organism_id = $node->feature->organism_id;
- $previous_db = tripal_db_set_active('chado');
- $sql = "SELECT * FROM {library} L ".
- " INNER JOIN Library_feature LF ON L.library_id = LF.library_id ".
- "WHERE LF.feature_id = " . $node->feature->feature_id;
- $libraries = array();
- $results = db_query($sql);
- while($library = db_fetch_object($results)){
- $libraries[] = $library;
- }
- tripal_db_set_active($previous_db);
- if(count($libraries) > 0){
- $lib_additions = array();
- foreach ($libraries as $library){
- $sql = "SELECT nid FROM {chado_library} WHERE library_id = %d";
- $lib_nid = db_result(db_query($sql, $library->library_id));
- if ($lib_nid) {
- $lib_url = url("node/$lib_nid");
- }
- $lib_additions[$lib_url] = $library->name;
- };
- $node->lib_additions = $lib_additions;
- }
- }
- return $content;
- }
- function get_tripal_library_organism_libraries($nid) {
- $content = "";
-
-
- $box_status =variable_get("tripal_library-box-libraries","menu_off");
-
- $sql = "SELECT organism_id FROM {chado_organism} WHERE nid = %d";
- $organism_id = db_result(db_query($sql, $nid));
-
- $previous_db = tripal_db_set_active('chado');
- $sql = "SELECT L.library_id, L.organism_id, L.name, L.uniquename, ".
- " L.type_id, CVT.name as cvname, CVT.definition ".
- "FROM {library} L ".
- " INNER JOIN CVTerm CVT ON CVT.cvterm_id = L.type_id ".
- "WHERE L.Organism_id = $organism_id";
- $libraries = array();
- $results = db_query($sql);
- while($library = db_fetch_object($results)){
-
- $sql = "SELECT * FROM {libraryprop} LP ".
- " INNER JOIN CVTerm CVT ON CVT.cvterm_id = LP.type_id ".
- "WHERE LP.library_id = $library->library_id ".
- " AND CVT.name = 'library_description'";
- $desc = db_fetch_object(db_query($sql));
- $library->description = $desc->value;
- $libraries[] = $library;
- }
- tripal_db_set_active($previous_db);
-
- if(strcmp($box_status,"menu_off")==0){
- $content .= "<div id=\"tripal_library_box\" class=\"tripal_library-info-box\">";
- $content .= "<br><div class=\"tripal_expandableBox\">".
- "<h3>Libraries associated with this organism</h3>".
- "</div>";
- $content .= "<div class=\"tripal_expandableBoxContent\">";
- } else {
- $content .= "<h3>Libraries associated with this organism</h3>";
- }
- $content .= "<table class=\"organism-libraries\">";
- if (count($libraries) > 0) {
- $content .= " <tr>";
- $content .= " <th class=\"dbfieldname\">Name</th>";
- $content .= " <th class=\"dbfieldname\">Description</th>";
- $content .= " <th class=\"dbfieldname\">Type</th>";
- $content .= " </tr>";
- foreach ($libraries as $library){
- $content .= "<tr>";
- $sql = "SELECT nid FROM {chado_library} WHERE library_id = %d";
- $lib_nid = db_result(db_query($sql, $library->library_id));
- $lib_url = url("node/$lib_nid");
- if ($lib_nid) {
- $content .= " <td><a href=\"$lib_url\">$library->name</a></td>";
- } else {
- $content .= " <td>$library->name</td>";
- }
- $content .= " <td>$library->description</td>";
- if ($library->cvname == 'cdna_library') {
- $display_lib = 'cDNA';
- } else if ($library->cvname == 'bac_library') {
- $display_lib = 'BAC';
- } else {
- $display_lib = $library->cvname;
- }
- $content .= " <td>$display_lib</td>";
- $content .= "</tr>";
- }
- } else {
- $content .= '<tr><td>There are no libraries available for this organism</td></tr>';
- }
- $content .= "</table>";
- if(user_access('access administrative pages')){
- $link = url("tripal_toggle_box_menu/tripal_library/libraries/$nid");
- if(strcmp($box_status,"menu_off")==0){
- $content .= "<br><a href=\"$link\">Show on menu</a>";
- } else {
- $content .= "<br><a href=\"$link\">Remove from menu</a>";
- }
- }
- if(strcmp($box_status,"menu_off")==0){
- $content .= "</div></div>";
- }
- return $content;
- }
- function get_tripal_library_admin_form_menu_set(&$form){
- $form['menu'] = array(
- '#type' => 'fieldset',
- '#title' => t('Set Menu')
- );
-
- $types = array(
- 'tripal_organism' => t('Organism Page'),
- 'tripal_feature' => t('Feature Page'),
- );
- $defaults = variable_get('tripal_lib_menu_node_types','');
- $form['menu']['tripal_lib_menu_node_types'] = array(
- '#title' => 'Page Types',
- '#type' => 'checkboxes',
- '#description' => t("Libraries can be associated with other data types ".
- "such as organisms, features, analyses, etc. The library module ".
- "will add to the respective pages a box or menu item with a ".
- "list of libraries associated with the data type. This list ".
- "will appear in a box on the page by default. To place this ".
- "list as a menu item rather than a box, check the appropriate boxes ".
- "above"),
- '#options' => $types,
- '#default_value' => $defaults,
- '#weight' => 1,
- );
- }
- function get_tripal_library_admin_form_cleanup_set(&$form) {
- $form['cleanup'] = array(
- '#type' => 'fieldset',
- '#title' => t('Clean Up')
- );
- $form['cleanup']['description'] = array(
- '#type' => 'item',
- '#value' => t("With Drupal and chado residing in different databases ".
- "it is possible that nodes in Drupal and libraries in Chado become ".
- "\"orphaned\". This can occur if an library node in Drupal is ".
- "deleted but the corresponding chado library is not and/or vice ".
- "versa. Click the button below to resolve these discrepancies."),
- '#weight' => 1,
- );
- $form['cleanup']['button'] = array(
- '#type' => 'submit',
- '#value' => t('Clean up orphaned libraries'),
- '#weight' => 2,
- );
- }
- function get_tripal_library_admin_form_taxonomy_set(&$form) {
- $form['taxonify'] = array(
- '#type' => 'fieldset',
- '#title' => t('Assign Drupal Taxonomy to Library Features')
- );
-
- $sql = "SELECT * FROM {Library} ORDER BY uniquename";
- $previous_db = tripal_db_set_active('chado');
- $lib_rset = db_query($sql);
- tripal_db_set_active($previous_db);
-
- $lib_boxes = array();
- while($library = db_fetch_object($lib_rset)){
- $lib_boxes[$library->library_id] = "$library->name";
- }
- $form['taxonify']['description'] = array(
- '#type' => 'item',
- '#value' => t("Drupal allows for assignment of \"taxonomy\" or catagorical terms to " .
- "nodes. These terms allow for advanced filtering during searching. This option allows ".
- "for setting taxonomy only for features that belong to the selected libraries below. All other features will be unaffected. To set taxonomy for all features in the site see the Feature Administration page."),
- '#weight' => 1,
- );
- $form['taxonify']['tx-libraries'] = array (
- '#title' => t('Libraries'),
- '#type' => t('checkboxes'),
- '#description' => t("Check the libraries whose features you want to reset taxonomy. Note: this list contains all libraries, even those that may not be synced."),
- '#required' => FALSE,
- '#prefix' => '<div id="lib_boxes">',
- '#suffix' => '</div>',
- '#options' => $lib_boxes,
- '#weight' => 2
- );
- $form['taxonify']['tx-button'] = array(
- '#type' => 'submit',
- '#value' => t('Set Feature Taxonomy'),
- '#weight' => 3
- );
- }
- function get_tripal_library_admin_form_reindex_set(&$form) {
-
- $form['reindex'] = array(
- '#type' => 'fieldset',
- '#title' => t('Reindex Library Features')
- );
-
- $sql = "SELECT * FROM {Library} ORDER BY uniquename";
- $previous_db = tripal_db_set_active('chado');
- $lib_rset = db_query($sql);
- tripal_db_set_active($previous_db);
-
- $lib_boxes = array();
- while($library = db_fetch_object($lib_rset)){
- $lib_boxes[$library->library_id] = "$library->name";
- }
- $form['reindex']['description'] = array(
- '#type' => 'item',
- '#value' => t("This option allows for reindexing of only those features that belong to the selected libraries below. All other features will be unaffected. To reindex all features in the site see the Feature Administration page."),
- '#weight' => 1,
- );
- $form['reindex']['re-libraries'] = array (
- '#title' => t('Libraries'),
- '#type' => t('checkboxes'),
- '#description' => t("Check the libraries whoee features you want to reindex. Note: this list contains all libraries, even those that may not be synced."),
- '#required' => FALSE,
- '#prefix' => '<div id="lib_boxes">',
- '#suffix' => '</div>',
- '#options' => $lib_boxes,
- '#weight' => 2,
- );
- $form['reindex']['re-button'] = array(
- '#type' => 'submit',
- '#value' => t('Reindex Features'),
- '#weight' => 3,
- );
- }
- function get_tripal_library_admin_form_sync_set (&$form) {
-
- $form['sync'] = array(
- '#type' => 'fieldset',
- '#title' => t('Sync Libraries')
- );
-
- $sql = "SELECT * FROM {Library} ORDER BY uniquename";
- $previous_db = tripal_db_set_active('chado');
- $lib_rset = db_query($sql);
- tripal_db_set_active($previous_db);
-
-
-
-
- $lib_boxes = array();
- $added = 0;
- while($library = db_fetch_object($lib_rset)){
-
-
- $sql = "SELECT * FROM {chado_library} WHERE library_id = %d";
- if(!db_fetch_object(db_query($sql,$library->library_id))){
- $lib_boxes[$library->library_id] = "$library->name";
- $added++;
- }
- }
-
-
- if($added > 0){
- $lib_boxes['all'] = "All Libraries";
- $form['reindex']['description'] = array(
- '#type' => 'item',
- '#value' => t("This option allows for the creation of Drupal content for libraries in chado. Only the selected libraries will be synced."),
- '#weight' => 1,
- );
- $form['sync']['libraries'] = array (
- '#title' => t('Available Libraries'),
- '#type' => t('checkboxes'),
- '#description' => t("Check the libraries you want to sync. Drupal content will be created for each of the libraries listed above. Select 'All Libraries' to sync all of them."),
- '#required' => FALSE,
- '#prefix' => '<div id="lib_boxes">',
- '#suffix' => '</div>',
- '#options' => $lib_boxes,
- '#weight' => 2,
- );
- $form['sync']['button'] = array(
- '#type' => 'submit',
- '#value' => t('Sync Libraries'),
- '#weight' => 3,
- );
- }
-
- else {
- $form['sync']['value'] = array(
- '#value' => t('All libraries in Chado are currently synced with Drupal.')
- );
- }
- }
- function tripal_library_admin_validate($form, &$form_state) {
- global $user;
- $job_args = array();
-
- if ($form_state['values']['op'] == t('Sync Libraries')) {
-
-
- $libraries = $form_state['values']['libraries'];
- $do_all = FALSE;
- $to_sync = array();
- foreach ($libraries as $library_id){
- if(preg_match("/^all$/i",$library_id)){
- $do_all = TRUE;
- }
- if($library_id and preg_match("/^\d+$/i",$library_id)){
-
- $sql = "SELECT * FROM {Library} WHERE library_id = %d";
- $previous_db = tripal_db_set_active('chado');
- $library = db_fetch_object(db_query($sql,$library_id));
- tripal_db_set_active($previous_db);
- $to_sync[$library_id] = $library->name;
- }
- }
-
- if($do_all){
- tripal_add_job('Sync all libraries','tripal_library','tripal_library_sync_libraries',$job_args,$user->uid);
- }
- else{
- foreach($to_sync as $library_id => $name){
- $job_args[0] = $library_id;
- tripal_add_job("Sync library: $name",'tripal_library','tripal_library_sync_libraries',$job_args,$user->uid);
- }
- }
- }
-
-
- if ($form_state['values']['op'] == t('Reindex Features')) {
- $libraries = $form_state['values']['re-libraries'];
- foreach ($libraries as $library_id){
- if($library_id and preg_match("/^\d+$/i",$library_id)){
-
- $sql = "SELECT * FROM {Library} WHERE library_id = %d";
- $previous_db = tripal_db_set_active('chado');
- $library = db_fetch_object(db_query($sql,$library_id));
- tripal_db_set_active($previous_db);
- $job_args[0] = $library_id;
- tripal_add_job("Reindex features for library: $library->name",'tripal_library',
- 'tripal_library_reindex_features',$job_args,$user->uid);
- }
- }
- }
-
-
- if ($form_state['values']['op'] == t('Set Feature Taxonomy')) {
- $libraries = $form_state['values']['tx-libraries'];
- foreach ($libraries as $library_id){
- if($library_id and preg_match("/^\d+$/i",$library_id)){
-
- $sql = "SELECT * FROM {Library} WHERE library_id = %d";
- $previous_db = tripal_db_set_active('chado');
- $library = db_fetch_object(db_query($sql,$library_id));
- tripal_db_set_active($previous_db);
- $job_args[0] = $library_id;
- tripal_add_job("Set taxonomy for features in library: $library->name",'tripal_library',
- 'tripal_library_taxonify_features',$job_args,$user->uid);
- }
- }
- }
-
-
- if ($form_state['values']['op'] == t('Clean up orphaned libraries')) {
- tripal_add_job('Cleanup orphaned libraries','tripal_library',
- 'tripal_library_cleanup',$job_args,$user->uid);
- }
- }
- function tripal_library_show_libraries (){
-
- $sql = "SELECT COUNT(library_id) FROM {chado_library}";
- $no_libs = db_result(db_query ($sql));
- if($no_libs != 0) {
- $libraries = get_chado_libraries ();
- if($no_libs != count($libraries)) {
- drupal_set_message("Synchronization needed.");
- }
- return theme('tripal_library_library_table', &$libraries);
- } else {
- return t("No library exists. Please contact administrators to ".
- "synchronize libraries.");
- }
- }
- function tripal_library_cron (){
- }
- function tripal_library_library_access($op, $node, $account){
- if ($op == 'create') {
- return user_access('create chado_library content', $account);
- }
- if ($op == 'update') {
- if (user_access('edit any chado_library content', $account) ||
- (user_access('edit own chado_library content', $account) &&
- ($account->uid == $node->uid))){
- return TRUE;
- }
- }
- if ($op == 'delete') {
- if (user_access('delete any chado_library content', $account) ||
- (user_access('delete own chado_library content', $account) &&
- ($account->uid == $node->uid))) {
- return TRUE;
- }
- }
- }
- function chado_library_validate($node){
- $lib = 0;
-
-
- if($node->library_id){
- $sql = "SELECT * FROM ".
- "{Library} WHERE ".
- "uniquename = '%s' ".
- "AND NOT library_id = %d";
- $previous_db = tripal_db_set_active('chado');
- $lib = db_fetch_object(db_query($sql, $node->uniquename,
- $node->library_id));
- tripal_db_set_active($previous_db);
- } else {
- $sql = "SELECT * FROM ".
- "{Library} ".
- "WHERE uniquename = '%s'";
- $previous_db = tripal_db_set_active('chado');
- $lib = db_fetch_object(db_query($sql, $node->uniquename));
- tripal_db_set_active($previous_db);
- }
- if($lib){
- form_set_error('uniquename',t('The unique library name already exists. '.
- 'Please choose another'));
- }
- }
- function chado_library_insert($node){
-
-
- $l_sql= "SELECT library_id ".
- "FROM {Library} ".
- "WHERE organism_id = %d ".
- "AND uniquename = '%s' ".
- "AND type_id = %d";
- $previous_db = tripal_db_set_active('chado');
- $library = db_fetch_object(db_query($l_sql, $node->organism_id,
- $node->uniquename, $node->type_id));
- $libid = $node->library_id;
-
-
- if (!$library) {
- $sql = "INSERT INTO {library} (organism_id, name, uniquename, type_id)".
- "VALUES(%d,'%s','%s', ".
- " (SELECT cvterm_id ".
- " FROM {CVTerm} CVT ".
- " INNER JOIN CV ON CVT.cv_id = CV.cv_id ".
- " WHERE CV.name = 'tripal' and CVT.name = '%s'))";
- db_query($sql,$node->organism_id,$node->title,$node->uniquename,
- $node->library_type);
-
- $sql = "SELECT library_id ".
- "FROM {library} ".
- "WHERE uniquename = '%s'";
- $lib = db_fetch_object(db_query($sql, $node->uniquename));
- $libid = $lib->library_id;
- }
-
- tripal_db_set_active($previous_db);
-
- $sql = "INSERT INTO {chado_library} (nid, vid, library_id) ".
- "VALUES (%d, %d, %d)";
- db_query($sql, $node->nid, $node->vid, $libid);
-
- if (!$library) {
- tripal_library_add_properties($node,$libid);
- }
- }
- function chado_library_update($node){
- if($node->revision){
-
- } else {
-
- $sql = "SELECT library_id ".
- "FROM {chado_library} ".
- "WHERE vid = %d";
- $lib = db_fetch_object(db_query($sql, $node->vid));
-
- $sql = "UPDATE {library} ".
- " SET name = '%s', uniquename = '%s', organism_id = %d, ".
- " type_id = (SELECT cvterm_id ".
- " FROM {CVTerm} CVT ".
- " INNER JOIN CV ON CVT.cv_id = CV.cv_id ".
- " WHERE CV.name = 'local' and CVT.name = '%s') ".
- "WHERE library_id = %d ";
- $previous_db = tripal_db_set_active('chado');
- db_query($sql, $node->title, $node->uniquename, $node->organism_id,
- $node->library_type, $lib->library_id);
- tripal_db_set_active($previous_db);
- tripal_library_add_properties($node,$lib->library_id);
- tripal_library_add_taxonomy($node,$lib->library_id);
- }
- }
- function tripal_library_add_properties ($node,$library_id){
-
- $previous_db = tripal_db_set_active('chado');
-
-
- $sql = "DELETE FROM {libraryprop} ".
- "WHERE library_id = %d";
- db_query($sql,$library_id);
-
- $sql = "INSERT INTO {libraryprop} (library_id, type_id, value) ".
- "VALUES (%d,".
- " (SELECT cvterm_id ".
- " FROM {CVTerm} CVT ".
- " INNER JOIN CV ON CVT.cv_id = CV.cv_id ".
- " WHERE CV.name = 'tripal' and CVT.name = '%s'), ".
- " '%s')";
- if($node->library_description){
- db_query($sql,$library_id,'library_description',
- $node->library_description);
- }
-
- tripal_db_set_active($previous_db);
- }
- function tripal_library_add_taxonomy ($node,$library_id){
-
-
-
- module_load_include('inc', 'taxonomy', 'taxonomy.admin');
-
-
- $vocab_form['values']['name'] = 'DNA Libraries';
- $vocab_form['values']['description'] = 'Allows for associating/searching of library features by library name';
- $vocab_form['values']['help'] = '';
- $vocab_form['values']['module'] = 'taxonomy';
- drupal_execute('taxonomy_form_vocabulary',$vocab_form);
- return;
-
-
- if($vid){
- $tree = taxonomy_get_tree($vid);
- $found = 0;
- foreach ($tree as $term) {
- if($term->name == $node->title){
- $found = 1;
- }
- }
-
- if(!$found){
- $form_state = array();
- $form_state['values']['name'] = $node->title;
- $form_state['values']['description'] = $library_id;
- drupal_execute('taxonomy_form_term',$form_state,$vid);
- }
- }
- }
- function chado_library_form ($node){
- $type = node_get_types('type',$node);
- $form = array();
-
-
- $form['library_id'] = array(
- '#type' => 'value',
- '#value' => $node->library_id,
- );
- $form['title']= array(
- '#type' => 'textfield',
- '#title' => t('Library Title'),
- '#description' => t('Please enter the title for this library. '.
- 'This appears at the top of the library page.'),
- '#required' => TRUE,
- '#default_value' => $node->title,
- '#weight' => 1
- );
- $form['uniquename']= array(
- '#type' => 'textfield',
- '#title' => t('Unique Library Name'),
- '#description' => t('Please enter a unique name for this library'),
- '#required' => TRUE,
- '#default_value' => $node->uniquename,
- '#weight' => 2
- );
-
- $library_types = array();
- $library_types[''] = '';
- $library_types['cdna_library'] = 'cDNA Library';
- $library_types['bac_library'] = 'BAC Library';
- $library_types['fosmid_library'] = 'FOSMID Library';
- $library_types['cosmid_library'] = 'COSMID Library';
- $library_types['yac_library'] = 'YAC Library';
-
-
- $form['library_type'] = array (
- '#title' => t('Library Type'),
- '#type' => t('select'),
- '#description' => t("Choose the library type."),
- '#required' => TRUE,
- '#default_value' => $node->library_type,
- '#options' => $library_types,
- '#weight' => 3
- );
-
- $sql = "SELECT * FROM {Organism}";
- $previous_db = tripal_db_set_active('chado');
- $org_rset = db_query($sql);
- tripal_db_set_active($previous_db);
- $organisms = array();
- $organisms[''] = '';
- while($organism = db_fetch_object($org_rset)){
- $organisms[$organism->organism_id] =
- "$organism->genus $organism->species ($organism->common_name)";
- }
- $form['organism_id'] = array (
- '#title' => t('Organism'),
- '#type' => t('select'),
- '#description' => t("Choose the organism with which this library is ".
- "associated."),
- '#required' => TRUE,
- '#default_value' => $node->organism_id,
- '#options' => $organisms,
- '#weight' => 4,
- );
- $form['library_description']= array(
- '#type' => 'textarea',
- '#title' => t('Library Description'),
- '#description' => t('A brief description of the library'),
- '#required' => TRUE,
- '#default_value' => $node->library_description,
- '#weight' => 5
- );
-
- $form['sequence_num'] = array(
- '#type' => 'value',
- '#value' => $node->sequence_num,
- );
- return $form;
- }
- function tripal_library_sync_libraries ($library_id = NULL, $job_id = NULL){
- global $user;
- $page_content = '';
-
- if(!$library_id){
- $sql = "SELECT * FROM {Library} L";
- $previous_db = tripal_db_set_active('chado');
- $results = db_query($sql);
- tripal_db_set_active($previous_db);
- } else {
- $sql = "SELECT * FROM {Library} L WHERE library_id = %d";
- $previous_db = tripal_db_set_active('chado');
- $results = db_query($sql,$library_id);
- tripal_db_set_active($previous_db);
- }
-
-
- $sql = "SELECT * FROM {chado_library} ".
- "WHERE library_id = %d";
- while($library = db_fetch_object($results)){
-
-
- if(!db_fetch_object(db_query($sql,$library->library_id))){
- $new_node = new stdClass();
- $new_node->type = 'chado_library';
- $new_node->uid = $user->uid;
- $new_node->title = "$library->name";
- $new_node->library_id = $library->library_id;
- $new_node->organism_id = $library->organism_id;
- $new_node->uniquename = $library->uniquename;
- $new_node->type_id = $library->type_id;
- node_validate($new_node);
- if(!form_get_errors()){
- $node = node_submit($new_node);
- node_save($node);
- if($node->nid){
- $page_content .= "Added $library->name<br>";
- }
- }
- } else {
- $page_content .= "Skipped $library->name<br>";
- }
- }
- return $page_content;
- }
- function chado_library_load($node){
- $sql = 'SELECT library_id FROM {chado_library} WHERE vid = %d';
- $map = db_fetch_object(db_query($sql, $node->vid));
- $additions->library_id = $map->library_id;
- $previous_db = tripal_db_set_active('chado');
-
- $sql = "SELECT L.organism_id, L.uniquename, CVT.name as type_name ".
- "FROM {Library} L ".
- "INNER JOIN CVTerm CVT ON CVT.cvterm_id = L.type_id ".
- "WHERE library_id = %d";
- $library = db_fetch_object(db_query($sql, $map->library_id));
- $additions->uniquename = $library->uniquename;
- $additions->library_type = $library->type_name;
- $additions->organism_id = $library->organism_id;
- $sql = "SELECT genus, species, common_name ".
- "FROM {organism} O ".
- "INNER JOIN library L ".
- "ON L.organism_id = O.organism_id ".
- "WHERE L.library_id = %d";
- $organism = db_fetch_object(db_query($sql,$map->library_id));
- $additions->genus = $organism->genus;
- $additions->species = $organism->species;
- $additions->common_name = $organism->common_name;
- $sql = "SELECT LP.value ".
- "FROM {libraryProp} LP ".
- "WHERE LP.library_id = %d ";
- $desc = db_fetch_object(db_query($sql, $map->library_id))->value;
- if ($desc) {
- $additions->library_description = $desc;
- } else {
- $additions->library_description = "NA";
- }
-
-
- if ($map->library_id) {
- $sql = "SELECT num_features FROM {library_feature_count} ".
- "WHERE Library_id = $map->library_id";
- $additions->num_features = db_fetch_object(db_query($sql, $map->library_id))->num_features;
- }
- tripal_db_set_active($previous_db);
- return $additions;
- }
- function chado_library_view ($node, $teaser = FALSE, $page = FALSE) {
-
- if (!$teaser) {
- $node = node_prepare($node, $teaser);
-
-
-
- if(!$node->genus) {
- $previous_db = tripal_db_set_active('chado');
- $sql = "SELECT * FROM {organism} WHERE organism_id = %d";
- $data = db_fetch_object(db_query($sql, $node->organism_id));
- $node->genus = $data->genus;
- $node->species = $data->species;
- $node->common_name = $data->common_name;
- tripal_db_set_active($previous_db);
- }
- }
- return $node;
- }
- function theme_tripal_library_library_table (&$libraries) {
-
- $output = "<div id=\"libraries\">";
- $output .= '<table>';
- $output .= "<tr>";
- $output .= "<th>Name</th>";
- $output .= "<th>Type</th>";
- $output .= "<th>Organism</th>";
- $output .= "<th>Description</th>";
- $output .= "</tr>";
- foreach($libraries as $library){
- $lib_url = url("node/$library->node_id");
- $output .= "<tr>";
- $output .= "<td>".
- " <a href=\"$lib_url\">$library->name</a>".
- "</td>";
- if(strcasecmp($library->type_name, 'bac_library') == 0){
- $output .= "<td>BAC</td>";
- }
- elseif(strcasecmp($library->type_name, 'cdna_library') == 0){
- $output .= "<td>cDNA</td>";
- }
- else{
- $output .= "<td>$library->type_name</td>";
- }
- $output .= "<td nowrap>".
- " $library->common_name".
- "</td>";
- $description = $library->library_description;
- $output .= "<td>$description</td>";
- $output .= "</tr>";
- }
- $output .= "</table>";
- $output .= "</div>";
- return $output;
- }
- function tripal_library_feature_set_taxonomy($library_id = NULL){
-
-
- $vocabularies = taxonomy_get_vocabularies();
- $vid = NULL;
- foreach($vocabularies as $vocab){
- if($vocab->name == 'Library'){
- $vid = $vocab->vid;
- }
- }
- if(!$vid){
- return;
- }
-
- if($library_id){
- print "Finding features for library with ID: $library_id\n";
- $sql = "SELECT LF.feature_id, L.library_id, L.name as libname ".
- "FROM {library_feature} LF ".
- "INNER JOIN Library L ON LF.library_id = L.library_id ".
- "WHERE L.library_id = $library_id ".
- "ORDER BY LF.feature_id";
- $previous_db = tripal_db_set_active('chado');
- $features = db_query($sql);
- tripal_db_set_active($previous_db);
- } else {
- print "Finding features for all libraries\n";
- $sql = "SELECT LF.feature_id, L.library_id, L.name as libname ".
- "FROM {library_feature} LF ".
- "INNER JOIN Library L ON LF.library_id = L.library_id ".
- "ORDER BY LF.feature_id";
- $previous_db = tripal_db_set_active('chado');
- $features = db_query($sql);
- tripal_db_set_active($previous_db);
- }
- $node_sql = "SELECT * FROM {chado_feature} CF ".
- " INNER JOIN {node} N ON CF.nid = N.nid ".
- "WHERE feature_id = %d";
-
- while($feature = db_fetch_object($features)){
- $node = db_fetch_object(db_query($node_sql,$feature->feature_id));
- $tags["$vid"] = $feature->libname;
- $terms['tags'] = $tags;
- taxonomy_node_save($node,$terms);
- print "Updated $feature->feature_id as $feature->libname\n";
- }
- }
- function tripal_library_reindex_features ($library_id = NULL, $job_id = NULL){
- $i = 0;
-
-
-
- if($library_id){
- $sql = "SELECT LF.feature_id, L.library_id, L.name as libname ".
- " FROM {library_feature} LF ".
- " INNER JOIN Library L ON LF.library_id = L.library_id ".
- "WHERE L.library_id = $library_id ".
- "ORDER BY LF.feature_id";
- $previous_db = tripal_db_set_active('chado');
- $results = db_query($sql);
- tripal_db_set_active($previous_db);
- }
- else {
- $sql = "SELECT LF.feature_id, L.library_id, L.name as libname ".
- " FROM {library_feature} LF ".
- " INNER JOIN Library L ON LF.library_id = L.library_id ".
- "ORDER BY LF.feature_id";
- $previous_db = tripal_db_set_active('chado');
- $results = db_query($sql);
- tripal_db_set_active($previous_db);
- }
-
- $count = 0;
- $ids = array();
- while($id = db_fetch_object($results)){
- $ids[$count] = $id->feature_id;
- $count++;
- }
- $interval = intval($count * 0.01);
- foreach($ids as $feature_id){
-
- if($job_id and $i % interval == 0){
- tripal_job_set_progress($job_id,intval(($i/$count)*100));
- }
- tripal_feature_sync_feature ($feature_id);
- $i++;
- }
- }
- function tripal_library_taxonify_features ($library_id = NULL, $job_id = NULL){
- $i = 0;
-
-
-
- if($library_id){
- $sql = "SELECT LF.feature_id, L.library_id, L.name as libname ".
- " FROM {library_feature} LF ".
- " INNER JOIN Library L ON LF.library_id = L.library_id ".
- "WHERE L.library_id = $library_id ".
- "ORDER BY LF.feature_id";
- $previous_db = tripal_db_set_active('chado');
- $results = db_query($sql);
- tripal_db_set_active($previous_db);
- }
- else {
- $sql = "SELECT LF.feature_id, L.library_id, L.name as libname ".
- " FROM {library_feature} LF ".
- " INNER JOIN Library L ON LF.library_id = L.library_id ".
- "ORDER BY LF.feature_id";
- $previous_db = tripal_db_set_active('chado');
- $results = db_query($sql);
- tripal_db_set_active($previous_db);
- }
-
- $count = 0;
- $ids = array();
- while($id = db_fetch_object($results)){
- $ids[$count] = $id->feature_id;
- $count++;
- }
-
- tripal_feature_set_vocabulary();
-
- $nsql = "SELECT * FROM {chado_feature} CF ".
- " INNER JOIN {node} N ON N.nid = CF.nid ".
- "WHERE feature_id = %d";
-
- $interval = intval($count * 0.01);
- foreach($ids as $feature_id){
-
- if($job_id and $i % interval == 0){
- tripal_job_set_progress($job_id,intval(($i/$count)*100));
- }
- $node = db_fetch_object(db_query($nsql,$feature_id));
- tripal_feature_set_taxonomy($node,$feature_id);
- $i++;
- }
- }
- function chado_library_delete(&$node){
-
-
- $sql_drupal = "SELECT library_id ".
- "FROM {chado_library} ".
- "WHERE nid = %d AND vid = %d";
- $library_id = db_result(db_query($sql_drupal, $node->nid, $node->vid));
-
-
- $sql_del = "DELETE FROM {chado_library} ".
- "WHERE nid = %d ".
- "AND vid = %d";
- db_query($sql_del, $node->nid, $node->vid);
- $sql_del = "DELETE FROM {node} ".
- "WHERE nid = %d ".
- "AND vid = %d";
- db_query($sql_del, $node->nid, $node->vid);
- $sql_del = "DELETE FROM {node_revisions} ".
- "WHERE nid = %d ".
- "AND vid = %d";
- db_query($sql_del, $node->nid, $node->vid);
-
- $previous_db = tripal_db_set_active('chado');
- db_query("DELETE FROM {library} WHERE library_id = %d", $library_id);
- db_query("DELETE FROM {libraryprop} WHERE library_id = %d", $library_id);
- tripal_db_set_active($previous_db);
- }
- function tripal_library_block($op = 'list', $delta = '0', $edit = array()){
- switch($op){
- case 'list':
- $blocks[0]['info'] = t('Libraries');
- return $blocks;
- case 'view':
- if(user_access('access chado_library content')){
-
- $sql = "SELECT COUNT(library_id) FROM {chado_library}";
- $no_libs = db_result(db_query ($sql));
- if($no_libs != 0) {
- $libraries = get_chado_libraries();
- foreach($libraries as $library){
-
- $items[] = l($library->name, 'node/' . $library->node_id);
- }
- } else {
- $items[] = t("No library exists.");
- }
- $block['subject'] = t('Libraries');
-
- $block['content'] = theme('item_list', $items);
- }
- return $block;
- }
- }
- function get_chado_libraries() {
- $sql_drupal = "SELECT COUNT (library_id) FROM {chado_library}";
- $no_libs = db_result(db_query($sql_drupal));
- if ($no_libs != 0) {
-
- $sql = "SELECT library_id, nid FROM {chado_library}";
- $result = db_query($sql);
- $previous_db = tripal_db_set_active('chado');
-
- $sql_info = "SELECT L.name, uniquename, genus, species, common_name, ".
- " CVT.name as type_name ".
- "FROM {Library} L ".
- "INNER JOIN Organism O ON L.organism_id = O.organism_id ".
- "INNER JOIN CVTerm CVT ON L.type_id = CVT.cvterm_id ".
- "WHERE library_id=%d";
-
- $sql_desc = "SELECT value ".
- "FROM {Libraryprop} LP ".
- "INNER JOIN CVTerm CVT ON LP.type_id = CVT.cvterm_id ".
- "WHERE library_id = %d AND CVT.name = 'library_description'";
- $libraries = array();
- while ($data = db_fetch_object($result)) {
- $library = db_fetch_object(db_query($sql_info, $data->library_id));
- $library->node_id = $data->nid;
- $desc = db_fetch_object(db_query($sql_desc, $data->library_id))->value;
- if ($desc) {
- $library->library_description = $desc;
- } else {
- $library->library_description = "NA";
- }
-
- $key = strtolower($library->uniquename);
- $libraries [$key] = $library;
- }
- tripal_db_set_active($previous_db);
-
- ksort($libraries, SORT_STRING);
- return $libraries;
- }
- }
- function tripal_library_cleanup($dummy = NULL, $job_id = NULL) {
-
- $dsql = "SELECT * FROM {node} WHERE type = 'chado_library' order by nid";
- $nsql = "SELECT * FROM {node} WHERE nid = %d";
- $csql = "SELECT * FROM {chado_library} where nid = %d ";
- $cosql= "SELECT * FROM {chado_library}";
- $tsql = "SELECT * FROM {library} L WHERE library_id = %d";
-
- $results = db_query($dsql);
- $count = 0;
- $nodes = array();
- while($node = db_fetch_object($results)){
- $nodes[$count] = $node;
- $count++;
- }
-
- $results = db_query($cosql);
- $cnodes = array();
- while($node = db_fetch_object($results)){
- $cnodes[$count] = $node;
- $count++;
- }
- $interval = intval($count * 0.01);
-
- foreach($nodes as $nid){
-
- if($job_id and $i % $interval == 0){
- tripal_job_set_progress($job_id,intval(($i/$count)*100));
- }
-
-
- $library = db_fetch_object(db_query($csql,$nid->nid));
- if(!$library){
- node_delete($nid->nid);
- $message = "Missing in chado_library table.... DELETING: $nid->nid\n";
- watchdog('tripal_library',$message,array(),WATCHDOG_WARNING);
- continue;
- }
- $i++;
- }
-
- foreach($cnodes as $nid){
-
- if($job_id and $i % $interval == 0){
- tripal_job_set_progress($job_id,intval(($i/$count)*100));
- }
- $node = db_fetch_object(db_query($nsql,$nid->nid));
- if(!$node){
- db_query("DELETE FROM {chado_library} WHERE nid = $nid->nid");
- $message = "chado_library missing node.... DELETING: $nid->nid\n";
- watchdog('tripal_library',$message,array(),WATCHDOG_WARNING);
- }
- $i++;
- }
- return '';
- }
|