/** * Add the page title and toolbar. */ protected function addToolbar() { JFactory::getApplication()->input->set('hidemainmenu', true); $user = JFactory::getUser(); $isNew = $this->item->id == 0; if (isset($this->item->checked_out)) { $checkedOut = !($this->item->checked_out == 0 || $this->item->checked_out == $user->get('id')); } else { $checkedOut = false; } $canDo = CitybrandingHelper::getActions(); JToolBarHelper::title(JText::_('COM_CITYBRANDING_TITLE_COMMENT'), 'comment-2'); // If not checked out, can save the item. if (!$checkedOut && ($canDo->get('core.edit') || $canDo->get('core.create'))) { JToolBarHelper::apply('comment.apply', 'JTOOLBAR_APPLY'); JToolBarHelper::save('comment.save', 'JTOOLBAR_SAVE'); } if (!$checkedOut && $canDo->get('core.create')) { JToolBarHelper::custom('comment.save2new', 'save-new.png', 'save-new_f2.png', 'JTOOLBAR_SAVE_AND_NEW', false); } // If an existing item, can save to a copy. if (!$isNew && $canDo->get('core.create')) { JToolBarHelper::custom('comment.save2copy', 'save-copy.png', 'save-copy_f2.png', 'JTOOLBAR_SAVE_AS_COPY', false); } if (empty($this->item->id)) { JToolBarHelper::cancel('comment.cancel', 'JTOOLBAR_CANCEL'); } else { JToolBarHelper::cancel('comment.cancel', 'JTOOLBAR_CLOSE'); } }
/** * Method to get the options to populate list * * @return array The field option objects. * * @since 3.2 */ protected function getOptions() { // Hash for caching $hash = md5($this->element); if (!isset(static::$options[$hash])) { static::$options[$hash] = parent::getOptions(); $options = array(); $db = JFactory::getDbo(); $user = JFactory::getUser(); $query = $db->getQuery(true)->select('a.id AS value')->select('a.title AS text')->select('COUNT(DISTINCT b.id) AS level')->from('#__categories as a')->where('a.extension = "' . $this->extension . '"')->join('LEFT', '#__categories AS b ON a.lft > b.lft AND a.rgt < b.rgt')->group('a.id, a.title, a.lft, a.rgt')->order('a.lft ASC'); $isRoot = $user->authorise('core.admin'); if (!$isRoot) { require_once JPATH_COMPONENT_ADMINISTRATOR . '/helpers/citybranding.php'; $allowed_catids = CitybrandingHelper::getCategoriesByUserGroups(); $allowed_catids = implode(',', $allowed_catids); if (!empty($allowed_catids)) { $query->where('a.id IN (' . $allowed_catids . ')'); } } $db->setQuery($query); if ($options = $db->loadObjectList()) { foreach ($options as &$option) { $option->text = str_repeat('- ', $option->level) . $option->text; } static::$options[$hash] = array_merge(static::$options[$hash], $options); } } return static::$options[$hash]; }
/** * Method to get the options to populate list * * @return array The field option objects. * * @since 3.2 */ protected function getOptions() { $showEmpty = $this->element['showempty']; // Hash for caching $hash = md5($this->element); if (!isset(static::$options[$hash])) { static::$options[$hash] = parent::getOptions(); $options = array(); $db = JFactory::getDbo(); $user = JFactory::getUser(); $canDo = CitybrandingHelper::getActions(); $canShowAllPois = $canDo->get('citybranding.showall.pois'); if ($canShowAllPois) { $query = $db->getQuery(true)->select('a.id AS value')->select('a.title AS text')->select('COUNT(DISTINCT b.id) AS level')->from('#__usergroups as a')->where('a.id > 9')->join('LEFT', '#__usergroups AS b ON a.lft > b.lft AND a.rgt < b.rgt')->group('a.id, a.title, a.lft, a.rgt')->order('a.lft ASC'); } else { //get user groups higher than 9 $usergroups = JAccess::getGroupsByUser($user->id, false); for ($i = 0; $i < count($usergroups); $i++) { if ($usergroups[$i] <= 9) { unset($usergroups[$i]); } } $ids = implode(',', $usergroups); //get lft, rgt for these groups $where = array(); $query = $db->getQuery(true)->select('a.id, a.lft, a.rgt')->from('#__usergroups as a')->where('a.id IN (' . $ids . ')'); $db->setQuery($query); if ($grps = $db->loadAssocList()) { foreach ($grps as $grp) { $where[] = '(a.lft >= ' . $grp['lft'] . ' AND a.rgt <= ' . $grp['rgt'] . ')'; $where[] = ' OR '; } array_pop($where); } else { $where[] = "1=1"; } $query = $db->getQuery(true)->select('a.id AS value')->select('a.title AS text')->select('COUNT(DISTINCT b.id) AS level')->from('#__usergroups as a')->where('a.id > 9')->where(implode("\n", $where))->join('LEFT', '#__usergroups AS b ON a.lft > b.lft AND a.rgt < b.rgt')->group('a.id, a.title, a.lft, a.rgt')->order('a.lft ASC'); } $db->setQuery($query); if ($options = $db->loadObjectList()) { if ($showEmpty) { $empty = new stdClass(); $empty->value = '0'; $empty->text = ''; $empty->level = 1; array_unshift($options, $empty); } foreach ($options as &$option) { $option->text = str_repeat('- ', $option->level) . $option->text; } static::$options[$hash] = array_merge(static::$options[$hash], $options); } } return static::$options[$hash]; }
/** * Add the page title and toolbar. */ protected function addToolbar() { JFactory::getApplication()->input->set('hidemainmenu', true); $user = JFactory::getUser(); $isNew = $this->item->id == 0; if (isset($this->item->checked_out)) { $checkedOut = !($this->item->checked_out == 0 || $this->item->checked_out == $user->get('id')); } else { $checkedOut = false; } $canDo = CitybrandingHelper::getActions(); JToolBarHelper::title(JText::_('COM_CITYBRANDING_TITLE_POI'), 'drawer'); // If not checked out, can save the item. if (!$checkedOut && ($canDo->get('core.edit') || $canDo->get('core.create'))) { JToolBarHelper::apply('poi.apply', 'JTOOLBAR_APPLY'); JToolBarHelper::save('poi.save', 'JTOOLBAR_SAVE'); } // if (!$checkedOut && ($canDo->get('core.create'))) { // JToolBarHelper::custom('poi.save2new', 'save-new.png', 'save-new_f2.png', 'JTOOLBAR_SAVE_AND_NEW', false); // } // If an existing item, can save to a copy. //if (!$isNew && $canDo->get('core.create')) { // JToolBarHelper::custom('poi.save2copy', 'save-copy.png', 'save-copy_f2.png', 'JTOOLBAR_SAVE_AS_COPY', false); //} if (!empty($this->item->id)) { //on existing allow printing //JToolBarHelper::custom('poi.printPoi', 'print.png', 'print.png', 'COM_CITYBRANDING_PRINT', false); $bar = JToolBar::getInstance('toolbar'); $layout = new JLayoutFile('joomla.toolbar.popup'); $dhtml = $layout->render(array('doTask' => 'print', 'class' => 'icon-print', 'text' => JText::_('COM_CITYBRANDING_PRINT'), 'name' => 'citybranding-print')); $bar->appendButton('Custom', $dhtml); //$url = 'index.php?option=com_citybranding&view=poi&task=poi.printPoi&id='.$this->item->id.'&tmpl=component'; //$bar->appendButton('Popup', 'print', 'JTOOLBAR_EXPORT', $url); } if (empty($this->item->id)) { JToolBarHelper::cancel('poi.cancel', 'JTOOLBAR_CANCEL'); } else { JToolBarHelper::cancel('poi.cancel', 'JTOOLBAR_CLOSE'); } }
/** * Method to get the record form. * * @param array $data An optional array of data for the form to interogate. * @param boolean $loadData True if the form is to load its own data (default case), false if not. * @return JForm A JForm object on success, false on failure * @since 1.6 */ public function getForm($data = array(), $loadData = true) { // Initialise variables. $app = JFactory::getApplication(); // Get the form. $form = $this->loadForm('com_citybranding.log', 'log', array('control' => 'jform', 'load_data' => $loadData)); if (empty($form)) { return false; } $canDo = CitybrandingHelper::getActions(); $canManageLogs = $canDo->get('citybranding.manage.logs'); if (!$canManageLogs) { //TODO: This alert to be moved on view echo '<div class="alert alert-info"><button type="button" class="close" data-dismiss="alert">×</button>' . JText::_('COM_CITYBRANDING_ACTION_ALERT') . '</div>'; // Disable fields for display. $form->setFieldAttribute('state', 'disabled', 'true'); $form->setFieldAttribute('stepid', 'disabled', 'true'); $form->setFieldAttribute('poiid', 'disabled', 'true'); $form->setFieldAttribute('action', 'disabled', 'true'); $form->setFieldAttribute('description', 'disabled', 'true'); } return $form; }
/** * Build an SQL query to load the list data. * * @return JDatabaseQuery * @since 1.6 */ protected function getListQuery() { $user = JFactory::getUser(); // Create a new query object. $db = $this->getDbo(); $query = $db->getQuery(true); // Select the required fields from the table. $query->select($this->getState('list.select', 'DISTINCT a.*')); $query->from('`#__citybranding_pois` AS a'); // Join over the users for the checked out user $query->select("uc.name AS editor"); $query->join("LEFT", "#__users AS uc ON uc.id=a.checked_out"); // Join over the category 'catid' $query->select('catid.title AS catid_title'); $query->join('LEFT', '#__categories AS catid ON catid.id = a.catid'); // Join over the user field 'created_by' $query->select('created_by.name AS created_by'); $query->join('LEFT', '#__users AS created_by ON created_by.id = a.created_by'); // Join over the asset groups. $query->select('ag.title AS access_level')->join('LEFT', '#__viewlevels AS ag ON ag.id = a.access'); // Join over the citybranding steps. $query->select('st.title AS stepid_title, st.stepcolor AS stepid_color')->join('LEFT', '#__citybranding_steps AS st ON st.id = a.stepid'); // Filter by published state $published = $this->getState('filter.state'); if (is_numeric($published)) { $query->where('a.state = ' . (int) $published); } else { if ($published === '') { $query->where('(a.state IN (0, 1))'); } } // Filter by search in title $search = $this->getState('filter.search'); if (!empty($search)) { if (stripos($search, 'id:') === 0) { $query->where('a.id = ' . (int) substr($search, 3)); } else { $search = $db->Quote('%' . $db->escape($search, true) . '%'); $query->where('( a.title LIKE ' . $search . ' OR a.address LIKE ' . $search . ' )'); } } // Filter by access level. if ($access = $this->getState('filter.access')) { $query->where('a.access = ' . (int) $access); } // Implement View Level Access if (!$user->authorise('core.admin')) { $groups = implode(',', $user->getAuthorisedViewLevels()); $query->where('a.access IN (' . $groups . ')'); } //Filtering stepid if ($stepid = $this->getState('filter.stepid')) { $query->where('a.stepid = ' . (int) $stepid); } //Filtering catid $filter_catid = $this->state->get("filter.catid"); if ($filter_catid) { $query->where("a.catid = '" . $db->escape($filter_catid) . "'"); } //Filtering by category usergroups except if access citybranding.showall.pois = true $canDo = CitybrandingHelper::getActions(); $canShowAllPois = $canDo->get('citybranding.showall.pois'); if (!$canShowAllPois) { require_once JPATH_COMPONENT . '/helpers/citybranding.php'; $allowed_catids = CitybrandingHelper::getCategoriesByUserGroups(); $allowed_catids = implode(',', $allowed_catids); if (!empty($allowed_catids)) { $query->where('a.catid IN (' . $allowed_catids . ')'); } else { //show nothing $query->where('a.catid = -1'); } } //Filtering by subgroup $filter_subgroup = $this->state->get("filter.subgroup"); if ($filter_subgroup) { $query->where("a.subgroup = '" . $db->escape($filter_subgroup) . "'"); } // Add the list ordering clause. $orderCol = $this->state->get('list.ordering'); $orderDirn = $this->state->get('list.direction'); if ($orderCol == 'access_level') { $orderCol = 'ag.title'; } if ($orderCol && $orderDirn) { $query->order($db->escape($orderCol . ' ' . $orderDirn)); } return $query; }
/** * Add the page title and toolbar. * * @since 1.6 */ protected function addToolbar() { if (!$this->canManageSteps) { JToolBarHelper::title(JText::_('COM_CITYBRANDING_TITLE_STEPS'), 'drawer-2'); //JToolBarHelper::back(); $bar = JToolBar::getInstance('toolbar'); $bar->appendButton('Link', 'leftarrow', 'COM_CITYBRANDING_BACK', JRoute::_('index.php?option=com_citybranding', false)); return; } require_once JPATH_COMPONENT . '/helpers/citybranding.php'; $state = $this->get('State'); $canDo = CitybrandingHelper::getActions($state->get('filter.category_id')); JToolBarHelper::title(JText::_('COM_CITYBRANDING_TITLE_STEPS'), 'drawer-2'); //Check if the form exists before showing the add/edit buttons $formPath = JPATH_COMPONENT_ADMINISTRATOR . '/views/step'; if (file_exists($formPath)) { if ($canDo->get('core.create')) { JToolBarHelper::addNew('step.add', 'JTOOLBAR_NEW'); } if ($canDo->get('core.edit') && isset($this->items[0])) { JToolBarHelper::editList('step.edit', 'JTOOLBAR_EDIT'); } } if ($canDo->get('core.edit.state')) { if (isset($this->items[0]->state)) { JToolBarHelper::divider(); JToolBarHelper::custom('steps.publish', 'publish.png', 'publish_f2.png', 'JTOOLBAR_PUBLISH', true); JToolBarHelper::custom('steps.unpublish', 'unpublish.png', 'unpublish_f2.png', 'JTOOLBAR_UNPUBLISH', true); } else { if (isset($this->items[0])) { //If this component does not use state then show a direct delete button as we can not trash JToolBarHelper::deleteList('', 'steps.delete', 'JTOOLBAR_DELETE'); } } if (isset($this->items[0]->state)) { JToolBarHelper::divider(); JToolBarHelper::archiveList('steps.archive', 'JTOOLBAR_ARCHIVE'); } if (isset($this->items[0]->checked_out)) { JToolBarHelper::custom('steps.checkin', 'checkin.png', 'checkin_f2.png', 'JTOOLBAR_CHECKIN', true); } } //Show trash and delete for components that uses the state field if (isset($this->items[0]->state)) { if ($state->get('filter.state') == -2 && $canDo->get('core.delete')) { JToolBarHelper::deleteList('', 'steps.delete', 'JTOOLBAR_EMPTY_TRASH'); JToolBarHelper::divider(); } else { if ($canDo->get('core.edit.state')) { JToolBarHelper::trash('steps.trash', 'JTOOLBAR_TRASH'); JToolBarHelper::divider(); } } } if ($canDo->get('core.admin')) { JToolBarHelper::preferences('com_citybranding'); } //Set sidebar action - New in 3.0 JHtmlSidebar::setAction('index.php?option=com_citybranding&view=steps'); $this->extra_sidebar = ''; JHtmlSidebar::addFilter(JText::_('JOPTION_SELECT_PUBLISHED'), 'filter_published', JHtml::_('select.options', JHtml::_('jgrid.publishedOptions'), "value", "text", $this->state->get('filter.state'), true)); }
/** * Add the page title and toolbar. * * @since 1.6 */ protected function addToolbar() { require_once JPATH_COMPONENT . '/helpers/citybranding.php'; $state = $this->get('State'); $canDo = CitybrandingHelper::getActions($state->get('filter.category_id')); JToolBarHelper::title(JText::_('COM_CITYBRANDING_TITLE_VOTES'), 'votes.png'); //Check if the form exists before showing the add/edit buttons $formPath = JPATH_COMPONENT_ADMINISTRATOR . '/views/vote'; if (file_exists($formPath)) { if ($canDo->get('core.create')) { JToolBarHelper::addNew('vote.add', 'JTOOLBAR_NEW'); } if ($canDo->get('core.edit') && isset($this->items[0])) { JToolBarHelper::editList('vote.edit', 'JTOOLBAR_EDIT'); } } if ($canDo->get('core.edit.state')) { if (isset($this->items[0]->state)) { JToolBarHelper::divider(); JToolBarHelper::custom('votes.publish', 'publish.png', 'publish_f2.png', 'JTOOLBAR_PUBLISH', true); JToolBarHelper::custom('votes.unpublish', 'unpublish.png', 'unpublish_f2.png', 'JTOOLBAR_UNPUBLISH', true); } else { if (isset($this->items[0])) { //If this component does not use state then show a direct delete button as we can not trash JToolBarHelper::deleteList('', 'votes.delete', 'JTOOLBAR_DELETE'); } } if (isset($this->items[0]->state)) { JToolBarHelper::divider(); JToolBarHelper::archiveList('votes.archive', 'JTOOLBAR_ARCHIVE'); } if (isset($this->items[0]->checked_out)) { JToolBarHelper::custom('votes.checkin', 'checkin.png', 'checkin_f2.png', 'JTOOLBAR_CHECKIN', true); } } //Show trash and delete for components that uses the state field if (isset($this->items[0]->state)) { if ($state->get('filter.state') == -2 && $canDo->get('core.delete')) { JToolBarHelper::deleteList('', 'votes.delete', 'JTOOLBAR_EMPTY_TRASH'); JToolBarHelper::divider(); } else { if ($canDo->get('core.edit.state')) { JToolBarHelper::trash('votes.trash', 'JTOOLBAR_TRASH'); JToolBarHelper::divider(); } } } if ($canDo->get('core.admin')) { JToolBarHelper::preferences('com_citybranding'); } //Set sidebar action - New in 3.0 JHtmlSidebar::setAction('index.php?option=com_citybranding&view=votes'); $this->extra_sidebar = ''; //Filter for the field ".poiid; jimport('joomla.form.form'); $options = array(); JForm::addFormPath(JPATH_COMPONENT . '/models/forms'); $form = JForm::getInstance('com_citybranding.vote', 'vote'); $field = $form->getField('poiid'); $query = $form->getFieldAttribute('filter_poiid', 'query'); $translate = $form->getFieldAttribute('filter_poiid', 'translate'); $key = $form->getFieldAttribute('filter_poiid', 'key_field'); $value = $form->getFieldAttribute('filter_poiid', 'value_field'); // Get the database object. $db = JFactory::getDBO(); // Set the query and get the result list. $db->setQuery($query); $items = $db->loadObjectlist(); // Build the field options. if (!empty($items)) { foreach ($items as $item) { if ($translate == true) { $options[] = JHtml::_('select.option', $item->{$key}, JText::_($item->{$value})); } else { $options[] = JHtml::_('select.option', $item->{$key}, $item->{$value}); } } } JHtmlSidebar::addFilter('Poi', 'filter_poiid', JHtml::_('select.options', $options, "value", "text", $this->state->get('filter.poiid')), true); JHtmlSidebar::addFilter(JText::_('JOPTION_SELECT_PUBLISHED'), 'filter_published', JHtml::_('select.options', JHtml::_('jgrid.publishedOptions'), "value", "text", $this->state->get('filter.state'), true)); }
/** * Add the page title and toolbar. * * @since 1.6 */ protected function addToolbar() { require_once JPATH_COMPONENT . '/helpers/citybranding.php'; $state = $this->get('State'); $canDo = CitybrandingHelper::getActions($state->get('filter.category_id')); JToolBarHelper::title(JText::_('COM_CITYBRANDING_TITLE_POIS'), 'drawer'); //Check if the form exists before showing the add/edit buttons $formPath = JPATH_COMPONENT_ADMINISTRATOR . '/views/poi'; if (file_exists($formPath)) { if ($canDo->get('core.create')) { JToolBarHelper::addNew('poi.add', 'JTOOLBAR_NEW'); } if ($canDo->get('core.edit') && isset($this->items[0])) { JToolBarHelper::editList('poi.edit', 'JTOOLBAR_EDIT'); } } if ($canDo->get('core.edit.state')) { if (isset($this->items[0]->state)) { JToolBarHelper::divider(); JToolBarHelper::custom('pois.publish', 'publish.png', 'publish_f2.png', 'JTOOLBAR_PUBLISH', true); JToolBarHelper::custom('pois.unpublish', 'unpublish.png', 'unpublish_f2.png', 'JTOOLBAR_UNPUBLISH', true); } else { if (isset($this->items[0])) { //If this component does not use state then show a direct delete button as we can not trash JToolBarHelper::deleteList('', 'pois.delete', 'JTOOLBAR_DELETE'); } } if (isset($this->items[0]->state)) { JToolBarHelper::divider(); JToolBarHelper::archiveList('pois.archive', 'JTOOLBAR_ARCHIVE'); } if (isset($this->items[0]->checked_out)) { JToolBarHelper::custom('pois.checkin', 'checkin.png', 'checkin_f2.png', 'JTOOLBAR_CHECKIN', true); } } //Show trash and delete for components that uses the state field if (isset($this->items[0]->state)) { if ($state->get('filter.state') == -2 && $canDo->get('core.delete')) { JToolBarHelper::deleteList('', 'pois.delete', 'JTOOLBAR_EMPTY_TRASH'); JToolBarHelper::divider(); } else { if ($canDo->get('core.edit.state')) { JToolBarHelper::trash('pois.trash', 'JTOOLBAR_TRASH'); JToolBarHelper::divider(); } } } if ($canDo->get('core.admin')) { JToolBarHelper::preferences('com_citybranding'); } //Set sidebar action - New in 3.0 JHtmlSidebar::setAction('index.php?option=com_citybranding&view=pois'); $this->extra_sidebar = ''; JHtmlSidebar::addFilter(JText::_("JOPTION_SELECT_CATEGORY"), 'filter_catid', JHtml::_('select.options', JHtml::_('category.options', 'com_citybranding'), "value", "text", $this->state->get('filter.catid'))); //Get custom field JFormHelper::addFieldPath(JPATH_ROOT . '/components/com_citybranding/models/fields'); $steps = JFormHelper::loadFieldType('Step', false); $options = $steps->getOptions(); JHtmlSidebar::addFilter(JText::_("COM_CITYBRANDING_POIS_STEPID_FILTER"), 'filter_stepid', JHtml::_('select.options', $options, "value", "text", $this->state->get('filter.stepid'), true)); JHtmlSidebar::addFilter(JText::_('JOPTION_SELECT_PUBLISHED'), 'filter_published', JHtml::_('select.options', JHtml::_('jgrid.publishedOptions'), "value", "text", $this->state->get('filter.state'), true)); }
private static function loadCats($cats = array()) { if (is_array($cats)) { foreach ($cats as $JCatNode) { $params = json_decode($JCatNode->params); if (isset($params->citybranding_category_usergroup)) { $usergroups = $params->citybranding_category_usergroup; } else { $usergroups = array(); } self::$catIds[] = array('catid' => $JCatNode->id, 'usergroups' => $usergroups); if ($JCatNode->hasChildren()) { CitybrandingHelper::loadCats($JCatNode->getChildren()); } } } return false; }