function display($tpl = null)
 {
     $cid = JRequest::getVar('cid', array(0), '', 'array');
     $id = intval($cid[0]);
     $db =& JFactory::getDBO();
     $acl = JFactory::getACL();
     $query = "SELECT id, name FROM #__groups WHERE id = {$id}";
     $db->setQuery($query);
     $row = $db->loadObject();
     $query = "SELECT id_group FROM #__noixacl_groups_level WHERE id_levels like '%{$id}%'";
     $db->setQuery($query);
     $rowGroups = $db->loadObjectList();
     $levelGroups = JArrayHelper::getColumn($rowGroups, 'id_group');
     /**
      * get groups
      */
     $aclGroups = $acl->sort_groups();
     /**
      * format groups
      */
     $groups = $acl->format_groups($aclGroups, 'html', 28);
     $this->assignRef('accesslevel', $row);
     $this->assignRef('levelGroups', $levelGroups);
     $this->assignRef('groups', $groups);
     $text = !$cid[0] ? JText::_('NOIXACL_VIEW_ACCESSLEVEL_TEXT_EDIT') : JText::_('NOIXACL_VIEW_ACCESSLEVEL_TEXT_NEW');
     JToolBarHelper::title(JText::_('NOIXACL_VIEW_ACCESSLEVEL_TEXT_GROUP') . ': <small><small>[ ' . $text . ' ]</small></small>', 'user.png');
     JToolBarHelper::save();
     JToolBarHelper::apply();
     JToolBarHelper::cancel();
     parent::display($tpl);
 }
 /**
  * Method to get an array of data items.
  *
  * @return    mixed    An array of data items on success, false on failure.
  */
 public function getItems()
 {
     // Get a storage key.
     $store = $this->getStoreId();
     // Try to load the data from internal storage.
     if (isset($this->cache[$store])) {
         return $this->cache[$store];
     }
     // Load the list items.
     $query = $this->_getListQuery();
     try {
         $count = (int) $this->getState('list.count_elements');
         $items = $this->_getList($query, $this->getStart(), $this->getState('list.limit'));
         if ($count) {
             $pks = JArrayHelper::getColumn($items, 'id');
             $elements = $this->getElementCount($pks);
         }
         foreach ($items as $item) {
             $item->element_count = $count ? $elements[$item->id] : 0;
             $item->orphaned = empty($item->project_exists);
         }
     } catch (RuntimeException $e) {
         $this->setError($e->getMessage());
         return false;
     }
     // Add the items to the internal cache.
     $this->cache[$store] = $items;
     return $this->cache[$store];
 }
 /**
  * Method to get an array of data items.
  *
  * @return    mixed    An array of data items on success, false on failure.
  */
 public function getItems()
 {
     // Get a storage key.
     $store = $this->getStoreId();
     // Try to load the data from internal storage.
     if (isset($this->cache[$store])) {
         return $this->cache[$store];
     }
     // Load the list items.
     $query = $this->_getListQuery();
     try {
         $items = $this->_getList($query, 0, 0);
         $pks = JArrayHelper::getColumn($items, 'id');
         $elements = $this->getRevisionCount($pks);
         foreach ($items as $item) {
             $item->revision_count = $elements[$item->id];
         }
     } catch (RuntimeException $e) {
         $this->setError($e->getMessage());
         return false;
     }
     // Add the items to the internal cache.
     $this->cache[$store] = $items;
     return $this->cache[$store];
 }
Beispiel #4
0
 /**
  * Overrides the getItems method to attach additional metrics to the list.
  *
  * @return  mixed  An array of data items on success, false on failure.
  *
  * @since   1.6.1
  */
 public function getItems()
 {
     // Get a storage key.
     $store = $this->getStoreId('getItems');
     // Try to load the data from internal storage.
     if (!empty($this->cache[$store])) {
         return $this->cache[$store];
     }
     // Load the list items.
     $items = parent::getItems();
     // If emtpy or an error, just return.
     if (empty($items)) {
         return array();
     }
     // Getting the following metric by joins is WAY TOO SLOW.
     // Faster to do three queries for very large menu trees.
     // Get the menu types of menus in the list.
     $db = $this->getDbo();
     $menuTypes = JArrayHelper::getColumn($items, 'menutype');
     // Quote the strings.
     $menuTypes = implode(',', array_map(array($db, 'quote'), $menuTypes));
     // Get the published menu counts.
     $query = $db->getQuery(true)->select('m.menutype, COUNT(DISTINCT m.id) AS count_published')->from('#__menu AS m')->where('m.published = 1')->where('m.menutype IN (' . $menuTypes . ')')->group('m.menutype');
     $db->setQuery($query);
     try {
         $countPublished = $db->loadAssocList('menutype', 'count_published');
     } catch (RuntimeException $e) {
         $this->setError($e->getMessage());
         return false;
     }
     // Get the unpublished menu counts.
     $query->clear('where')->where('m.published = 0')->where('m.menutype IN (' . $menuTypes . ')');
     $db->setQuery($query);
     try {
         $countUnpublished = $db->loadAssocList('menutype', 'count_published');
     } catch (RuntimeException $e) {
         $this->setError($e->getMessage());
         return false;
     }
     // Get the trashed menu counts.
     $query->clear('where')->where('m.published = -2')->where('m.menutype IN (' . $menuTypes . ')');
     $db->setQuery($query);
     try {
         $countTrashed = $db->loadAssocList('menutype', 'count_published');
     } catch (RuntimeException $e) {
         $this->setError($e->getMessage);
         return false;
     }
     // Inject the values back into the array.
     foreach ($items as $item) {
         $item->count_published = isset($countPublished[$item->menutype]) ? $countPublished[$item->menutype] : 0;
         $item->count_unpublished = isset($countUnpublished[$item->menutype]) ? $countUnpublished[$item->menutype] : 0;
         $item->count_trashed = isset($countTrashed[$item->menutype]) ? $countTrashed[$item->menutype] : 0;
     }
     // Add the items to the internal cache.
     $this->cache[$store] = $items;
     return $this->cache[$store];
 }
 public function getItems()
 {
     if (!$this->pid) {
         return array();
     }
     $user = JFactory::getUser();
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     $nd = $db->getNullDate();
     $query->select('a.id, a.milestone_id, a.title, a.created')->select('m.start_date AS m_start, m.end_date AS m_end')->from('#__pf_task_lists AS a')->join('LEFT', '#__pf_projects AS p ON p.id = a.project_id')->join('LEFT', '#__pf_milestones AS m ON m.id = a.milestone_id')->where('a.project_id = ' . $this->pid)->where('a.state != -2');
     // Filter access
     if (!$user->authorise('core.admin')) {
         $query->where('a.access IN(' . implode(', ', $user->getAuthorisedViewLevels()) . ')');
     }
     $query->order('a.id ASC');
     $db->setQuery($query);
     $data = $db->loadObjectList();
     if (!is_array($data)) {
         return array();
     }
     // Prepare data
     $datas = array();
     $keys = JArrayHelper::getColumn($data, 'id');
     $completed = $this->getCompleted($keys);
     foreach ($data as $i => $item) {
         // Set dates
         $item->start_date = $this->getStartDate($item->id, $item->milestone_id, $item->m_start);
         $item->end_date = $this->getEndDate($item->id, $item->milestone_id, $item->m_end);
         // Skip item if no start or end is set
         if ($item->start_date == $nd || $item->end_date == $nd) {
             continue;
         }
         $item->complete = $completed[$item->id];
         $item->start_time = floor(strtotime($item->start_date) / 86400) * 86400;
         $item->end_time = floor(strtotime($item->end_date) / 86400) * 86400;
         $start_date = new JDate($item->start_date);
         $end_date = new JDate($item->end_date);
         $item->start_date = $start_date->format('Y-m-d H:i:s');
         $item->end_date = $end_date->format('Y-m-d H:i:s');
         $item->duration = $item->end_time - $item->start_time;
         $duration = strtotime($item->end_date) - strtotime($item->start_date);
         $item->fduration = $this->time2string($duration);
         $item->type = 'tasklist';
         if (!isset($datas[$item->start_time])) {
             $datas[$item->start_time] = array();
         }
         $datas[$item->start_time][] = $item;
     }
     ksort($datas, SORT_NUMERIC);
     $items = array();
     foreach ($datas as $key => $vals) {
         foreach ($vals as $val) {
             $items[] = $val;
         }
     }
     return $items;
 }
 /**
  * Method to get a list of items.
  * Overriden to inject convert the attribs field into a JParameter object.
  *
  * @return    mixed    $items    An array of objects on success, false on failure.
  */
 public function getItems()
 {
     $items = parent::getItems();
     $base_path = JPATH_ROOT . '/media/com_projectfork/repo/0/logo';
     $base_url = JURI::root(true) . '/media/com_projectfork/repo/0/logo';
     $tasks_exists = PFApplicationHelper::enabled('com_pftasks');
     $repo_exists = PFApplicationHelper::enabled('com_pfrepo');
     $pks = JArrayHelper::getColumn($items, 'id');
     // Get aggregate data
     $progress = array();
     $total_tasks = array();
     $completed_tasks = array();
     $total_files = array();
     if ($tasks_exists) {
         JLoader::register('PFtasksModelTasks', JPATH_SITE . '/components/com_pftasks/models/tasks.php');
         $tmodel = JModelLegacy::getInstance('Tasks', 'PFtasksModel', array('ignore_request' => true));
         $progress = $tmodel->getAggregatedProgress($pks, 'project_id');
         $total_tasks = $tmodel->getAggregatedTotal($pks, 'project_id');
         $completed_tasks = $tmodel->getAggregatedTotal($pks, 'project_id', 1);
     }
     if ($repo_exists) {
         JLoader::register('PFrepoModelFiles', JPATH_SITE . '/components/com_pfrepo/models/files.php');
         $fmodel = JModelLegacy::getInstance('Files', 'PFrepoModel', array('ignore_request' => true));
         $total_files = $fmodel->getProjectCount($pks);
     }
     // Loop over each row to inject data
     foreach ($items as $i => &$item) {
         $params = new JRegistry();
         $params->loadString($item->attribs);
         // Convert the parameter fields into objects.
         $items[$i]->params = clone $this->getState('params');
         // Create slug
         $items[$i]->slug = $items[$i]->alias ? $items[$i]->id . ':' . $items[$i]->alias : $items[$i]->id;
         // Try to find the logo img
         $items[$i]->logo_img = null;
         if (JFile::exists($base_path . '/' . $item->id . '.jpg')) {
             $items[$i]->logo_img = $base_url . '/' . $item->id . '.jpg';
         } elseif (JFile::exists($base_path . '/' . $item->id . '.jpeg')) {
             $items[$i]->logo_img = $base_url . '/' . $item->id . '.jpeg';
         } elseif (JFile::exists($base_path . '/' . $item->id . '.png')) {
             $items[$i]->logo_img = $base_url . '/' . $item->id . '.png';
         } elseif (JFile::exists($base_path . '/' . $item->id . '.gif')) {
             $items[$i]->logo_img = $base_url . '/' . $item->id . '.gif';
         }
         // Inject task count
         $items[$i]->tasks = isset($total_tasks[$item->id]) ? $total_tasks[$item->id] : 0;
         // Inject completed task count
         $items[$i]->completed_tasks = isset($completed_tasks[$item->id]) ? $completed_tasks[$item->id] : 0;
         // Inject progress
         $items[$i]->progress = isset($progress[$item->id]) ? $progress[$item->id] : 0;
         // Inject attached files
         $items[$i]->attachments = isset($total_files[$item->id]) ? $total_files[$item->id] : 0;
     }
     return $items;
 }
 /**
  * Method to get an array of data items.
  *
  * @return    mixed    An array of data items on success, false on failure.
  */
 public function getItems()
 {
     // Get a storage key.
     $store = $this->getStoreId();
     // Try to load the data from internal storage.
     if (isset($this->cache[$store])) {
         return $this->cache[$store];
     }
     // Load the items
     $items = array();
     $count = (int) $this->getState('list.count_elements');
     $parent = (int) $this->getState('filter.parent_id', 1);
     $dir = $this->getInstance('Directory', 'PFrepoModel', $config = array('ignore_request' => true));
     if ($parent == 1) {
         // Load the list items.
         $query = $this->_getListQuery();
         try {
             $items['directory'] = $dir->getItem($parent);
             $items['directories'] = $this->_getList($query, $this->getStart(), $this->getState('list.limit'));
             $items['notes'] = array();
             $items['files'] = array();
             if ($count) {
                 $pks = JArrayHelper::getColumn($items['directories'], 'id');
                 $elements = $this->getElementCount($pks);
             }
             foreach ($items['directories'] as $item) {
                 $item->element_count = $count ? $elements[$item->id] : 0;
                 $item->orphaned = empty($item->project_exists);
             }
         } catch (RuntimeException $e) {
             $this->setError($e->getMessage());
             return false;
         }
     } else {
         // Get the models
         $dirs = $this->getInstance('Directories', 'PFrepoModel', $config = array());
         $notes = $this->getInstance('Notes', 'PFrepoModel', $config = array());
         $files = $this->getInstance('Files', 'PFrepoModel', $config = array());
         // Get the data
         try {
             $items['directory'] = $dir->getItem($parent);
             $items['directories'] = $dirs->getItems();
             $items['notes'] = $notes->getItems();
             $items['files'] = $files->getItems();
         } catch (RuntimeException $e) {
             $this->setError($e->getMessage());
             return false;
         }
     }
     // Add the items to the internal cache.
     $this->cache[$store] = $items;
     return $this->cache[$store];
 }
