Quote:
I don't understand your concern about additional queries. All it should take is adding something like $criteria->add(new Criteria('poll_mid', $poll_mid, '=')); to an existing query.
i think in any case a new field means more time/load in select, update , ... 1- in existing query we have to modify all existing queries. needs time. 2- sometimes we should add new query. If we use dirname or mid field we should drop config "poll_module" so sometimes we should recheck to find if poll_module is still exist or active. for example when i want to delete a poll after delete the topic. now i just write a standalone function.
public function deletePoll($poll_id)
{
if (empty($poll_id)) return false;
$module_handler = &xoops_gethandler('module');
$newbbConfig = newbb_load_config();
$pollModuleHandler =& $module_handler->getByDirname($newbbConfig["poll_module"]);
if (!is_object($pollModuleHandler) || !$pollModuleHandler->getVar('isactive')) return false;
// new xoopspoll module
if($pollModuleHandler->getVar("version") >= 140) {
$poll_handler =& xoops_getmodulehandler('poll', $newbbConfig["poll_module"]);
if (false !== $poll_handler->deleteAll(new Criteria('poll_id', $poll_id, '='))) {
$option_handler =& xoops_getmodulehandler('option', $newbbConfig["poll_module"]);
$option_handler->deleteAll(new Criteria('poll_id', $poll_id, '='));
$log_handler =& xoops_getmodulehandler('log', $newbbConfig["poll_module"]);
$log_handler->deleteAll(new Criteria('poll_id', $poll_id, '='));
xoops_comment_delete($GLOBALS['xoopsModule']->getVar('mid'), $poll_id);
}
// old xoopspoll or umfrage or any clone from them
} else {
$classPoll = $this->loadOldPoll();
$poll = new $classPoll($poll_id);
if ( $poll->delete() != false ) {
$classOption = $classPoll . "Option";
$classOption::deleteByPollId($poll->getVar("poll_id"));
$classLog = $classPoll . "Log";
$classLog::deleteByPollId($poll->getVar("poll_id"));
xoops_comment_delete($xoopsModule->getVar('mid'), $poll->getVar('poll_id'));
}
} // end poll_module new or old
return true;
}
but if we drop config i have to check the poll_module field. I think about dropping topic_haspoll field. this field is useless we can just have a poll_id. if poll_id > 0 => topic has a poll I dont understand why old developers add this field. Quote:
I'm not sure how this could be implemented effectively - but maybe you have some ideas.
for sure! see newbb/xoops_version.php
// START irmtfan add a poll_module config
$pollDirs = array();
$dir_def = 0;
// if in install, update
if($isModuleAction) {
$allDirs = xoops_getActiveModules();
foreach($allDirs as $dirname) {
// pollresults.php file is exist in all xoopspoll versions and umfrage versions
if(file_exists($GLOBALS['xoops']->path("modules/" . $dirname . "/pollresults.php"))) {
$pollDirs[$dirname] = $dirname;
}
}
// priorities for default poll module : 1- xoopspoll 2- last element in array 3- if no poll module => 0
$dir_def = !empty($pollDirs) ? (!empty($pollDirs["xoopspoll"]) ? $pollDirs["xoopspoll"] : end($pollDirs))
: 0;
}
$isPref = (
// action module "system"
is_object($GLOBALS["xoopsModule"]) && "system" == $GLOBALS["xoopsModule"]->getVar("dirname", "n")
&&
// current action
$_REQUEST['fct'] == "preferences"
);
// if in pref AND click on save AND 'poll_module' != 0
if($isPref && !empty($_POST['poll_module'])) {
$hModConfig = xoops_gethandler('config');
$criteria = new CriteriaCompo();
$criteria->add(new Criteria('conf_name', "poll_module", "="), "AND");
$criteria->add(new Criteria('conf_formtype', "select", "="), "AND"); // not hidden
$criteria->add(new Criteria('conf_id', "(" . implode(", ",$_POST['conf_ids']). ")", "IN"), "AND");
$pollOptions = $hModConfig->getConfigs($criteria);
$pollOptions = end($pollOptions);
if(is_object($pollOptions) && $pollOptions->getVar("conf_value") != "0") {
$topic_handler = xoops_getmodulehandler('topic', $modversion['dirname']);
$topicPolls = $topic_handler->getCount(new Criteria("topic_haspoll", 1));
if($topicPolls > 0) {
$pollOptions->setVar("conf_formtype", "hidden");
$result = $hModConfig->insertConfig($pollOptions);
if(!$result) {
//echo "error: poll_module is in danger!!!";
}
}
}
}
xoops_loadLanguage('admin', $modversion['dirname']);
$i = count($modversion['config']); // temporary until change the whole xoops_version config
$i++;
$modversion['config'][$i]['name'] = 'poll_module';
$modversion['config'][$i]['title'] = '_AM_NEWBB_POLLMODULE';
$modversion['config'][$i]['description'] = '_AM_NEWBB_POLLMODULE';
$modversion['config'][$i]['valuetype'] = 'text';
$modversion['config'][$i]['default'] = $dir_def;
if(count($pollDirs) <= 1) {
$modversion['config'][$i]['formtype'] = 'hidden';
} else {
$modversion['config'][$i]['formtype'] = 'select';
$modversion['config'][$i]['options'] = $pollDirs;
}
// END irmtfan add a poll_module config
and $isModuleAction is:
$isModuleAction = @(
// action module "system"
!empty($GLOBALS["xoopsModule"]) && "system" == $GLOBALS["xoopsModule"]->getVar("dirname", "n")
&&
// current dirname
($dirname == $_POST["dirname"] || $dirname == $_POST["module"])
&&
// current op
("update_ok" == $_POST["op"] || "install_ok" == $_POST["op"] || "uninstall_ok" == $_POST["op"])
&&
// current action
"modulesadmin" == $_POST["fct"]
);
That is reliable way. - in update and install it will check and add config. if there is just one poll the config will be hidden. if there is more than one poll module it will select with this priority: 1- xoopspoll 2- last element in array ps: we can leave all OnInstall, OnUpdate and OnUninstall functions and use this method. It will be very useful to make a module like xoopspoll clonable with a simple rename of dirname. even it will be possible to update a clone "blabla" using original "xoopspoll" - when user goes to pref and click on submit. it will check the "poll_module" config and find if there is a topic with poll. then it will hide the config. Note: currently it is not possible to find the poll module in newbb installations before most recent version (version 4.32) but we can add some guess to the above code. Quote:
if he still plans to actively develop newbb.
AFAIK Alfred continue developing newbb but some adding/dropping features are not acceptable for me. eg: he dropped the user moderation in forums and replace it with group moderation. It is very bad. I need to let one user to be a moderator in one forum without any additional group or permissions. Quote:
You could find the poll module(s) by looking for a 'signature' (file name, class, etc.) that is consistent between poll modules.
I used pollresults.php. it is consistent in all xoopspoll and umfrage versions and all current and future clones. do you have better idea? you used hard-code date() function in the current xoopspoll 1.4. do you want to consider using formatTimeStamp or better XoopsLocal::formatTimeStamp for formatted times in templates? in result forms you should use it. but in edit forms we still should add the hejira date in JQuery date time picker @redheadedrod: Quote:
What happens now if you remove the poll module? Does newbbs recognize this?
because newbb and all other poll modules are completely separated modules we cannot add many tight relations. but newbb will check the poll module existence every time wants to do something. but if somebody uninstall xoopspoll newbb will not understand it. (that is why zyspec add the functionality to xooppoll) I think xoopspoll will not understand whether newbb is uninstalled too