--- db/prgsrc/drupal/modules/chgk_db/chgk_db.module 2010/04/24 18:04:15 1.5 +++ db/prgsrc/drupal/modules/chgk_db/chgk_db.module 2010/04/24 21:45:49 1.6 @@ -6,24 +6,68 @@ *********************/ require_once(dirname(__FILE__)."/classes/DbPackage.class.php"); +require_once(dirname(__FILE__)."/classes/DbEditors.class.php"); /** * Implementation of hook_menu(). */ function chgk_db_menu() { - $items['print'] = array( +#print_r(debug_backtrace()); + $items['tour/%/view'] = array( + 'title' => 'Читать', + 'type' => MENU_DEFAULT_LOCAL_TASK, + 'weight' => 0 + ); + + $items['tour/%/print'] = array( 'path' => 'print', + 'title' => 'Печатать', 'page callback' => 'chgk_db_print', 'page arguments' => array(1), 'access callback' => "chgk_db_access", + 'access arguments' => array(1, 'print'), + 'localized_options' => array('attributes' => array('target'=>'_blank')), + 'type' => MENU_LOCAL_TASK, + 'weight' => 1 ); - $items['fb2'] = array( - 'path' => 'fb2', + + + $items['tour/%/fb2'] = array( + 'path' => 'tour/%/fb2', + 'title' => 'FB2', 'page callback' => 'chgk_db_fb2', 'page arguments' => array(1), 'access callback' => "chgk_db_access", + 'access arguments' => array(1, 'fb2'), + 'type' => MENU_LOCAL_TASK, + 'weight' => 2 + + ); + $items['tree'] = array( + 'path' => 'tree', + 'title' => 'Все турниры', + 'page callback' => 'chgk_db_tree', + 'access callback' => "chgk_db_access", + 'type' => MENU_NORMAL_ITEM + ); + + $items['editors'] = array( + 'path' => 'editors', + 'title' => 'Редакторы', + 'page callback' => 'chgk_db_editors', + 'access callback' => "chgk_db_access", + 'type' => MENU_NORMAL_ITEM + ); + + $items['tour'] = array( + 'path' => 'tour', + 'page callback' => 'chgk_db_tour', + 'page arguments' => array(1), + 'access callback' => "chgk_db_access" ); + + return $items; } @@ -34,7 +78,10 @@ function chgk_db_theme() { $items['chgk_db_print'] = array( 'arguments' => array( 'title' =>'', - 'content' => '' + 'content' => '', + 'link' => '' + + ), 'template'=>'templates/chgk_db_print' ); @@ -59,6 +106,14 @@ function chgk_db_theme() { 'template'=>'templates/chgk_db_tour_fb2' ); + $items['chgk_db_tours_fb2'] = array( + 'arguments' => array( + 'tournament'=>'', + ), + 'template'=>'templates/chgk_db_tours_fb2' + ); + + $items['chgk_db_question'] = array( 'arguments' => array( @@ -100,10 +155,35 @@ function chgk_db_print($string) { print $tournament->getPrintVersion(); } +function chgk_db_tour($name) { + if (empty($name)) { + $tournament = DbPackage::newRoot(); + } else { + $tournament = DbPackage::newFromDb($name); + } + drupal_set_title($tournament->getFullTitle()); + $breadcrumb = array_merge(drupal_get_breadcrumb(),$tournament->getBreadcrumb()); + drupal_set_breadcrumb($breadcrumb); + return $tournament->getHtmlContent(); +} + +function chgk_db_tree() { + $class = DbPackage::newRoot(); + $class -> loadTree(); + drupal_set_title('Все турниры'); +# $breadcrumb = array_merge(drupal_get_breadcrumb(),$tournament->getBreadcrumb()); + drupal_set_breadcrumb($breadcrumb); + + return $class->htmlTree()."\n"; +} + function chgk_db_fb2($string) { $tournament = DbPackage::newFromDb($string); - $tournament->getAll(); - $xml = theme('chgk_db_fb2', $tournament); + $xml = $tournament->getFb2(); + if (!$xml) { + print "Something is wrong :("; + exit; + } $filename = "$string.fb2"; $zipname = $filename.".zip"; @@ -119,10 +199,69 @@ function chgk_db_fb2($string) { system("zip $zipname $filename>/dev/null"); print passthru("cat $zipname"); exit; - #print $tournament->getFb2(); } -function chgk_db_access() { +function chgk_db_access($tour=NULL, $action ='') { + if ($action == 'fb2') { + $tournament = DbPackage::newFromDb($tour); + if (!$tournament->hasFb2()) { + return FALSE; + } + } elseif ($action == 'print') { + $tournament = DbPackage::newFromDb($tour); + if (!$tournament->hasPrintVersion()) { + return FALSE; + } + } return TRUE; -} \ No newline at end of file +} + +function chgk_db_search($op = 'search', $keys = NULL, $skip_access_check = FALSE) { + if ($op == 'name') { + return 'Вопросы'; + } elseif( $op == 'search') { + $db = new DbDatabase(); + $res = $db->getFulltextSearchRes($keys); + $factory = new DbQuestionFactory(); + + while($a = db_fetch_object($res)) { + $q = $factory->getQuestion($a); + $q->setSearchString($keys); + $results[] = array( + 'link' => $q->getUrl(), + 'title' => $q->getSearchTitle(), + 'snippet' => $q->getHtml() + ); + } + return $results; + + } + return true; +} + + function chgk_db_form_alter(&$form, &$form_state) { + if ($form['#submit'][0] == 'search_box_form_submit') { + $form['#submit'][] = 'chgk_db_search_box_submit'; + } + } +function chgk_db_editors() { + if ($id = arg(1)) { + $author = new DbEditor($id); + drupal_set_title($author->getFullName()); + $breadcrumb = array_merge( + drupal_get_breadcrumb(), + $author->getBreadcrumb()); + drupal_set_breadcrumb($breadcrumb); + + return $author->getHtmlPage(); + } else { + $authorsEngine = new DbEditors(); + return $authorsEngine->getAllHtml(); + } + } + +function chgk_db_search_box_submit($form, &$form_state) { + $form_id = $form['form_id']['#value']; + $form_state['redirect'] = 'search/chgk_db/'. trim($form_state['values'][$form_id]); +}