Beispiel #8
0
 public function generateLayout(&$article, &$params, $dispatcher)
 {
     if ($template = TZ_Portfolio_PlusTemplate::getTemplate(true)) {
         $tplparams = $template->params;
         if ($tplparams->get('use_single_layout_builder', 1)) {
             $core_types = TZ_Portfolio_PlusPluginHelper::getCoreContentTypes();
             $this->core_types = JArrayHelper::getColumn($core_types, 'value');
             $this->_generateLayout($article, $params, $dispatcher);
             return $this->generateLayout;
         }
     }
     return false;
 }
 /**
  * Method to display a search view.
  *
  * @return  JController		This object to support chaining.
  *
  * @since   1.5
  */
 public function search()
 {
     $sphinx_search_model = $this->getModel('Search', 'CatalogueModel');
     $result = $sphinx_search_model->getItems();
     $app = JFactory::getApplication('site');
     $jinput = $app->input;
     $category_id = $jinput->get('cid');
     $ids = JArrayHelper::getColumn($result, 'id');
     $app->setUserState('com_catalogue.category.' . $category_id . '.filter.sphinx_ids', $ids);
     /*
      * $result = array('result' => array('total' => count($ids)));
      * echo json_encode($result);
      * $app->close();
      */
     $this->display();
 }
Beispiel #10
0
 public static function getContentTypes()
 {
     if ($core_types = self::getCoreContentTypes()) {
         $types = JArrayHelper::getColumn($core_types, 'value');
         $includeTypes = $core_types;
         $dispatcher = JEventDispatcher::getInstance();
         if ($contentPlugins = self::importPlugin('content')) {
             if ($pluginTypes = $dispatcher->trigger('onAddContentType')) {
                 foreach ($pluginTypes as $i => $plgType) {
                     if (is_array($plgType) && count($plgType)) {
                         foreach ($plgType as $j => $type) {
                             if (in_array($type->value, $types)) {
                                 unset($pluginTypes[$i][$j]);
                             }
                         }
                     } else {
                         if (in_array($plgType->value, $types)) {
                             unset($pluginTypes[$i]);
                         }
                     }
                 }
                 $includeTypes = array_merge($includeTypes, $pluginTypes);
                 return $includeTypes;
             }
         }
         return $core_types;
     }
     return false;
 }
