<?php
class CF_Directory_ControllerAdmin_Directory extends XenForo_ControllerAdmin_Abstract
{
protected function _preDispatch($action)
{
$this->assertAdminPermission('cfDirectory');
}
/**
*
* @return XenForo_ControllerResponse_View
*/
public function actionIndex()
{
$pageModel = $this->_getPageModel();
$viewParams = array(
'pages' => $pageModel->getAllPages()
);
return $this->responseView('CF_Directory_ViewAdmin_Page_List', 'cf_directory_pages_list', $viewParams);
}
/**
* Presents form for editing a page.
*
* @return XenForo_ControllerResponse_Error|XenForo_ControllerResponse_View
*/
public function actionEdit()
{
$pageId = $this->_input->filterSingle('page_id', XenForo_Input::UINT);
$viewParams = array(
'page' => XenForo_Model::create('CF_Directory_Model_Page')->getPageById($pageId)
);
return $this->responseView('CF_Directory_ViewAdmin_Page_Add', 'cf_directory_page_add', $viewParams);
}
/**
* Presents form for adding a new page.
*
* @return XenForo_ControllerResponse_View
*/
public function actionAdd()
{
$viewParams = array(
'page' => array(
'title' => '',
'description' => '',
'category_id' => 0,
'display_order' => 1,
'route' => ''
)
);
return $this->responseView('CF_Directory_ViewAdmin_Page_Add', 'cf_directory_page_add', $viewParams);
}
public function actionSave()
{
$this->_assertPostOnly();
$input = $this->_input->filter(array(
'route' => XenForo_Input::STRING,
'display_order' => XenForo_Input::UINT
));
$pageId = $this->_input->filterSingle('page_id', XenForo_Input::UINT);
$pageWriter = XenForo_DataWriter::create('CF_Directory_DataWriter_Page');
if ($pageId) {
$pageWriter->setExistingData($pageId);
}
$pageWriter->bulkSet($input);
$pageWriter->save();
$lastPage = $pageWriter->getMergedData();
$data = array(
'title' => 'cf_directory_page_' . $lastPage['page_id'],
'language_id' => 0,
'global_cache' => 0,
'addon_id' => 'CFDirectory'
);
$writer = XenForo_DataWriter::create('XenForo_DataWriter_Phrase');
if ($pageId) {
$phrases = XenForo_Model::create('XenForo_Model_Phrase')->getPhraseIdInLanguagesByTitle($data['title']);
$writer->setExistingData($phrases[0], true);
}
$writer->set('phrase_text', $this->_input->filterSingle('title', XenForo_Input::STRING));
if (!$pageId) {
$writer->bulkSet($data);
}
$writer->save();
$writer = XenForo_DataWriter::create('XenForo_DataWriter_Template');
if ($pageId) {
$template_id = XenForo_Model::create('XenForo_Model_Template')->getTemplateInStyleByTitle('cf_directory_page.' . $lastPage['page_id']);
$writer->setExistingData($template_id);
} else {
$writer->set('title', 'cf_directory_page.' . $lastPage['page_id']);
$writer->set('style_id', 0);
$writer->set('addon_id', 'CFDirectory');
}
$writer->set('template', $this->_input->filterSingle('template', XenForo_Input::STRING));
$writer->save();
return $this->responseRedirect(
XenForo_ControllerResponse_Redirect::SUCCESS,
XenForo_Link::buildAdminLink('directory')
);
}
/**
* Deletes a page.
*
* @return XenForo_ControllerResponse_Redirect|XenForo_ControllerResponse_View
*/
public function actionDelete()
{
$pageId = $this->_input->filterSingle('page_id', XenForo_Input::INT);
if ($this->isConfirmedPost()) {
$pageWriter = XenForo_DataWriter::create('CF_Directory_DataWriter_Page');
$pageWriter->setExistingData($pageId);
$pageWriter->delete();
return $this->responseRedirect(
XenForo_ControllerResponse_Redirect::SUCCESS,
XenForo_Link::buildAdminLink('directory')
);
} else {
return $this->responseReroute('CF_Directory_ControllerAdmin_Directory', 'deleteConfirm');
}
}
public function actionDeleteConfirm() {
$pageId = $this->_input->filterSingle('page_id', XenForo_Input::INT);
$viewParams = array(
'page' => $this->_getPageModel()->getPageById($pageId)
);
return $this->responseView('XenForo_ViewAdmin_Page_Delete', 'cf_directory_page_delete', $viewParams);
}
/**
* @return CF_Directory_Model_Page
*/
protected function _getPageModel()
{
return $this->getModelFromCache('CF_Directory_Model_Page');
}
}
?>