/** * Method to generate a link to the request diet page for the current user * * @param JRegistry $params The item parameters * @param array $attribs Optional attributes for the link * * @return string The HTML markup for the create item link */ public static function create($attribs = array()) { require_once JPATH_COMPONENT_SITE . '/controllers/request.php'; $controller = new SibdietControllerRequest(); if ($controller->allowAdd()) { JHtml::_('bootstrap.tooltip'); $uri = JUri::getInstance(); $url = 'index.php?option=com_sibdiet&task=request.add&return=' . base64_encode($uri) . '&r_id=0'; $text = '<span class="icon-plus"></span> ' . JText::_('COM_SIBDIET_REQUEST_NEW_DIET') . ' '; // Add the button classes to the attribs array if (isset($attribs['class'])) { $attribs['class'] = $attribs['class'] . ' btn btn-primary'; } else { $attribs['class'] = 'btn btn-primary'; } $output = JHtml::_('link', JRoute::_($url), $text, $attribs); return $output; } }
/** * Execute and display a template script. * * @param string $tpl The name of the template file to parse; automatically searches through the template paths. * * @return mixed A string if successful, otherwise a Error object. */ public function display($tpl = null) { $user = JFactory::getUser(); // Get model data. $this->state = $this->get('State'); $this->item = $this->get('Item'); $this->form = $this->get('Form'); $this->return_page = $this->get('ReturnPage'); $controller = new SibdietControllerRequest(); if (empty($this->item->id)) { $authorised = $controller->allowAdd(); } else { $authorised = $controller->allowEdit((array) $this->item); } if ($authorised !== true) { JError::raiseError(403, JText::_('JERROR_ALERTNOAUTHOR')); return false; } // Check for errors. if (count($errors = $this->get('Errors'))) { JError::raiseWarning(500, implode("\n", $errors)); return false; } // Check second time $db = JFactory::getDbo(); $query = $db->getQuery(true)->select('COUNT(s.id)')->from('#__sibdiet_setdiets s')->join('INNER', '#__sibdiet_profiles p ON (s.profiles_id = p.id)')->where('p.users_id = ' . $user->id); if (isset($this->item->id)) { $query->where('s.id <> ' . (int) $this->item->id); } $db->setQuery($query); $this->second_time = $db->loadResult(); // Create a shortcut to the parameters. $params =& $this->state->params; //Escape strings for HTML output $this->pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx')); $this->params = $params; $this->user = $user; $this->_prepareDocument(); parent::display($tpl); }