<?php
class Andy_SmilieCount_Model_Install
{
public static function install()
{
$db = XenForo_Application::get('db');
$db->query("
CREATE TABLE IF NOT EXISTS `andy_smilie_count` (
`max_smilie` int(10) unsigned NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
");
}
}
?>
<?php
class Andy_SmilieCount_Model_Install
{
public static function install()
{
$db = XenForo_Application::get('db');
$db->query("
CREATE TABLE IF NOT EXISTS `andy_smilie_count` (
`max_smilie` int(10) unsigned NOT NULL,
PRIMARY KEY (max_smilie)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
");
}
}
?>
$max_count = array();
$db = XenForo_Application::getDb();
return $db->fetchRow('SELECT max_smilie FROM andy_smilie_count WHERE max_smilie = ?', $max_count);
<?php
class Andy_SmilieCount_ControllerAdmin_Tools extends XenForo_ControllerAdmin_Tools
{
public function actionIndex()
{
// get data table andy_smilie_count
// !!! this does not work yet
$max_count = array();
$db = XenForo_Application::getDb();
return $db->fetchRow('SELECT max_smilie FROM andy_smilie_count WHERE max_smilie = ?', $max_count);
//return $this->responseError($max_count);
//$max_count = '5';
// display andy_smiliecount template
$viewParams = array('post' => $max_count);
return $this->responseView('Andy_ViewPublic_Post','andy_smiliecount',$viewParams);
}
public function actionSave()
{
// make sure data comes from $_POST
$this->_assertPostOnly();
// get new_post_date from overlay
$newSmilieCount = $this->_input->filterSingle('new_smilie_count', XenForo_Input::STRING);
//########################################
// save $newSmilieCount
//########################################
// response redirect
return $this->responseRedirect(
XenForo_ControllerResponse_Redirect::SUCCESS,
XenForo_Link::buildAdminLink('tools')
);
}
}
?>
<?php
class Andy_SmilieCount_ControllerAdmin_Tools extends XenForo_ControllerAdmin_Tools
{
public function actionIndex()
{
// get data from table andy_smilie_count
$db = XenForo_Application::getDb();
$viewParams = $db->fetchRow("select max_smilie from `andy_smilie_count`");
// pass $viewParams to template and display template
return $this->responseView('Andy_ViewPublic_Post','andy_smiliecount',$viewParams);
}
public function actionSave()
{
// make sure data comes from $_POST
$this->_assertPostOnly();
// get new_post_date from overlay
$newSmilieCount = $this->_input->filterSingle('new_smilie_count', XenForo_Input::STRING);
//########################################
// save $newSmilieCount
//########################################
// response redirect
return $this->responseRedirect(
XenForo_ControllerResponse_Redirect::SUCCESS,
XenForo_Link::buildAdminLink('tools')
);
}
}
?>
<xen:title>Smilie Count</xen:title>
<form action="{xen:adminlink 'smiliecount/save', $post}" method="post" class="xenForm AutoValidator" data-redirect="on">
<fieldset>
<dl class="ctrlUnit">
<dt><label>Enter maximum smilie count per post:</label></dt>
<dd><input type="text" name="new_smilie_count" size="10" value="{$max_smilie}" class="textCtrl titleCtrl"></dd>
</dl>
<dl class="ctrlUnit submitUnit">
<dt></dt>
<dd><input type="submit" value="Submit" class="button primary" accesskey="s" /></dd>
</dl>
</fieldset>
<input type="hidden" name="_xfToken" value="{$visitor.csrf_token_page}" />
</form>
<?php
class Andy_SmilieCount_ControllerAdmin_Tools extends XenForo_ControllerAdmin_Tools
{
public function actionIndex()
{
// get data from table andy_smilie_count
$db = XenForo_Application::getDb();
$viewParams = $db->fetchRow("select max_smilie from `andy_smilie_count`");
// pass $viewParams to template and display template
return $this->responseView('Andy_ViewPublic_Post','andy_smiliecount',$viewParams);
}
public function actionSave()
{
// make sure data comes from $_POST
$this->_assertPostOnly();
// get new_post_date from overlay
$newSmilieCount = $this->_input->filterSingle('new_smilie_count', XenForo_Input::STRING);
// save $newSmilieCount
$db = XenForo_Application::getDb();
$db->query("
UPDATE andy_smilie_count
SET max_smilie = '$newSmilieCount'
WHERE max_smilie <> ''
");
// response redirect
return $this->responseRedirect(
XenForo_ControllerResponse_Redirect::SUCCESS,
XenForo_Link::buildAdminLink('tools')
);
}
}
?>
However I need to move the UPDATE query to the Model in order to follow the proper xF framework.
$dw = XenForo_DataWriter::create('DATAWRITERCLASS');
if ($update)
{
$dw->setExistingData($existingData);
}
$dw->set('field', 'value');
$dw->save();
You put the path to your class in the datawriter.
Should be something along the lines of
Andy_Smilie_DataWriter_Count
$dw = XenForo_DataWriter::create('Andy_SmilieCount_DataWriter_UpdateTable');
if ($update)
{
$dw->setExistingData($existingData);
}
$dw->set('max_smilie', $newSmilieCount);
$dw->save();
No code event listener is needed, you aren't extending; you are making a new table, new datawriter, etc...
$dw = XenForo_DataWriter::create('Andy_SmilieCount_DataWriter_UpdateTable');
if ($update)
{
$dw->setExistingData($existingData);
}
$dw->set('max_smilie', $newSmilieCount);
$dw->save();
We use essential cookies to make this site work, and optional cookies to enhance your experience.