public function save() { $app = JFactory::getApplication(); $model = $this->getModel('badges'); $ruleId = $app->input->post->getInt('ruleId', 0); $userId = $app->input->post->getInt('userId', 0); if ($ruleId && $userId) { $return = $model->get_badge_rules(); $badgeRules = !empty($return->rules) ? $return->rules : array(); if (!empty($badgeRules)) { $selectedRule = null; foreach ($badgeRules as $badgeRule) { if ($badgeRule->id == $ruleId) { $selectedRule = $badgeRule; break; } } if ($selectedRule && $selectedRule->rule_content) { $ruleContent = json_decode($selectedRule->rule_content); if (!empty($ruleContent->rules)) { $params = array(); foreach ($ruleContent->rules as $rule) { $params[$rule->name] = $app->input->post->get($rule->name, null, $rule->dataType); } CjBlogApi::trigger_badge_rule($selectedRule->rule_name, $params, $userId); $this->setRedirect(JRoute::_('index.php?option=' . CJBLOG . '&view=badgeactivity', false), JText::_('COM_CJBLOG_SUCCESS')); return; } } } } $this->setRedirect(JRoute::_('index.php?option=' . CJBLOG . '&view=badgeactivity&task=add', false), JText::_('COM_CJBLOG_ERROR_PROCESSING')); }
public function onContentChangeState($context, $pks, $value) { if ($context != 'com_content.article') { return true; } $api = JPATH_ROOT . '/components/com_cjblog/api.php'; if (file_exists($api)) { $db = JFactory::getDbo(); JArrayHelper::toInteger($pks); $query = ' select count(*) as articles, created_by from #__content where created_by in (select created_by from #__content where id in (' . implode(',', $pks) . ')) and state = 1 group by created_by'; $db->setQuery($query); $contents = $db->loadObjectList(); if (count($contents) > 0) { require_once $api; foreach ($contents as $content) { CjBlogApi::trigger_badge_rule('com_content.num_articles', array('num_articles' => $content->articles), $content->created_by); $query = 'update #__cjblog_users set num_articles = ' . $content->articles . ' where id = ' . $content->created_by; $db->setQuery($query); $db->query(); } } } else { die('CjBlog component is not installed.'); } }