Beispiel #11
0
 /**
  * get query to make records
  *
  * @return  string	sql
  */
 public function buildQuery()
 {
     $profiler = JProfiler::getInstance('Application');
     $input = $this->app->input;
     JDEBUG ? $profiler->mark('buildQuery: start') : null;
     $db = $this->getDb();
     $query = $db->getQuery(true);
     $table = $this->getTable();
     if ($this->mergeJoinedData()) {
         /* $$$ rob - get a list of the main table's ids limited on the navigation
          * this will then be used to filter the main query,
          * by modifying the where part of the query
          */
         $db = $this->getDb();
         $table = $this->getTable();
         /* $$$ rob 23/05/2012 if the search data is in the joined records we want to get the id's for the joined records and not the master record
         			 see http://fabrikar.com/forums/showthread.php?t=26400. This is a partial hack as I can't see how we know which joined record is really last
         			$$$ rob 25/05/2012 - slight change so that we work our way up the pk/fk list until we find some ids.
         			$$$ hugh, later in the day 25/05/2012 - big OOOOPS, see comment below about table_key vs table_join_key!
         			erm no not a mistake!?! reverted as no example of what was wrong with original code
         			*/
         $joins = $this->getJoins();
         // Default to the primary key as before this fix
         $lookupC = 0;
         $tmpPks = array();
         foreach ($joins as $join) {
             // $$$ hugh - added repeatElement, as _makeJoinAliases() is going to set canUse to false for those,
             // so they won't get included in the query ... so will blow up if we reference them with __pk_calX selection
             if ($join->params->get('type') !== 'element' && $join->params->get('type') !== 'repeatElement') {
                 // $$$ hugh - need to be $lookupC + 1, otherwise we end up with two 0's, 'cos we added main table above
                 /**
                  * [non-merged data]
                  *
                  * country	towm
                  * ------------------------------
                  * france	la rochelle
                  * france	paris
                  * france	bordeaux
                  *
                  * [merged data]
                  *
                  * country	town
                  * -------------------------------
                  * france	la rochelle
                  * 			paris
                  * 			bordeaux
                  *
                  * [now search on town = 'la rochelle']
                  *
                  * If we don't use this new code then the search results show all three towns.
                  * By getting the lowest set of complete primary keys (in this example the town ids) we set our query to be:
                  *
                  * where town_id IN (1)
                  *
                  * which gives a search result of
                  *
                  * country	town
                  * -------------------------------
                  * france	la rochelle
                  *
                  */
                 $pk = $join->params->get('pk');
                 if (!array_key_exists($pk, $tmpPks) || !is_array($tmpPks[$pk])) {
                     $tmpPks[$pk] = array($pk);
                 } else {
                     if (count($tmpPks[$pk]) == 1) {
                         $v = str_replace('`', '', $tmpPks[$pk][0]);
                         $v = explode('.', $v);
                         $v[0] = $v[0] . '_0';
                         $tmpPks[$pk][0] = $db->qn($v[0] . '.' . $v[1]);
                     }
                     $v = str_replace('`', '', $pk);
                     $v = explode('.', $v);
                     $v[0] = $v[0] . '_' . count($tmpPks[$pk]);
                     $tmpPks[$pk][] = $db->qn($v[0] . '.' . $v[1]);
                 }
             }
         }
         // Check for duplicate pks if so we can presume that they are aliased with _X in from query
         $lookupC = 0;
         $lookUps = array('DISTINCT ' . $table->db_primary_key . ' AS __pk_val' . $lookupC);
         $lookUpNames = array($table->db_primary_key);
         foreach ($tmpPks as $pks) {
             foreach ($pks as $pk) {
                 $lookUps[] = $pk . ' AS __pk_val' . ($lookupC + 1);
                 $lookUpNames[] = $pk;
                 $lookupC++;
             }
         }
         // $$$ rob if no ordering applied i had results where main record (e.g. UK) was shown in 2 lines not next to each other
         // causing them not to be merged and a 6 rows shown when limit set to 5. So below, if no order by set then order by main pk asc
         $by = trim($table->order_by) === '' ? array() : (array) json_decode($table->order_by);
         if (empty($by)) {
             $dir = (array) json_decode($table->order_dir);
             array_unshift($dir, 'ASC');
             $table->order_dir = json_encode($dir);
             $by = (array) json_decode($table->order_by);
             array_unshift($by, $table->db_primary_key);
             $table->order_by = json_encode($by);
         }
         // $$$ rob build order first so that we know of any elements we need to include in the select statement
         $query = $this->buildQueryOrder($query);
         $this->selectedOrderFields = (array) $this->selectedOrderFields;
         $this->selectedOrderFields = array_unique(array_merge($lookUps, $this->selectedOrderFields));
         $query->select(implode(', ', $this->selectedOrderFields) . ' FROM ' . $db->qn($table->db_table_name));
         $query = $this->buildQueryJoin($query);
         $query = $this->buildQueryWhere($input->get('incfilters', 1), $query);
         $query = $this->buildQueryGroupBy($query);
         // Can't limit the query here as this gives incorrect _data array.
         // $db->setQuery($query, $this->limitStart, $this->limitLength);
         $db->setQuery($query);
         FabrikHelperHTML::debug((string) $query, 'table:mergeJoinedData get ids');
         $ids = array();
         $idRows = $db->loadObjectList();
         $maxPossibleIds = count($idRows);
         // An array of the lists pk values
         $mainKeys = array();
         foreach ($idRows as $r) {
             $mainKeys[] = $db->q($r->__pk_val0);
         }
         // Chop up main keys for list limitstart, length to cull the data down to the correct length as defined by the page nav/ list settings
         $mainKeys = array_unique($mainKeys);
         if ($this->limitLength > 0) {
             $mainKeys = array_slice($mainKeys, $this->limitStart, $this->limitLength);
         }
         /**
          * $$$ rob get an array containing the PRIMARY key values for each joined tables data.
          * Stop as soon as we have a set of ids totaling the sum of records contained in $idRows
          */
         while (count($ids) < $maxPossibleIds && $lookupC >= 0) {
             $ids = JArrayHelper::getColumn($idRows, '__pk_val' . $lookupC);
             for ($idx = count($ids) - 1; $idx >= 0; $idx--) {
                 if ($ids[$idx] == '') {
                     unset($ids[$idx]);
                 } else {
                     $ids[$idx] = $db->q($ids[$idx]);
                 }
             }
             if (count($ids) < $maxPossibleIds) {
                 $lookupC--;
             }
         }
     }
     // Now lets actually construct the query that will get the required records:
     $query->clear();
     unset($this->orderBy);
     $query = $this->buildQuerySelect('list', $query);
     JDEBUG ? $profiler->mark('queryselect: got') : null;
     $query = $this->buildQueryJoin($query);
     JDEBUG ? $profiler->mark('queryjoin: got') : null;
     if ($this->mergeJoinedData()) {
         /* $$$ rob We've already used buildQueryWhere to get our list of main pk ids.
          * so lets use that list of ids to create the where statement. This will return 5/10/20 etc
          * records from our main table, as per our page nav, even if a main record has 3 rows of joined
          * data. If no ids found then do where "2 = -2" to return no records (was "1 = -1", changed to make
          * it easier to know where this is coming form when debugging)
          */
         if (!empty($ids)) {
             if ($lookUpNames[$lookupC] !== $table->db_primary_key) {
                 $query->where($lookUpNames[$lookupC] . ' IN (' . implode(array_unique($ids), ',') . ')');
             }
             if (!empty($mainKeys)) {
                 // Limit to the current page
                 $query->where($table->db_primary_key . ' IN (' . implode($mainKeys, ',') . ')');
             } else {
                 $query->where('2 = -2');
             }
         } else {
             $query->where('2 = -2');
         }
     } else {
         // $$$ rob we aren't merging joined records so lets just add the standard where query
         // Incfilters set when exporting as CSV
         $query = $this->buildQueryWhere($input->get('incfilters', 1), $query);
     }
     $query = $this->buildQueryGroupBy($query);
     $query = $this->buildQueryOrder($query);
     $query = $this->pluginQuery($query);
     $this->mainQuery = $query;
     /*
     $params = $this->getParams();
     
     if ($params->get('force_collate', '') !== '')
     {
     	$query .= ' COLLATE ' . $params->get('force_collate', '') . ' ';
     }
     */
     return (string) $query;
 }
 public function onSaveArticleFieldValue($value)
 {
     if (!$this->article_id) {
         return false;
     }
     $_value = $this->prepareFieldValue($value);
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     $result = true;
     $table_name = '#__tz_portfolio_plus_field_content_map';
     $query->select('m.*');
     $query->from($table_name . ' AS m');
     $query->where('m.fieldsid = ' . $this->id);
     $query->where('m.contentid = ' . $this->article_id);
     $db->setQuery($query);
     $countData = $db->loadResult();
     if ($countData > 0) {
         if ($groupid = TZ_Portfolio_PlusFrontHelperExtraFields::getFieldGroupsByArticleId($this->article_id)) {
             $groupid = JArrayHelper::getColumn($groupid, 'id');
             if (count($groupid)) {
                 $query->join('INNER', '#__tz_portfolio_plus_field_fieldgroup_map AS fm ON fm.fieldsid = m.fieldsid');
                 $query->where('fm.groupid IN(' . implode(',', $groupid) . ')');
             }
         }
         $db->setQuery($query);
         $countGData = $db->loadResult();
         $query->clear();
         if ($_value !== "" && !is_null($_value) && $countGData > 0) {
             $query->update($table_name);
             $query->set('value = ' . $db->quote($_value));
             $query->where('fieldsid = ' . $this->id);
             $query->where('contentid = ' . $this->article_id);
             $db->setQuery($query);
             $result = $db->execute();
         } else {
             $query->delete($table_name);
             $query->where('fieldsid = ' . $this->id);
             $query->where('contentid = ' . $this->article_id);
             $db->setQuery($query);
             $result = $db->execute();
         }
     } else {
         if ($_value !== "" && !is_null($_value)) {
             $query->clear();
             $query->insert($table_name);
             $query->columns('fieldsid, contentid, value, ordering');
             $query->values($this->id . ',' . $this->article_id . ',' . $db->quote($_value) . ', 0');
             $db->setQuery($query);
             $result = $db->execute();
         }
     }
     return $result;
 }
