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']));
}
Ejemplo n.º 2
0
        $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) {
                $item->keywords[$i] = rtrim(ltrim($item->keywords[$i]));