Ejemplo n.º 1
0
    public function RightColumnContent()
    {
        switch ($this->Action) {
            case 'view':
                $this->CheckIdExist();
                $Object = Db_Category::getObjectById($this->Id);
                $this->TPL->assign('Object', $Object);
                $ObjectTrans = Db_CategoryTrans::getTransByObjectId($this->Id);
                $this->TPL->assign('ObjectTrans', $ObjectTrans);
                $LanguageModel = Db_Language::getLanguageWithKey();
                $this->TPL->assign('LanguageModel', $LanguageModel);
                break;
            case 'edit':
                $this->CheckIdExist();
                $Object = Db_Category::getObjectById($this->Id);
                $this->TPL->assign('Object', $Object);
                $ObjectTrans = Db_CategoryTrans::getTransByObjectId($this->Id);
                $this->TPL->assign('ObjectTrans', $ObjectTrans);
                $LanguageModel = Db_Language::getLanguageWithKey();
                $this->TPL->assign('LanguageModel', $LanguageModel);
                break;
            case 'delete':
                if ($this->Id != 0) {
                    Db_Category::deleteByField('id', $this->Id);
                    Db_CategoryTrans::deleteByField('ct_category_id', $this->Id, 0);
                    $this->rrmdir(BASE_PATH . 'files/' . $this->object_path . $this->Id, true);
                    $this->Msg->SetMsg($this->_T('success_item_deleted'));
                    $this->Redirect($this->PageUrl);
                }
                break;
            case 'add':
                $LanguageModel = Db_Language::getLanguageWithKey();
                $this->TPL->assign('LanguageModel', $LanguageModel);
                break;
            case 'save':
                if ($this->Id != 0) {
                    $this->CheckIdExist();
                }
                $c_priority = getPost('c_priority');
                $c_published = isset($_POST['c_published']) ? 1 : 0;
                $c_url = getPost('c_url');
                $ct_title = getPost('ct_title');
                //                Save data into OBJECT
                $Object = new Db_Category($this->DB, $this->Id, 'id');
                $Object->c_priority = $c_priority;
                $Object->c_published = $c_published;
                $Object->c_url = $c_url;
                $Object->save();
                //                Take id of $Object
                $id = $Object->id;
                //                Save trans values into $ObjectTrans
                foreach ($ct_title as $lang => $title) {
                    $ObjectTrans = new Db_CategoryTrans();
                    $ObjectTrans->findByFields(array('ct_category_id' => $id, 'ct_lang_id' => $lang));
                    $ObjectTrans->ct_title = $title;
                    $ObjectTrans->ct_category_id = $id;
                    $ObjectTrans->ct_lang_id = $lang;
                    $ObjectTrans->save();
                }
                $this->Msg->SetMsg($this->_T('success_item_saved'));
                $this->Redirect($this->PageUrl . '?action=view&id=' . $id);
                break;
            default:
                $Objects = Db_Category::getObjects();
                $ObjectsTrans = Db_CategoryTrans::getTransByLang($this->LangId);
                $ListGrid = false;
                if ($Objects) {
                    $ListGrid = new TGrid();
                    $ListGrid->Spacing = 0;
                    $ListGrid->Width = '100%';
                    $ListGrid->SetClass('table table-bordered table-highlight-head');
                    $ListGrid->AddHeaderRow($this->_T('id'), $this->_T('Title'), $this->_T('Url'), $this->_T('Priority'), $this->_T('Published'), $this->_T('actions'));
                    $ListGrid->BeginBody();
                    foreach ($Objects as $Object) {
                        $Grid_TR = new TGrid_TTR();
                        $Grid_TD = new TGrid_TTD($Object['id'] . ' (&nbsp;<a href="' . $this->PageUrl . '?action=view&id=' . $Object['id'] . '">' . $this->_T('see') . '</a>&nbsp;)');
                        $Grid_TR->Add($Grid_TD);
                        $Grid_TD = new TGrid_TTD($ObjectsTrans[$Object['id']]['ct_title']);
                        $Grid_TR->Add($Grid_TD);
                        $Grid_TD = new TGrid_TTD($Object['c_url']);
                        $Grid_TR->Add($Grid_TD);
                        $Grid_TD = new TGrid_TTD($Object['c_priority']);
                        $Grid_TR->Add($Grid_TD);
                        $Grid_TD = new TGrid_TTD($Object['c_published'] == 1 ? $this->_T('yes') : $this->_T('no'));
                        $Grid_TR->Add($Grid_TD);
                        $Grid_TD = new TGrid_TTD('
								<a class="bs-tooltip" title="" href="' . $this->PageUrl . '?action=edit&id=' . $Object['id'] . '" data-original-title="' . $this->_T('edit') . '"><i class="icon-pencil"></i></a>
								<a class="bs-tooltip confirm-dialog" data-text="' . _T('sure_you_want_to_delete') . '" title="" href="' . $this->PageUrl . '?action=delete&id=' . $Object['id'] . '" data-original-title="' . $this->_T('delete') . '"><i class="icon-trash"></i></a>
							');
                        $Grid_TD->AddAttr(new TAttr('class', 'align-center'));
                        $Grid_TR->Add($Grid_TD);
                        $ListGrid->AddTR($Grid_TR);
                    }
                    $ListGrid->EndBody();
                    $ListGrid = $ListGrid->Html();
                }
                $this->TPL->assign('ListGrid', $ListGrid);
                break;
        }
        $msg = $this->Msg->Html();
        $this->TPL->assign('msg', $msg);
        $this->TPL->assign('Action', $this->Action);
        $result = $this->TPL->display(null, true);
        $this->Msg->Clear();
        return $result;
    }