Beispiel #13
0
 /**
  * Method to get a list of items.
  * Overriden to inject convert the attribs field into a JParameter object.
  *
  * @return    mixed    $items    An array of objects on success, false on failure.
  */
 public function getItems()
 {
     $items = parent::getItems();
     $labels = $this->getInstance('Labels', 'PFModel');
     $tasks_exists = PFApplicationHelper::enabled('com_pftasks');
     $pks = JArrayHelper::getColumn($items, 'id');
     // Get aggregate data
     $progress = array();
     $total_tasks = array();
     $completed_tasks = array();
     if ($tasks_exists) {
         JLoader::register('PFtasksModelTasks', JPATH_SITE . '/components/com_pftasks/models/tasks.php');
         $tmodel = JModelLegacy::getInstance('Tasks', 'PFtasksModel', array('ignore_request' => true));
         $progress = $tmodel->getAggregatedProgress($pks, 'milestone_id');
         $total_tasks = $tmodel->getAggregatedTotal($pks, 'milestone_id');
         $completed_tasks = $tmodel->getAggregatedTotal($pks, 'milestone_id', 1);
     }
     foreach ($items as $i => &$item) {
         // Convert the parameter fields into objects.
         $params = new JRegistry();
         $params->loadString($item->attribs);
         $items[$i]->params = clone $this->getState('params');
         // Create slugs
         $items[$i]->slug = $items[$i]->alias ? $items[$i]->id . ':' . $items[$i]->alias : $items[$i]->id;
         $items[$i]->project_slug = $items[$i]->project_alias ? $items[$i]->project_id . ':' . $items[$i]->project_alias : $items[$i]->project_id;
         // Get the labels
         if ($items[$i]->label_count > 0) {
             $items[$i]->labels = $labels->getConnections('com_pfmilestones.milestone', $items[$i]->id);
         }
         if (!isset($items[$i]->watching)) {
             $items[$i]->watching = 0;
         }
         // Inject task count
         $items[$i]->tasks = isset($total_tasks[$item->id]) ? $total_tasks[$item->id] : 0;
         // Inject completed task count
         $items[$i]->completed_tasks = isset($completed_tasks[$item->id]) ? $completed_tasks[$item->id] : 0;
         // Inject progress
         $items[$i]->progress = isset($progress[$item->id]) ? $progress[$item->id] : 0;
     }
     return $items;
 }
 /**
  * Method to get a list of items.
  * Overriden to inject convert the attribs field into a JParameter object.
  *
  * @return    mixed    $items    An array of objects on success, false on failure.
  */
 public function getItems()
 {
     $items = parent::getItems();
     $labels = $this->getInstance('Labels', 'PFModel');
     // Get the global params
     $global_params = JComponentHelper::getParams('com_pfforum', true);
     $null_date = JFactory::getDbo()->getNullDate();
     // Get reply count
     $pks = JArrayHelper::getColumn($items, 'id');
     $replies = $this->getReplyCount($pks);
     foreach ($items as $i => &$item) {
         // Convert the parameter fields into objects.
         $params = new JRegistry();
         $params->loadString($item->attribs);
         $items[$i]->params = clone $this->getState('params');
         // Create slugs
         $items[$i]->slug = $items[$i]->alias ? $items[$i]->id . ':' . $items[$i]->alias : $items[$i]->id;
         $items[$i]->project_slug = $items[$i]->project_alias ? $items[$i]->project_id . ':' . $items[$i]->project_alias : $items[$i]->project_id;
         // Reply count
         $item->replies = $replies[$item->id];
         // Get the labels
         if ($items[$i]->label_count > 0) {
             $items[$i]->labels = $labels->getConnections('com_pfforum.topic', $items[$i]->id);
         }
     }
     return $items;
 }
 protected function getSelect2HTML($value, $multiple = false)
 {
     $access = (int) $this->form->getValue('access');
     $pks = JArrayHelper::getColumn($value, 'id');
     $html = array();
     if (!$access) {
         $access = (int) JFactory::getConfig()->get('access');
     }
     $url = "index.php?option=com_pfusers&view=userref&filter_access=" . $access . "&tmpl=component&layout=select2&format=json";
     $html[] = '<input type="hidden" id="' . $this->id . '" name="' . $this->name . '" value="' . implode(',', $pks) . '" class="inputbox input-large"/>';
     $html[] = '<script type="text/javascript">';
     $html[] = 'jQuery("#' . $this->id . '").select2({';
     $html[] = '    allowClear: true,';
     $html[] = '    minimumInputLength: 0,';
     $html[] = '    multiple: true,';
     $html[] = '    ajax:';
     $html[] = '    {';
     $html[] = '        url: "' . $url . '",';
     $html[] = '        dataType: "json",';
     $html[] = '        quietMillis: 200,';
     $html[] = '        data: function (term, page)';
     $html[] = '        {';
     $html[] = '            return {filter_search: term, limit: 10, limitstart: ((page - 1) * 10)};';
     $html[] = '        },';
     $html[] = '        results: function (data, page)';
     $html[] = '        {';
     $html[] = '            var more = (page * 10) < data.total;';
     $html[] = '            return {results: data.items, more: more};';
     $html[] = '        }';
     $html[] = '    }';
     if (count($pks)) {
         $html[] = '    ,initSelection: function(element, callback)';
         $html[] = '    {';
         $html[] = '        callback(' . $this->getJsonUsers($pks) . ');';
         $html[] = '    }';
     }
     $html[] = '});';
     $html[] = '</script>';
     return $html;
 }
 protected function __getArticleByKey($article, $key = 'id')
 {
     $storeId = md5(__METHOD__ . '::' . $key);
     if (!isset($this->cache[$storeId])) {
         $this->cache[$storeId] = JArrayHelper::getColumn($article, $key);
         return $this->cache[$storeId];
     }
     return $this->cache[$storeId];
 }
    function display($tpl = null)
    {
        $doc = JFactory::getDocument();
        $menus = JMenu::getInstance('site');
        $active = $menus->getActive();
        $state = $this->get('State');
        $this->state = $state;
        $params = $state->params;
        // Set value again for option tz_portfolio_plus_redirect
        if ($params->get('tz_portfolio_plus_redirect') == 'default') {
            $params->set('tz_portfolio_plus_redirect', 'article');
        }
        $items = $this->get('Items');
        if ($items) {
            $user = JFactory::getUser();
            $userId = $user->get('id');
            $guest = $user->get('guest');
            $content_ids = array();
            if ($items) {
                $content_ids = JArrayHelper::getColumn($items, 'id');
            }
            $mainCategories = TZ_Portfolio_PlusFrontHelperCategories::getCategoriesByArticleId($content_ids, array('main' => true));
            $second_categories = TZ_Portfolio_PlusFrontHelperCategories::getCategoriesByArticleId($content_ids, array('main' => false));
            $tags = null;
            if (count($content_ids) && $params->get('show_tags', 1)) {
                $tags = TZ_Portfolio_PlusFrontHelperTags::getTagsByArticleId($content_ids, array('orderby' => 'm.contentid', 'reverse_contentid' => true));
            }
            $dispatcher = JDispatcher::getInstance();
            JPluginHelper::importPlugin('content');
            TZ_Portfolio_PlusPluginHelper::importPlugin('content');
            TZ_Portfolio_PlusPluginHelper::importPlugin('mediatype');
            $dispatcher->trigger('onAlwaysLoadDocument', array('com_tz_portfolio_plus.users'));
            $dispatcher->trigger('onLoadData', array('com_tz_portfolio_plus.users', $items, $params));
            foreach ($items as $i => &$item) {
                if ($mainCategories && isset($mainCategories[$item->id])) {
                    $mainCategory = $mainCategories[$item->id];
                    if ($mainCategory) {
                        $item->catid = $mainCategory->id;
                        $item->category_title = $mainCategory->title;
                        $item->catslug = $mainCategory->id . ':' . $mainCategory->alias;
                        $item->category_link = $mainCategory->link;
                    }
                } else {
                    // Create main category's link
                    $item->category_link = TZ_Portfolio_PlusHelperRoute::getCategoryRoute($item->catid);
                }
                // Get all second categories
                $item->second_categories = null;
                if (isset($second_categories[$item->id])) {
                    $item->second_categories = $second_categories[$item->id];
                }
                // Get article's tags
                $item->tags = null;
                if ($tags && count($tags) && isset($tags[$item->id])) {
                    $item->tags = $tags[$item->id];
                }
                /*** New source ***/
                $tmpl = null;
                if ($item->params->get('tz_use_lightbox', 0)) {
                    $tmpl = '&tmpl=component';
                }
                $config = JFactory::getConfig();
                $ssl = -1;
                if ($config->get('force_ssl')) {
                    $ssl = 1;
                }
                // Create article link
                $item->link = JRoute::_(TZ_Portfolio_PlusHelperRoute::getArticleRoute($item->slug, $item->catid) . $tmpl);
                $item->fullLink = JRoute::_(TZ_Portfolio_PlusHelperRoute::getArticleRoute($item->slug, $item->catid), true, $ssl);
                // Create author link
                $item->author_link = JRoute::_(TZ_Portfolio_PlusHelperRoute::getUserRoute($item->created_by, $params->get('user_menu_active', 'auto')));
                // Compute the asset access permissions.
                // Technically guest could edit an article, but lets not check that to improve performance a little.
                if (!$guest) {
                    $asset = 'com_tz_portfolio_plus.article.' . $item->id;
                    // Check general edit permission first.
                    if ($user->authorise('core.edit', $asset)) {
                        $item->params->set('access-edit', true);
                    } elseif (!empty($userId) && $user->authorise('core.edit.own', $asset)) {
                        // Check for a valid user and that they are the owner.
                        if ($userId == $item->created_by) {
                            $item->params->set('access-edit', true);
                        }
                    }
                }
                // Old plugins: Ensure that text property is available
                if (!isset($item->text)) {
                    $item->text = $item->introtext;
                }
                if (version_compare(COM_TZ_PORTFOLIO_PLUS_VERSION, '3.1.7', '<')) {
                    $item->text = null;
                    if ($params->get('show_intro', 1)) {
                        $item->text = $item->introtext;
                    }
                }
                $item->event = new stdClass();
                //Call trigger in group content
                $results = $dispatcher->trigger('onContentPrepare', array('com_tz_portfolio_plus.users', &$item, &$params, $state->get('offset')));
                $item->introtext = $item->text;
                $results = $dispatcher->trigger('onContentAfterTitle', array('com_tz_portfolio_plus.users', &$item, &$params, $state->get('offset')));
                $item->event->afterDisplayTitle = trim(implode("\n", $results));
                $results = $dispatcher->trigger('onContentBeforeDisplay', array('com_tz_portfolio_plus.users', &$item, &$params, $state->get('offset')));
                $item->event->beforeDisplayContent = trim(implode("\n", $results));
                $results = $dispatcher->trigger('onContentAfterDisplay', array('com_tz_portfolio_plus.users', &$item, &$params, $state->get('offset')));
                $item->event->afterDisplayContent = trim(implode("\n", $results));
                $results = $dispatcher->trigger('onContentTZPortfolioVote', array('com_tz_portfolio_plus.users', &$item, &$params, $state->get('offset')));
                $item->event->TZPortfolioVote = trim(implode("\n", $results));
                // Process the tz portfolio's content plugins.
                $results = $dispatcher->trigger('onContentDisplayVote', array('com_tz_portfolio_plus.users', &$item, &$params, $state->get('offset')));
                $item->event->contentDisplayVote = trim(implode("\n", $results));
                $results = $dispatcher->trigger('onBeforeDisplayAdditionInfo', array('com_tz_portfolio_plus.users', &$item, &$params, $state->get('offset')));
                $item->event->beforeDisplayAdditionInfo = trim(implode("\n", $results));
                $results = $dispatcher->trigger('onAfterDisplayAdditionInfo', array('com_tz_portfolio_plus.users', &$item, &$params, $state->get('offset')));
                $item->event->afterDisplayAdditionInfo = trim(implode("\n", $results));
                $results = $dispatcher->trigger('onContentDisplayListView', array('com_tz_portfolio_plus.users', &$item, &$params, $state->get('offset')));
                $item->event->contentDisplayListView = trim(implode("\n", $results));
                //Call trigger in group tz_portfolio_plus_mediatype
                $results = $dispatcher->trigger('onContentDisplayMediaType', array('com_tz_portfolio_plus.users', &$item, &$params, $state->get('offset')));
                if ($item) {
                    $item->event->onContentDisplayMediaType = trim(implode("\n", $results));
                    if ($results = $dispatcher->trigger('onAddMediaType')) {
                        $mediatypes = array();
                        foreach ($results as $result) {
                            if (isset($result->special) && $result->special) {
                                $mediatypes[] = $result->value;
                            }
                        }
                        $item->mediatypes = $mediatypes;
                    }
                } else {
                    unset($items[$i]);
                }
            }
        }
        //Escape strings for HTML output
        $this->pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx'));
        if ($active) {
            $params->def('page_heading', $params->get('page_title', $active->title));
        } else {
            $params->def('page_heading', JText::_('JGLOBAL_ARTICLES'));
        }
        $this->items = $items;
        $this->params = $params;
        $this->assign('mediaParams', $params);
        $this->assign('pagination', $this->get('Pagination'));
        if ($author = JFactory::getUser($state->get('users.id'))) {
            $author_registry = $author->getParameters();
            $author_info = new stdClass();
            $author_info->id = $author->id;
            $author_info->url = $author_registry->get('tz_portfolio_plus_user_url');
            $author_info->email = $author->email;
            $author_info->gender = $author_registry->get('tz_portfolio_plus_user_gender');
            $author_info->avatar = $author_registry->get('tz_portfolio_plus_user_avatar');
            $author_info->social_links = null;
            if ($social_links = $author_registry->get('tz_portfolio_plus_user_social_link')) {
                foreach ($social_links as &$social_link) {
                    $social_link = json_decode($social_link);
                }
                $author_info->social_links = $social_links;
            }
            $author_info->description = $author_registry->get('tz_portfolio_plus_user_description');
            $author_info->author = $author->name;
            $author_info->author_link = JRoute::_(TZ_Portfolio_PlusHelperRoute::getUserRoute($state->get('users.id'), $params->get('user_menu_active', 'auto')));
            $this->item_author = $author_info;
        }
        $params = $state->params;
        JModelLegacy::addIncludePath(COM_TZ_PORTFOLIO_PLUS_PATH_SITE . DIRECTORY_SEPARATOR . 'models');
        $model = JModelLegacy::getInstance('Portfolio', 'TZ_Portfolio_PlusModel', array('ignore_request' => true));
        $model->setState('params', $params);
        $model->setState('filter.userId', $state->get('users.id'));
        $this->char = $state->get('filter.char');
        $this->availLetter = $model->getAvailableLetter();
        if ($params->get('tz_use_lightbox', 0) == 1) {
            $doc->addCustomTag('<script type="text/javascript" src="components/com_tz_portfolio_plus/js' . '/jquery.fancybox.pack.js"></script>');
            $doc->addStyleSheet('components/com_tz_portfolio_plus/css/fancybox.min.css');
            $width = null;
            $height = null;
            $autosize = null;
            if ($params->get('tz_lightbox_width')) {
                if (preg_match('/%|px/', $params->get('tz_lightbox_width'))) {
                    $width = 'width:\'' . $params->get('tz_lightbox_width') . '\',';
                } else {
                    $width = 'width:' . $params->get('tz_lightbox_width') . ',';
                }
            }
            if ($params->get('tz_lightbox_height')) {
                if (preg_match('/%|px/', $params->get('tz_lightbox_height'))) {
                    $height = 'height:\'' . $params->get('tz_lightbox_height') . '\',';
                } else {
                    $height = 'height:' . $params->get('tz_lightbox_height') . ',';
                }
            }
            if ($width || $height) {
                $autosize = 'fitToView: false,autoSize: false,';
            }
            $scrollHidden = null;
            if ($params->get('use_custom_scrollbar', 1)) {
                $scrollHidden = ',scrolling: "no"
                                    ,iframe: {
                                        scrolling : "no",
                                    }';
            }
            $doc->addCustomTag('<script type="text/javascript">
                jQuery(\'.fancybox\').fancybox({
                    type:\'iframe\',
                    openSpeed:' . $params->get('tz_lightbox_speed', 350) . ',
                    openEffect: "' . $params->get('tz_lightbox_transition', 'elastic') . '",
                    ' . $width . $height . $autosize . '
		            helpers:  {
                        title : {
                            type : "inside"
                        },
                        overlay : {
                            css : {background: "rgba(0,0,0,' . $params->get('tz_lightbox_opacity', 0.75) . ')"}
                        }
                    }' . $scrollHidden . '
                });
                </script>
            ');
        }
        $doc->addStyleSheet('components/com_tz_portfolio_plus/css/tzportfolioplus.min.css');
        $this->_prepareDocument();
        // Add feed links
        if ($params->get('show_feed_link', 1)) {
            $link = '&format=feed&limitstart=';
            $attribs = array('type' => 'application/rss+xml', 'title' => 'RSS 2.0');
            $doc->addHeadLink(JRoute::_($link . '&type=rss'), 'alternate', 'rel', $attribs);
            $attribs = array('type' => 'application/atom+xml', 'title' => 'Atom 1.0');
            $doc->addHeadLink(JRoute::_($link . '&type=atom'), 'alternate', 'rel', $attribs);
        }
        parent::display($tpl);
    }
