Esempio n. 1
0
    {
        $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');
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']));
}
Esempio n. 3
0
<?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>
    {
        $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);
Esempio n. 5
0
 /**
  * name: render
  * params:
  */
 public function render($additional_values = null)
 {
     $out = "";
     $out .= "<table cellspacing=\"" . $this->cellspacing . "\" cellpadding=\"" . $this->cellpadding . "\" class=\"" . $this->cssclass . "\" id=\"" . $this->client_id() . "\">" . spchr::endl;
     if ($this->datasource !== null) {
         $types = $this->datasource->get_header()->get_types();
         $names = $this->datasource->get_header()->get_names();
         $header_items = array_values($this->datasource->get_header()->get_items());
         $out .= "<tr>" . spchr::endl;
         $header_class = $this->headercellclass;
         $base_url = $this->base_url;
         $sortby_param = $this->get_sortby_param();
         $current_sorting = $this->get_sorting();
         $current_direction = $this->get_sort_direction();
         $direction_param = $this->get_sort_direction_param();
         if (!is_null($additional_values)) {
             extract($additional_values);
         }
         foreach ($header_items as $hitem) {
             if (!$hitem->get_visible()) {
                 continue;
             }
             $sortable = $hitem->is_sortable();
             $sortname = $hitem->get_name();
             $title = $hitem->get_title();
             $direction = $current_sorting == $hitem->get_name() && $current_direction != sorting::SORT_DIR_DESC ? sorting::SORT_DIR_DESC : sorting::SORT_DIR_ASC;
             $params = $this->url_params($sortby_param, $direction_param);
             ob_start();
             eval($this->header_template);
             $result = ob_get_contents();
             $out .= spchr::tab . "<td class=\"{$header_class}\">" . spchr::endl;
             $out .= spchr::tab2 . $result . spchr::endl;
             $out .= spchr::tab . "</td>" . spchr::endl;
             ob_end_clean();
         }
         $out .= "</tr>" . spchr::endl;
         $values = $this->datasource->get_values();
         if (count($values)) {
             foreach ($values as $num => $columns) {
                 $col_id = 0;
                 $out .= "<tr>" . spchr::endl;
                 foreach ($columns as $data) {
                     if (!$this->datasource->get_header()->is_visible($names[$col_id])) {
                         $col_id++;
                         continue;
                     }
                     $out .= spchr::tab . "<td class=\"" . $this->cellclass . "\">" . spchr::endl;
                     $out .= spchr::tab2 . $header_items[$col_id]->get_formatter()->format($data, $types[$col_id], $col_id++, $columns) . spchr::endl;
                     $out .= spchr::tab . "</td>" . spchr::endl;
                 }
                 $out .= "</tr>" . spchr::endl;
             }
         } else {
             $out .= '<tr><td colspan="' . sizeof($header_items) . '">' . $this->no_data_message . '</td></tr>';
         }
     } else {
         $out .= '<tr><td>' . $this->no_data_message . '</td></tr>';
     }
     $out .= "</table>" . spchr::endl;
     return $out;
 }