PageRenderTime 236ms CodeModel.GetById 121ms app.highlight 6ms RepoModel.GetById 107ms app.codeStats 0ms

/www/app/AdminModule/presenters/AdminOptionsPresenter.php

https://github.com/bazo/Mokuji
PHP | 102 lines | 87 code | 13 blank | 2 comment | 2 complexity | bcddeb7d216abd1361ace8945f42d836 MD5 | raw file
  1<?php
  2class Admin_OptionsPresenter extends Admin_SecurePresenter
  3{
  4	
  5	public function actionDefault()
  6	{
  7            $this->view = 'options';
  8	}
  9	
 10    public function actionAdvanced()
 11    {
 12            $this->view = 'advanced';
 13    }
 14    
 15	public function createComponentPageMetaInfo($name)
 16	{
 17            $page = new Page($this,$name);
 18            
 19            $item = $page->addItem("Tabs");
 20            $item->contentFactory = array($this,'createTabs');
 21            
 22            //Tab Meta Info
 23            $item = $page->addItem("metainfo");
 24            $item->contentFactory = array($this,'createTabMetaInfo');
 25	}
 26    
 27    public function createComponentPageAdvanced($name)
 28    {
 29            $page = new Page($this,$name);
 30            
 31            $item = $page->addItem("Tabs");
 32            $item->contentFactory = array($this,'createTabs');
 33            
 34            //Advanced
 35            $item = $page->addItem("advanced");
 36            $item->contentFactory = array($this,'createTabAdvanced');
 37    }
 38	
 39    public function createTabs($name, $page)
 40    {
 41        $params = $this->getRequest()->getParams();
 42        $action = $params['action'];
 43        $linkMeta = Html::el('a')->href($this->link('default'))->add(Html::el('span')->add('Options'));
 44        $linkAdvanced = Html::el('a')->href($this->link('advanced'))->add(Html::el('span')->add('Advanced'));
 45        $liMeta = Html::el('li')->class('ui-tabs-panel ui-widget-content ui-state-default ui-corner-top');
 46        $liAdvanced = Html::el('li')->class('ui-tabs-panel ui-widget-content ui-state-default ui-corner-top');
 47        if($action == 'advanced')
 48            $liAdvanced->class('ui-tabs-panel ui-widget-content ui-state-default ui-corner-top ui-tabs-selected ui-state-active'); 
 49        else
 50            $liMeta->class('ui-tabs-panel ui-widget-content ui-state-default ui-corner-top ui-tabs-selected ui-state-active');
 51        $tabs = Html::el('div')->class('tabs ui-tabs ui-widget ui-widget-content ui-corner-all')->add(Html::el('ul')->class('ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all')
 52            ->add($liMeta->add($linkMeta))
 53            ->add($liAdvanced->add($linkAdvanced))); 
 54        return $tabs;
 55    }
 56    
 57	public function createTabMetaInfo($name, $page)
 58	{
 59            $form = new LiveForm($page, $name);
 60            $data = ConfigAdapterIni::load(APP_DIR.'/config/site.ini', 'site');
 61            $form->addText("title", "Title");
 62            $form->addText("author", "Author");
 63            $form->addText("keywords", "Keywords");
 64            $form->addText("description", "Description");
 65            $form->addSubmit("odeslat", "Odeslat");
 66            $form->setDefaults($data);
 67            $form->onSubmit[] = array($this,"saveMetaData");
 68            return $form;
 69	}
 70	
 71	public function saveMetaData($form)
 72	{
 73            $values = $form->getValues();
 74            $data = ConfigAdapterIni::load(APP_DIR.'/config/site.ini', 'site');
 75            try{
 76                    foreach($values as $key => $value)
 77                    {
 78                            $data['key'] = $value;
 79                    }
 80                    $metaConfig = new Config();
 81                    $metaConfig->import($data);
 82                    $metaConfig->save(APP_DIR.'/config/site.ini', 'site');
 83                    $this->flash('Metadata saved');
 84            }
 85            catch(InvalidArgumentException $e )
 86            {
 87                    $this->flash($e->getMessage );
 88            }
 89	}
 90
 91        public function createTabAdvanced($name, $page)
 92	{
 93            return Html::el('a')->href($this->link('ClearCache!'))->class('ajax')->add('Clear cache!');
 94	}
 95
 96        public function handleClearCache()
 97        {
 98            Environment::getCache()->release();
 99            Environment::getCache()->clean(array(Cache::ALL => TRUE));
100        }
101}
102?>