Beispiel #18
0
 /**
  * Method to get a list of items.
  * Overriden to inject convert the attribs field into a JParameter object.
  *
  * @return    mixed    $items    An array of objects on success, false on failure.
  */
 public function getItems()
 {
     $items = parent::getItems();
     $labels = $this->getInstance('Labels', 'PFModel');
     // Get revision count
     $pks = JArrayHelper::getColumn($items, 'id');
     $elements = $this->getRevisionCount($pks);
     foreach ($items as $i => &$item) {
         // Convert the parameter fields into objects.
         $params = new JRegistry();
         $params->loadString($item->attribs);
         $item->params = clone $this->getState('params');
         // Create slugs
         $item->slug = $item->alias ? $item->id . ':' . $item->alias : $item->id;
         $item->project_slug = $item->project_alias ? $item->project_id . ':' . $item->project_alias : $item->project_id;
         $item->dir_slug = $item->dir_alias ? $item->dir_id . ':' . $item->dir_alias : $item->dir_id;
         // Get the labels
         if ($item->label_count > 0) {
             $item->labels = $labels->getConnections('com_pfrepo.note', $item->id);
         }
         // Revision count
         $item->revision_count = $elements[$item->id];
     }
     return $items;
 }
Beispiel #19
0
 private function _renderTableData($data, $oAllRowsData)
 {
     $params =& $this->getParams();
     if ($params->get('rating-mode') == 'creator-rating') {
         return $data;
     } else {
         $list =& $this->getTableModel()->getTable();
         $listid = $list->id;
         $formid = $list->form_id;
         $ids = JArrayHelper::getColumn($this->getTableModel()->getData(), '__pk_val');
         $row_id = isset($oAllRowsData->__pk_val) ? $oAllRowsData->__pk_val : $oAllRowsData->id;
         list($avg, $total) = $this->getRatingAverage($data, $listid, $formid, $row_id, $ids);
         return $avg;
     }
 }
 public static function getExtraFieldsByArticle($article, $params = null)
 {
     if (is_numeric($article)) {
         $article = TZ_Portfolio_PlusContentHelper::getArticleById($article);
     }
     $groupid = self::getFieldGroupsByArticleId($article->id);
     $groupid = JArrayHelper::getColumn($groupid, 'id');
     $storeId = md5(__METHOD__ . '::' . implode(',', $groupid) . '::' . $article->id);
     if (!isset(self::$cache[$storeId])) {
         $db = JFactory::getDbo();
         $query = $db->getQuery(true);
         $query->select('f.*');
         $query->from('#__tz_portfolio_plus_fields AS f');
         $query->join('INNER', '#__tz_portfolio_plus_field_content_map AS m ON m.fieldsid = f.id');
         $query->join('INNER', '#__tz_portfolio_plus_content AS c ON c.id = m.contentid');
         $query->join('INNER', '#__tz_portfolio_plus_field_fieldgroup_map AS fm ON fm.fieldsid = f.id');
         $query->join('INNER', '#__tz_portfolio_plus_extensions AS e ON e.element = f.type')->where('e.type = ' . $db->quote('tz_portfolio_plus-plugin'))->where('e.folder = ' . $db->quote('extrafields'))->where('e.published = 1');
         if (count($groupid)) {
             $query->where('fm.groupid IN(' . implode(',', $groupid) . ')');
         }
         $query->where('c.id = ' . $article->id);
         $query->where('f.published = 1');
         $query->group('f.id');
         $db->setQuery($query);
         if ($fields = $db->loadObjectList()) {
             self::$cache[$storeId] = $fields;
             return $fields;
         }
         self::$cache[$storeId] = false;
     }
     return self::$cache[$storeId];
 }
