$this->_field = $field; $this->_client_id = $client_id; } public function format($data, $type, $number = 0, $columns = null) { switch ($this->_field) { case 'actions': return '<a href="javascript:' . $this->_client_id . '.deleteItem(' . $data[0] . ');">Удалить</a>'; default: return parent::format($data, $type); } } } // Создаём DataSource $datasource = new grid_data_source(new grid_header_item_array(new grid_header_item('id', 'Id', type::STRING, true), new grid_header_item('title', 'Заголовок', type::STRING, true), new grid_header_item('actions', 'Действия', null, false, new my_grid_formatter('actions', $emanager->client_id())))); // Создаём новый грид и пейджер к нему $grid_pager = new ajax_grid_pager('my_grid_pager', mydata::get_total(), 5); $grid = new ajax_grid('my_grid', $datasource, $ajaxbuffer, $grid_pager); // выбираем текущую страницу отсортированных данных $mydata = mydata::get_page($grid_pager->get_pagesize(), $grid_pager->get_curpage(), $grid->get_sort_direction() != sorting::SORT_DIR_DESC); // добавляем данные в DataSource foreach ($mydata as $data) { $datasource->add_row(array($data[0], $data[1], $data)); } // чтобы было видно прогресс задержим рендеринг постбэка на секунду if ($ajaxbuffer->is_post_back()) { sleep(1); } // Выводим результат $templater = new templater(dirname(__FILE__) . '/templates/main.tpl.php'); die($templater->render(array('grid' => $grid, 'ajaxbuffer' => $ajaxbuffer, 'title' => 'Тестовая страница')));
class conflicts_act_formatter extends grid_formatter { public function format($data, $type, $number = 0, $columns = null) { return '<input type="checkbox" name="selected_kwds[' . $data['keyword'] . '][]" />'; } } class conflicts_cat_formatter extends grid_formatter { protected $_cats = null; public function __construct($cats) { $this->_cats = $cats; } public function format($data, $type, $number = 0, $columns = null) { return !empty($this->_cats[$data]['title_ru']) ? $this->_cats[$data]['title_ru'] : $this->_cats[$data]['title']; } } $ajaxbuffer = new ajax_buffer("update_buffer"); $datasource = new grid_data_source(new grid_header_item_array(new grid_header_item('id', '', null, false, new conflicts_act_formatter()), new grid_header_item('url', 'URL', type::LINK_NEWWIN, true, null, true, true), new grid_header_item('keyword', 'Слово', type::STRING, true, null, true, true), new grid_header_item('forcid', 'Категория', type::STRING, true, new conflicts_cat_formatter($cats)), new grid_header_item('incid', 'Конфликт с', type::STRING, true, new conflicts_cat_formatter($cats)), new grid_header_item('date', 'Дата', type::STRING, true))); $grid = new ajax_grid('grid', $datasource, $ajaxbuffer); $grid->no_data_message = 'Нет записей'; $grid->render_pager_top(true); $grid->render_filter_bottom(true); $grid_pager = new ajax_grid_pager('grid_pager', $BILL->GetRowsCount('url_categories_conflicts', $grid->get_filterfield(), $grid->get_filtering()), COUNT_ON_PAGE); $grid->attach_pager($grid_pager); $conflicts = $BILL->GetUrlCategoriesConflicts($grid_pager->get_curpage(), $grid_pager->get_pagesize(), $grid->get_sorting(), $grid->get_sort_direction(), $grid->get_filterfield(), $grid->get_filtering()); foreach ($conflicts as $conflict) { $datasource->add_row(array($conflict, $conflict['url'], $conflict['keyword'], $conflict['forcid'], $conflict['incid'], $conflict['date'])); }
$this->_field = $field; $this->_entities_manager = $entities_manager; } public function format($data, $type, $number = 0, $columns = null) { switch ($this->_field) { case 'actions': return '<a href="javascript:deleteCat(' . $data['cid'] . ');">Удалить</a>, <a href="javascript:editCat(' . $data['cid'] . ',\'' . $data['title'] . '\',\'' . $data['title_ru'] . '\');">Изменить</a>'; default: return parent::format($data, $type); } } } $cats_ds = new grid_data_source(new grid_header_item_array(new grid_header_item('cid', 'Id', type::STRING, true), new grid_header_item('title', 'Категория', type::STRING, true, null, true, true), new grid_header_item('title_ru', 'Название', type::STRING, true, null, true, true), new grid_header_item('actions', 'Действия', null, false, new cats_formatter('actions', $emanager)))); $cats_grid = new ajax_grid('cats_grid', $cats_ds, $ajaxbuf_cats); $cats_grid_pager = new ajax_grid_pager('cats_grid_pager', $BILL->GetRowsCount('url_categories', $cats_grid->get_filterfield(), $cats_grid->get_filtering()), 20); $cats_grid->attach_pager($cats_grid_pager); /** * Check if we need to make some actions */ if ($emanager->isAnyAction() && $ajaxbuf_cats->is_post_back()) { switch ($emanager->getAction()) { case $emanager->action->ADD: $item = json_decode($emanager->getItem()); $BILL->AddUrlCategory(array('title' => $item->title, 'title_ru' => $item->title_ru)); break; case $emanager->action->UPD: $item = json_decode($emanager->getItem()); $item->keywords = explode(',', $item->keywords); for ($i = 0; $i < count($item->keywords); ++$i) {
} /** * * @return grid_data_source */ function create_ds_header($manager) { global $cats_cid; return new grid_data_source(new grid_header_item_array(new grid_header_item('u2cid', 'Id', type::STRING, true), new grid_header_item('url', 'URL', type::LINK_NEWWIN, true, null, true, true), new grid_header_item('cid', 'Категория', type::STRING, true, new cat_urls_formatter('category', $cats_cid, $manager)), new grid_header_item('actions', 'Действия', null, false, new cat_urls_formatter('actions', $cats_cid, $manager)))); } $url_cats_unmatched_ds = create_ds_header($emanager->client_id()); $url_cats_unmatched_grid = new ajax_grid('url_cats_grid_unmatched', $url_cats_unmatched_ds, $ajaxbuf_url_cats); $url_cats_unmatched_grid_pager = new ajax_grid_pager('url_cats_grid_pager_unmatched', $BILL->GetCategoriesUrlUnMatchedCount($url_cats_unmatched_grid->get_filterfield(), $url_cats_unmatched_grid->get_filtering()), 10); $url_cats_unmatched_grid->attach_pager($url_cats_unmatched_grid_pager); $url_cats_matched_ds = create_ds_header($emanager->client_id()); $url_cats_matched_grid = new ajax_grid('url_cats_grid_matched', $url_cats_matched_ds, $ajaxbuf_url_matched_cats); $url_cats_matched_grid_pager = new ajax_grid_pager('url_cats_grid_pager_matched', $BILL->GetCategoriesUrlMatchedCount($url_cats_matched_grid->get_filterfield(), $url_cats_matched_grid->get_filtering()), 10); $url_cats_matched_grid->attach_pager($url_cats_matched_grid_pager); /** * Check if we need to make some actions */ if ($emanager->isAnyAction()) { //special actions if ($emanager->getAction() == 'changeCatByName') { $item = json_decode($emanager->getItem()); $BILL->UpdateUrlCategoryMatchByName($item->url, $item->name); } elseif ($emanager->getAction() == 'recognizeAll') { $url_cats = $BILL->GetUrlCategoriesMatch($url_cats_unmatched_grid_pager->get_curpage(), 10, $url_cats_unmatched_grid->get_sorting(), $url_cats_unmatched_grid->get_sort_direction(), array(0), array()); require_once dirname(__FILE__) . '/CADBiS/recognize.php'; foreach ($url_cats as $url) { $catname = Recognizer::recognizeByUrlCheck($url['url']);
<?php session_start(); date_default_timezone_set("Europe/Moscow"); require_once "lib/seminars.inc.php"; require_once "lib/ajax/grid.inc.php"; header("Content-Type: text/html;charset=UTF-8"); /* .. Initialization .. */ $PPP = 15; $seminars = new seminars(); $grid = new ajax_grid('grid'); $pager = new ajax_grid_pager("pager", $seminars->get_count(), $PPP); $grid->attach_pager($pager); /* .. Data binding .. */ $src = new grid_data_source(new grid_header_item_array(new grid_header_item('title', utils::cp2utf('Название'), type::STRING, true), new grid_header_item('desc', utils::cp2utf('Описание'), type::STRING), new grid_header_item('time', utils::cp2utf('Дата'), type::DATE_TIME, true, new sem_formatter()))); $data = $seminars->get_data($pager->get_curpage(), $PPP, $grid->get_current_sorting(), $grid->get_sort_direction()); foreach ($data as $seminar) { $src->add_row(array(utils::cp2utf($seminar->get_title()), utils::cp2utf($seminar->get_desc()), utils::cp2utf($seminar->get_time()))); } $grid->set_datasource($src); /* .. Output .. */ ?> <html> <head> <link href="skins/partner4/css/grid.css" rel="stylesheet"/> <link href="skins/partner4/css/ajax.css" rel="stylesheet"/> <script type="text/javascript" src="js/scriptaculous/prototype.js"></script> <script type="text/javascript" src="js/window/window.js"> </script> <script type="text/javascript" src="js/ajax/engine.js"></script> </head> <body>