示例#1
0
 /**
  * @param   int $contactid	The contact item id
  */
 public static function association($contactid)
 {
     // Get the associations
     $associations = ContactHelper::getAssociations($contactid);
     foreach ($associations as $tag => $associated) {
         $associations[$tag] = (int) $associated->id;
     }
     // Get the associated contact items
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     $query->select('c.*');
     $query->from('#__contact_details as c');
     $query->select('cat.title as category_title');
     $query->leftJoin('#__categories as cat ON cat.id=c.catid');
     $query->where('c.id IN (' . implode(',', array_values($associations)) . ')');
     $query->leftJoin('#__languages as l ON c.language=l.lang_code');
     $query->select('l.image');
     $query->select('l.title as language_title');
     $db->setQuery($query);
     $items = $db->loadObjectList('id');
     // Check for a database error.
     if ($error = $db->getErrorMsg()) {
         JError::raiseWarning(500, $error);
         return false;
     }
     // Construct html
     $text = array();
     foreach ($associations as $tag => $associated) {
         if ($associated != $contactid) {
             $text[] = JText::sprintf('COM_CONTACT_TIP_ASSOCIATED_LANGUAGE', JHtml::_('image', 'mod_languages/' . $items[$associated]->image . '.gif', $items[$associated]->language_title, array('title' => $items[$associated]->language_title), true), $items[$associated]->name, $items[$associated]->category_title);
         }
     }
     return JHtml::_('tooltip', implode('<br />', $text), JText::_('COM_CONTACT_TIP_ASSOCIATION'), 'admin/icon-16-links.png');
 }
 /**
  * Method to get the associations for a given item
  *
  * @param   integer  $id    Id of the item
  * @param   string   $view  Name of the view
  *
  * @return  array   Array of associations for the item
  *
  * @since  3.0
  */
 public static function getAssociations($id = 0, $view = null)
 {
     jimport('helper.route', JPATH_COMPONENT_SITE);
     $app = JFactory::getApplication();
     $jinput = $app->input;
     $view = is_null($view) ? $jinput->get('view') : $view;
     $id = empty($id) ? $jinput->getInt('id') : $id;
     if ($view == 'contact') {
         if ($id) {
             $associations = ContactHelper::getAssociations($id);
             $return = array();
             foreach ($associations as $tag => $item) {
                 $return[$tag] = ContactHelperRoute::getContactRoute($item->id, $item->catid, $item->language);
             }
             return $return;
         }
     }
     if ($view == 'category' || $view == 'categories') {
         return self::getCategoryAssociations($id, 'com_contact');
     }
     return array();
 }
示例#3
0
 /**
  * Method to get a single record.
  *
  * @param   integer	$pk	The id of the primary key.
  *
  * @return  mixed  Object on success, false on failure.
  * @since   1.6
  */
 public function getItem($pk = null)
 {
     if ($item = parent::getItem($pk)) {
         // Convert the params field to an array.
         $registry = new JRegistry();
         $registry->loadString($item->metadata);
         $item->metadata = $registry->toArray();
     }
     // Load associated contact items
     $app = JFactory::getApplication();
     $assoc = isset($app->item_associations) ? $app->item_associations : 0;
     if ($assoc) {
         $item->associations = array();
         if ($item->id != null) {
             $associations = ContactHelper::getAssociations($item->id);
             foreach ($associations as $tag => $association) {
                 $item->associations[$tag] = $association->id;
             }
         }
     }
     return $item;
 }