Beispiel #21
0
 public static function getTagTitlesByArticleId($articleId)
 {
     if ($tags = self::getTagsByArticleId($articleId)) {
         $tags = JArrayHelper::getColumn($tags, 'title');
         return array_unique($tags);
     }
     return false;
 }
Beispiel #22
0
 function importJ16()
 {
     jimport('joomla.filesystem.file');
     jimport('joomla.html.parameter');
     jimport('joomla.utilities.xmlelement');
     $mainframe = JFactory::getApplication();
     $db = JFactory::getDBO();
     $query = "SELECT COUNT(*) FROM #__k2_categories";
     $db->setQuery($query);
     $result = $db->loadResult();
     if ($result) {
         $preserveCategoryIDs = false;
     } else {
         $preserveCategoryIDs = true;
     }
     $query = "SELECT COUNT(*) FROM #__k2_items";
     $db->setQuery($query);
     $result = $db->loadResult();
     if ($result) {
         $preserveItemIDs = false;
     } else {
         $preserveItemIDs = true;
     }
     $xml = new JXMLElement(JFile::read(JPATH_COMPONENT . DS . 'models' . DS . 'category.xml'));
     $categoryParams = class_exists('JParameter') ? new JParameter('') : new JRegistry('');
     foreach ($xml->params as $paramGroup) {
         foreach ($paramGroup->param as $param) {
             if ((string) $param->attributes()->type != 'spacer' && (string) $param->attributes()->name) {
                 $categoryParams->set((string) $param->attributes()->name, (string) $param->attributes()->default);
             }
         }
     }
     $categoryParams = $categoryParams->toString();
     $xml = new JXMLElement(JFile::read(JPATH_COMPONENT . DS . 'models' . DS . 'item.xml'));
     $itemParams = class_exists('JParameter') ? new JParameter('') : new JRegistry('');
     foreach ($xml->params as $paramGroup) {
         foreach ($paramGroup->param as $param) {
             if ((string) $param->attributes()->type != 'spacer' && (string) $param->attributes()->name) {
                 $itemParams->set((string) $param->attributes()->name, (string) $param->attributes()->default);
             }
         }
     }
     $itemParams = $itemParams->toString();
     $query = "SELECT id, name FROM #__k2_tags";
     $db->setQuery($query);
     $tags = $db->loadObjectList();
     if (is_null($tags)) {
         $tags = array();
     }
     $query = "SELECT * FROM #__categories WHERE extension = 'com_content'";
     $db->setQuery($query);
     $categories = $db->loadObjectList();
     $mapping = array();
     foreach ($categories as $category) {
         $category->params = json_decode($category->params);
         $category->image = $category->params->image;
         $K2Category = JTable::getInstance('K2Category', 'Table');
         $K2Category->name = $category->title;
         $K2Category->alias = $category->title;
         $K2Category->description = $category->description;
         $K2Category->parent = $category->parent_id;
         if ($K2Category->parent == 1) {
             $K2Category->parent = 0;
         }
         $K2Category->published = $category->published;
         $K2Category->access = $category->access;
         $K2Category->ordering = $K2Category->getNextOrder('parent=' . (int) $category->parent_id);
         $K2Category->image = basename($category->image);
         $K2Category->trash = 0;
         $K2Category->language = $category->language;
         $K2Category->params = $categoryParams;
         $K2Category->check();
         if ($preserveCategoryIDs) {
             $K2Category->id = $category->id;
             $db->insertObject('#__k2_categories', $K2Category);
         } else {
             $K2Category->store();
             $mapping[$category->id] = $K2Category->id;
         }
         if ($K2Category->image && JFile::exists(realpath(JPATH_SITE . DS . $category->image))) {
             JFile::copy(realpath(JPATH_SITE . DS . $category->image), JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'categories' . DS . $K2Category->image);
         }
         $query = "SELECT article.*, xref.content_id\n\t\t\t\tFROM #__content AS article \n\t\t\t\tLEFT JOIN #__content_frontpage AS xref ON article.id = xref.content_id \n\t\t\t\tWHERE catid = " . (int) $category->id;
         $db->setQuery($query);
         $items = $db->loadObjectList();
         foreach ($items as $item) {
             $K2Item = JTable::getInstance('K2Item', 'Table');
             $K2Item->title = $item->title;
             $K2Item->alias = $item->title;
             $K2Item->catid = $K2Category->id;
             if ($item->state < 0) {
                 $K2Item->trash = 1;
             } else {
                 $K2Item->trash = 0;
             }
             $K2Item->published = 1;
             if ($item->state == 0) {
                 $K2Item->published = 0;
             }
             $K2Item->featured = $item->content_id ? 1 : 0;
             $K2Item->introtext = $item->introtext;
             $K2Item->fulltext = $item->fulltext;
             $K2Item->created = $item->created;
             $K2Item->created_by = $item->created_by;
             $K2Item->created_by_alias = $item->created_by_alias;
             $K2Item->modified = $item->modified;
             $K2Item->modified_by = $item->modified_by;
             $K2Item->publish_up = $item->publish_up;
             $K2Item->publish_down = $item->publish_down;
             $K2Item->access = $item->access;
             $K2Item->ordering = $item->ordering;
             $K2Item->hits = $item->hits;
             $K2Item->metadesc = $item->metadesc;
             $K2Item->metadata = $item->metadata;
             $K2Item->metakey = $item->metakey;
             $K2Item->params = $itemParams;
             $K2Item->language = $item->language;
             $K2Item->check();
             if ($preserveItemIDs) {
                 $K2Item->id = $item->id;
                 $db->insertObject('#__k2_items', $K2Item);
             } else {
                 $K2Item->store();
             }
             if (!empty($item->metakey)) {
                 $itemTags = explode(',', $item->metakey);
                 foreach ($itemTags as $itemTag) {
                     $itemTag = JString::trim($itemTag);
                     if (in_array($itemTag, JArrayHelper::getColumn($tags, 'name'))) {
                         $query = "SELECT id FROM #__k2_tags WHERE name=" . $db->Quote($itemTag);
                         $db->setQuery($query);
                         $id = $db->loadResult();
                         $query = "INSERT INTO #__k2_tags_xref (`id`, `tagID`, `itemID`) VALUES (NULL, {$id}, {$K2Item->id})";
                         $db->setQuery($query);
                         $db->query();
                     } else {
                         $K2Tag = JTable::getInstance('K2Tag', 'Table');
                         $K2Tag->name = $itemTag;
                         $K2Tag->published = 1;
                         $K2Tag->store();
                         $tags[] = $K2Tag;
                         $query = "INSERT INTO #__k2_tags_xref (`id`, `tagID`, `itemID`) VALUES (NULL, {$K2Tag->id}, {$K2Item->id})";
                         $db->setQuery($query);
                         $db->query();
                     }
                 }
             }
         }
     }
     foreach ($mapping as $oldID => $newID) {
         $query = "UPDATE #__k2_categories SET parent=" . $newID . " WHERE parent=" . $oldID;
         $db->setQuery($query);
         $db->query();
     }
     $mainframe->enqueueMessage(JText::_('K2_IMPORT_COMPLETED'));
     $mainframe->redirect('index.php?option=com_k2&view=items');
 }
