Exemple #1
0
 protected function getInput()
 {
     require_once JPATH_SITE . '/components/com_javoice/models/items.php';
     require_once JPATH_SITE . '/components/com_javoice/models/forums.php';
     $jaVoiceModelItems = new JAVoiceModelItems();
     $model_forums = new JAVoiceModelforums();
     $class = (string) $this->element['class'];
     $multiple = $this->element['multiple'] ? 'multiple="multiple"' : '';
     $types = $jaVoiceModelItems->getVoiceTypes(" AND vt.published = 1", "vt.ordering");
     $forums = array();
     $forums[0] = new stdClass();
     $forums[0]->id = '1';
     $forums[0]->title = JText::_("Select All");
     foreach ($types as $type) {
         array_push($forums, JHTML::_('select.optgroup', $type->title, 'id', 'title'));
         $where_more = ' and f.published=1 and ft.voice_types_id=' . $type->id;
         $join = 'INNER JOIN #__jav_forums_has_voice_types as ft ON f.id=ft.forums_id';
         $results = $model_forums->getItems($where_more, 100, 0, 'f.ordering', '', $join);
         //array_push($forums, $optgroup);
         foreach ($results as $result) {
             $result->id = $type->id . '_' . $result->id;
             array_push($forums, $result);
         }
         array_push($forums, JHTML::_('select.optgroup', $type->title, 'id', 'title'));
     }
     //jexit();
     $out = JHTML::_('select.genericlist', $forums, $this->name, 'class="inputbox ' . $class . '" ' . $multiple, 'id', 'title', $this->value);
     return $out;
 }
Exemple #2
0
 function parseItems(&$items, $types)
 {
     global $javconfig;
     $db = JFactory::getDBO();
     $array_votes = array();
     $user = JFactory::getUser();
     require_once JPATH_SITE . DS . 'components' . DS . 'com_javoice' . DS . 'models' . DS . 'forums.php';
     $model_forums = new JAVoiceModelforums();
     $array_votes = array();
     if ($types) {
         foreach ($types as $type) {
             $params_type = class_exists('JRegistry') ? new JRegistry($type->vote_option) : new JParameter($type->vote_option);
             $array_votes[$type->id]['value'] = $params_type->get('votes_value') ? str_replace("###", ',', $params_type->get('votes_value')) : '';
         }
     }
     if ($items) {
         require_once JPATH_SITE . DS . 'components' . DS . 'com_javoice' . DS . 'models' . DS . 'voicetypesstatus.php';
         $model_status = new javoiceModelvoicetypesstatus();
         foreach ($items as $k => $item) {
             $items[$k]->has_down = 0;
             $check = true;
             /* Check status has closed */
             if ($item->voice_type_status_id && $item->status_allow_voting == 0) {
                 $check = false;
             } elseif ($item->voice_type_status_id && $item->status_allow_voting == -1) {
                 $parent_status = $model_status->getItems(" and s.id='{$item->status_parent_id}' and s.published=1", '', 0, 1);
                 if ($parent_status) {
                     $parent_status = $parent_status[0];
                 }
                 if ($parent_status && $parent_status->allow_voting == 0) {
                     $check = false;
                 }
             }
             if ($check) {
                 $user_can_post = $user_can_view = 0;
                 $layout = JRequest::getVar('layout', '');
                 $forum = $model_forums->getItems(' and f.id=' . $item->forums_id);
                 if ($layout == "add" || $layout == "form") {
                     $forum = $forum[1];
                 } else {
                     $forum = $forum[0];
                 }
                 $forum->gids_post = str_replace("\n\n", "\n", $forum->gids_post);
                 $forum->gids_vote = str_replace("\n\n", "\n", $forum->gids_post);
                 $lits_user_can_posts = explode("\n", $forum->gids_post);
                 $lits_user_can_views = explode("\n", $forum->gids_view);
                 if (!$user->id) {
                     $user->groups = array_merge(array('Guest' => '0'), $user->groups);
                 }
                 foreach (array_values($user->groups) as $ugid) {
                     if (in_array($ugid, $lits_user_can_posts)) {
                         $user_can_post = 1;
                     }
                     if (in_array($ugid, $lits_user_can_views)) {
                         $user_can_view = 1;
                     }
                 }
                 if (!$user_can_view) {
                     unset($items[$k]);
                 } else {
                     if ($user_can_post && isset($array_votes[$item->voice_types_id]['value'])) {
                         $values = explode(',', $array_votes[$item->voice_types_id]['value']);
                         foreach ($values as $value) {
                             if (intval($value) < 0) {
                                 $items[$k]->has_down = 1;
                                 break;
                             }
                         }
                     }
                 }
             }
         }
     }
 }