Beispiel #23
0
 /**
  * Automatically detects all views of the component
  *
  * @return  array  A list of all views, in the order to be displayed in the toolbar submenu
  */
 protected function getMyViews()
 {
     $views = array();
     $t_views = array();
     $using_meta = false;
     $componentPaths = FOFPlatform::getInstance()->getComponentBaseDirs($this->component);
     $searchPath = $componentPaths['main'] . '/views';
     JLoader::import('joomla.filesystem.folder');
     JLoader::import('joomla.utilities.arrayhelper');
     $allFolders = JFolder::folders($searchPath);
     if (!empty($allFolders)) {
         foreach ($allFolders as $folder) {
             $view = $folder;
             // View already added
             if (in_array(FOFInflector::pluralize($view), $t_views)) {
                 continue;
             }
             // Do we have a 'skip.xml' file in there?
             $files = JFolder::files($searchPath . '/' . $view, '^skip\\.xml$');
             if (!empty($files)) {
                 continue;
             }
             // Do we have extra information about this view? (ie. ordering)
             $meta = JFolder::files($searchPath . '/' . $view, '^metadata\\.xml$');
             // Not found, do we have it inside the plural one?
             if (!$meta) {
                 $plural = FOFInflector::pluralize($view);
                 if (in_array($plural, $allFolders)) {
                     $view = $plural;
                     $meta = JFolder::files($searchPath . '/' . $view, '^metadata\\.xml$');
                 }
             }
             if (!empty($meta)) {
                 $using_meta = true;
                 $xml = simplexml_load_file($searchPath . '/' . $view . '/' . $meta[0]);
                 $order = (int) $xml->foflib->ordering;
             } else {
                 // Next place. It's ok since the index are 0-based and count is 1-based
                 if (!isset($to_order)) {
                     $to_order = array();
                 }
                 $order = count($to_order);
             }
             $view = FOFInflector::pluralize($view);
             $t_view = new stdClass();
             $t_view->ordering = $order;
             $t_view->view = $view;
             $to_order[] = $t_view;
             $t_views[] = $view;
         }
     }
     JArrayHelper::sortObjects($to_order, 'ordering');
     $views = JArrayHelper::getColumn($to_order, 'view');
     // If not using the metadata file, let's put the cpanel view on top
     if (!$using_meta) {
         $cpanel = array_search('cpanels', $views);
         if ($cpanel !== false) {
             unset($views[$cpanel]);
             array_unshift($views, 'cpanels');
         }
     }
     return $views;
 }
        $this->item = $item;
        $params = $item->params;
        if ($params->get('tz_column_width', 230)) {
            $tzItemClass = ' tz_item';
        } else {
            $tzItemClass = null;
        }
        if ($item->featured == 1) {
            $tzItemFeatureClass = ' tz_feature_item';
        } else {
            $tzItemFeatureClass = null;
        }
        $class = '';
        if ($params->get('tz_filter_type', 'tags') == 'tags') {
            if ($item->tags && count($item->tags)) {
                $alias = JArrayHelper::getColumn($item->tags, 'alias');
                $class = implode(' ', $alias);
            }
        } elseif ($params->get('tz_filter_type', 'tags') == 'categories') {
            $class = 'category' . $item->catid;
            if (isset($item->second_categories) && $item->second_categories && count($item->second_categories)) {
                foreach ($item->second_categories as $category) {
                    $class .= ' category' . $category->id;
                }
            }
        } elseif ($params->get('tz_filter_type', 'tags') == 'letters') {
            $class = mb_strtolower(mb_substr(trim($item->title), 0, 1));
        }
        ?>
<div id="tzelement<?php 
        echo $item->id;
Beispiel #25
0
 function import()
 {
     $mainframe =& JFactory::getApplication();
     jimport('joomla.filesystem.file');
     $db =& JFactory::getDBO();
     $query = "SELECT * FROM #__sections";
     $db->setQuery($query);
     $sections = $db->loadObjectList();
     $xml = new JSimpleXML();
     $xml->loadFile(JPATH_COMPONENT . DS . 'models' . DS . 'category.xml');
     $categoryParams = new JParameter('');
     foreach ($xml->document->params as $paramGroup) {
         foreach ($paramGroup->param as $param) {
             if ($param->attributes('type') != 'spacer') {
                 $categoryParams->set($param->attributes('name'), $param->attributes('default'));
             }
         }
     }
     $categoryParams = $categoryParams->toString();
     $xml = new JSimpleXML();
     $xml->loadFile(JPATH_COMPONENT . DS . 'models' . DS . 'item.xml');
     $itemParams = new JParameter('');
     foreach ($xml->document->params as $paramGroup) {
         foreach ($paramGroup->param as $param) {
             if ($param->attributes('type') != 'spacer') {
                 $itemParams->set($param->attributes('name'), $param->attributes('default'));
             }
         }
     }
     $itemParams = $itemParams->toString();
     $query = "SELECT id, name FROM #__k2_tags";
     $db->setQuery($query);
     $tags = $db->loadObjectList();
     if (is_null($tags)) {
         $tags = array();
     }
     foreach ($sections as $section) {
         $K2Category =& JTable::getInstance('K2Category', 'Table');
         $K2Category->name = $section->title;
         $K2Category->alias = $section->title;
         $K2Category->description = $section->description;
         $K2Category->parent = 0;
         $K2Category->published = $section->published;
         $K2Category->access = $section->access;
         $K2Category->ordering = $section->ordering;
         $K2Category->image = $section->image;
         $K2Category->trash = 0;
         $K2Category->params = $categoryParams;
         $K2Category->check();
         $K2Category->store();
         if (JFile::exists(JPATH_SITE . DS . 'images' . DS . 'stories' . DS . $section->image)) {
             JFile::copy(JPATH_SITE . DS . 'images' . DS . 'stories' . DS . $section->image, JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'categories' . DS . $K2Category->image);
         }
         $query = "SELECT * FROM #__categories WHERE section = {$section->id}";
         $db->setQuery($query);
         $categories = $db->loadObjectList();
         foreach ($categories as $category) {
             $K2Subcategory =& JTable::getInstance('K2Category', 'Table');
             $K2Subcategory->name = $category->title;
             $K2Subcategory->alias = $category->title;
             $K2Subcategory->description = $category->description;
             $K2Subcategory->parent = $K2Category->id;
             $K2Subcategory->published = $category->published;
             $K2Subcategory->access = $category->access;
             $K2Subcategory->ordering = $category->ordering;
             $K2Subcategory->image = $category->image;
             $K2Subcategory->trash = 0;
             $K2Subcategory->params = $categoryParams;
             $K2Subcategory->check();
             $K2Subcategory->store();
             if (JFile::exists(JPATH_SITE . DS . 'images' . DS . 'stories' . DS . $category->image)) {
                 JFile::copy(JPATH_SITE . DS . 'images' . DS . 'stories' . DS . $category->image, JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'categories' . DS . $K2Subcategory->image);
             }
             $query = "SELECT * FROM #__content WHERE catid = {$category->id}";
             $db->setQuery($query);
             $items = $db->loadObjectList();
             foreach ($items as $item) {
                 $K2Item =& JTable::getInstance('K2Item', 'Table');
                 $K2Item->title = $item->title;
                 $K2Item->alias = $item->title;
                 $K2Item->catid = $K2Subcategory->id;
                 if ($item->state == -1) {
                     $K2Item->trash = 1;
                 } else {
                     $K2Item->trash = 0;
                     $K2Item->published = $item->state;
                 }
                 $K2Item->introtext = $item->introtext;
                 $K2Item->fulltext = $item->fulltext;
                 $K2Item->created = $item->created;
                 $K2Item->created_by = $item->created_by;
                 $K2Item->created_by_alias = $item->created_by_alias;
                 $K2Item->modified = $item->modified;
                 $K2Item->modified_by = $item->modified_by;
                 $K2Item->publish_up = $item->publish_up;
                 $K2Item->publish_down = $item->publish_down;
                 $K2Item->access = $item->access;
                 $K2Item->ordering = $item->ordering;
                 $K2Item->hits = $item->hits;
                 $K2Item->metadesc = $item->metadesc;
                 $K2Item->metadata = $item->metadata;
                 $K2Item->metakey = $item->metakey;
                 $K2Item->params = $itemParams;
                 $K2Item->check();
                 $K2Item->store();
                 if (!empty($item->metakey)) {
                     $itemTags = explode(',', $item->metakey);
                     foreach ($itemTags as $itemTag) {
                         $itemTag = JString::trim($itemTag);
                         if (in_array($itemTag, JArrayHelper::getColumn($tags, 'name'))) {
                             $query = "SELECT id FROM #__k2_tags WHERE name=" . $db->Quote($itemTag);
                             $db->setQuery($query);
                             $id = $db->loadResult();
                             $query = "INSERT INTO #__k2_tags_xref (`id`, `tagID`, `itemID`) VALUES (NULL, {$id}, {$K2Item->id})";
                             $db->setQuery($query);
                             $db->query();
                         } else {
                             $K2Tag =& JTable::getInstance('K2Tag', 'Table');
                             $K2Tag->name = $itemTag;
                             $K2Tag->published = 1;
                             $K2Tag->store();
                             $tags[] = $K2Tag;
                             $query = "INSERT INTO #__k2_tags_xref (`id`, `tagID`, `itemID`) VALUES (NULL, {$K2Tag->id}, {$K2Item->id})";
                             $db->setQuery($query);
                             $db->query();
                         }
                     }
                 }
             }
         }
     }
     $mainframe->redirect('index.php?option=com_k2&view=items', JText::_('Import Completed'));
 }
Beispiel #26
0
 /**
  * Method to get an array of data items.
  *
  * @return    mixed    An array of data items on success, false on failure.
  */
 public function getItems()
 {
     // Get a storage key.
     $store = $this->getStoreId();
     // Try to load the data from internal storage.
     if (isset($this->cache[$store])) {
         return $this->cache[$store];
     }
     // Load the items
     $items = array();
     $count = (int) $this->getState('list.count_elements');
     $parent = (int) $this->getState('filter.parent_id', 1);
     if ($parent == 1) {
         // Load the list items.
         $query = $this->_getListQuery();
         $dir = $this->getInstance('DirectoryForm', 'PFrepoModel', $config = array('ignore_request' => true));
         $labels = $this->getInstance('Labels', 'PFModel');
         try {
             $items['directory'] = $dir->getItem($parent);
             $items['directories'] = $this->_getList($query, $this->getStart(), $this->getState('list.limit'));
             $items['notes'] = array();
             $items['files'] = array();
         } catch (RuntimeException $e) {
             $this->setError($e->getMessage());
             return false;
         }
         if ($count) {
             $pks = JArrayHelper::getColumn($items['directories'], 'id');
             $elements = $this->getElementCount($pks);
         }
         foreach ($items['directories'] as $i => &$item) {
             // Convert the parameter fields into objects.
             $params = new JRegistry();
             $params->loadString($item->attribs);
             $item->params = clone $this->getState('params');
             // Create slugs
             $item->slug = $item->alias ? $item->id . ':' . $item->alias : $item->id;
             $item->project_slug = $item->project_alias ? $item->project_id . ':' . $item->project_alias : $item->project_id;
             // Set orphaned status
             $item->orphaned = empty($item->project_exists);
             // Get element count
             $item->element_count = $count ? $elements[$item->id] : 0;
             // Get the labels
             if ($item->label_count > 0) {
                 $item->labels = $labels->getConnections('com_pfrepo.directory', $item->id);
             }
         }
     } else {
         // Get the models
         $dir = $this->getInstance('DirectoryForm', 'PFrepoModel', $config = array('ignore_request' => true));
         $dirs = $this->getInstance('Directories', 'PFrepoModel', $config = array());
         $notes = $this->getInstance('Notes', 'PFrepoModel', $config = array());
         $files = $this->getInstance('Files', 'PFrepoModel', $config = array());
         // Get the data
         $items['directory'] = $dir->getItem($parent);
         $items['directories'] = $dirs->getItems();
         $items['notes'] = $notes->getItems();
         $items['files'] = $files->getItems();
         // Check for errors
         if ($dir->getError()) {
             $this->setError($dir->getError());
         }
         if ($dirs->getError()) {
             $this->setError($dirs->getError());
         }
         if ($notes->getError()) {
             $this->setError($notes->getError());
         }
         if ($files->getError()) {
             $this->setError($files->getError());
         }
     }
     // Add the items to the internal cache.
     $this->cache[$store] = $items;
     return $this->cache[$store];
 }
Beispiel #27
0
	/**
	 * Test pulling data from a single column (by index or association).
	 *
	 * @param array  $input   Input array
	 * @param mixed  $index   Column to pull, either by association or number
	 * @param array  $expect  The expected results
	 * @param string $message The failure message
	 *
	 * @return void
	 * @dataProvider getTestGetColumnData
	 */
	public function testGetColumn($input, $index, $expect, $message)
	{
		$this->assertEquals(
			$expect,
			JArrayHelper::getColumn($input, $index),
			$message
		);
	}
Beispiel #28
0
 /**
  * get query to make records
  * @return string sql
  */
 function _buildQuery()
 {
     global $_PROFILER;
     JDEBUG ? $_PROFILER->mark('_buildQuery: start') : null;
     $query = array();
     if ($this->mergeJoinedData()) {
         // $$$ rob - get a list of the main table's ids limited on the navigation
         // this will then be used to filter the main query,
         // by modifying the where part of the query
         $db = $this->getDb();
         $table = $this->getTable();
         // $$$ rob build order first so that we know of any elemenets we need to include in the select statement
         $order = $this->_buildQueryOrder();
         $this->selectedOrderFields = (array) $this->selectedOrderFields;
         array_unshift($this->selectedOrderFields, "DISTINCT " . $table->db_primary_key . " AS __pk_val");
         $query['select'] = "SELECT  " . implode(', ', $this->selectedOrderFields) . " FROM " . $db->nameQuote($table->db_table_name);
         $query['join'] = $this->_buildQueryJoin();
         $query['where'] = $this->_buildQueryWhere(JRequest::getVar('incfilters', 1));
         $query['grouby'] = $this->_buildQueryGroupBy();
         $query['order'] = $order;
         //check that the order by fields are in the select statement
         $squery = implode(" ", $query);
         $db->setQuery($squery, $this->limitStart, $this->limitLength);
         FabrikHelperHTML::debug($db->getQuery(), 'table:mergeJoinedData get ids');
         $ids = JArrayHelper::getColumn($db->loadObjectList(), '__pk_val');
     }
     $query = array();
     $query['select'] = $this->_buildQuerySelect();
     JDEBUG ? $_PROFILER->mark('queryselect: got') : null;
     $query['join'] = $this->_buildQueryJoin();
     JDEBUG ? $_PROFILER->mark('queryjoin: got') : null;
     if ($this->mergeJoinedData()) {
         // $$$ rob We've already used _buildQueryWhere to get our list of main pk ids.
         // so lets use that list of ids to create the where statement. This will return 5/10/20 etc
         // records from our main table, as per our page nav, even if a main record has 3 rows of joined
         // data. If no ids found then do where 1 = -1 to return no records
         if (!empty($ids)) {
             $query['where'] = " WHERE {$table->db_primary_key} IN (" . implode($ids, ',') . ')';
         } else {
             $query['where'] = " WHERE 1 = -1";
         }
     } else {
         // $$$ rob we aren't merging joined records so lets just add the standard where query
         //incfilters set when exporting as CSV
         $query['where'] = $this->_buildQueryWhere(JRequest::getVar('incfilters', 1));
     }
     $query['groupby'] = $this->_buildQueryGroupBy();
     $query['order'] = $this->_buildQueryOrder();
     $query = $this->pluginQuery($query);
     $query = implode(" ", $query);
     return $query;
 }
Beispiel #29
0
 /**
  * @since 2.6
  * @param user id
  * @return array of the latest group discussion the user has participated
  */
 public function getGroupDiscussionLastActive($userid)
 {
     $db = JFactory::getDBO();
     //first we get the discussion that the user has participated into
     $query = "SELECT contentid FROM " . $db->quoteName('#__community_wall') . " WHERE type='discussions' AND post_by=" . $db->Quote($userid);
     $db->setQuery($query);
     $discussionIds = $db->loadAssocList();
     $discussionIds = JArrayHelper::getColumn($discussionIds, 'contentid');
     if (count($discussionIds) > 0) {
         $discussionIds = implode(',', $discussionIds);
         //set the limit if configurable
         $query = "SELECT g.id AS discussionid, w.post_by, w.comment, w.date, g.groupid, g.title, gr.name AS group_name, w.params\n\t\t\t\t\t\tFROM " . $db->quoteName('#__community_wall') . " w, " . $db->quoteName('#__community_groups_discuss') . "\n\t\t\t\t\t\tg, " . $db->quoteName('#__community_groups') . " gr WHERE w.contentid = g.id AND w.type='discussions'\n\t\t\t\t\t\tAND gr.id = g.groupid AND w.contentid IN (" . $discussionIds . ") ORDER BY w.id DESC LIMIT 9";
         $db->setQuery($query);
         $discussionUpdates = $db->loadAssocList();
         //generate extra info for latest discussion updates
         foreach ($discussionUpdates as &$disc) {
             //grouplink
             $disc['group_link'] = CRoute::_('index.php?option=com_community&view=groups&task=viewgroup&groupid=' . $disc['groupid']);
             $disc['discussion_link'] = CRoute::_('index.php?option=com_community&view=groups&task=viewdiscussion&groupid=' . $disc['groupid'] . '&topicid=' . $disc['discussionid']);
             $date = CTimeHelper::getDate($disc['date']);
             $disc['created_interval'] = CTimeHelper::timeLapse($date);
             $user = CFactory::getUser($disc['post_by']);
             $disc['created_by'] = $user->getDisplayName();
             $table = JTable::getInstance('Group', 'CTable');
             $table->load($disc['groupid']);
             $disc['group_avatar'] = $table->getThumbAvatar();
         }
         return $discussionUpdates;
     }
     return null;
 }
Beispiel #30
0
 /**
  * Method to get a list of articles.
  * Overridden to add a check for access levels.
  *
  * @return	mixed	An array of data items on success, false on failure.
  * @since	1.6.1
  */
 public function getItems()
 {
     $items = parent::getItems();
     $app = JFactory::getApplication();
     // Get fields group
     $data = array();
     if ($app->isSite()) {
         $user = JFactory::getUser();
         $groups = $user->getAuthorisedViewLevels();
         for ($x = 0, $count = count($items); $x < $count; $x++) {
             //Check the access level. Remove articles the user shouldn't see
             if (!in_array($items[$x]->access, $groups)) {
                 unset($items[$x]);
             }
         }
     }
     if ($items) {
         $texts = array();
         $values = array();
         $dispatcher = JEventDispatcher::getInstance();
         TZ_Portfolio_PlusPluginHelper::importPlugin('mediatype');
         $results = $dispatcher->trigger('onAddMediaType');
         if (count($results)) {
             $texts = JArrayHelper::getColumn($results, 'text');
             $values = JArrayHelper::getColumn($results, 'value');
         }
         foreach ($items as &$item) {
             $categories = TZ_Portfolio_PlusHelperCategories::getCategoriesByArticleId($item->id, 0);
             $item->categories = $categories;
             if (isset($item->type) && in_array($item->type, $values)) {
                 $index = array_search($item->type, $values);
                 $item->type = $texts[$index];
             } else {
                 $item->type = JText::_('COM_TZ_PORTFOLIO_PLUS_OPTION_NONE_MEDIA');
             }
         }
     }
     return $items;
 }