示例#1
0
 /**
  * Content Search method
  * The sql must return the following fields that are used in a common display
  * routine: href, title, section, created, text, browsernav
  * @param string Target search string
  * @param string mathcing option, exact|any|all
  * @param string ordering option, newest|oldest|popular|alpha|category
  * @param mixed An array if the search it to be restricted to areas, null if search all
  */
 function onContentSearch($text, $phrase = '', $ordering = '', $areas = null, $categories = null, $fieldsfilter = null, $limit = 50)
 {
     if (is_array($categories)) {
         $categories = implode(",", $categories);
     }
     $results = array();
     $db = JFactory::getDbo();
     $app = JFactory::getApplication();
     $user = JFactory::getUser();
     $groups = implode(',', $user->getAuthorisedViewLevels());
     $tag = JFactory::getLanguage()->getTag();
     require_once JPATH_SITE . '/components/com_content/helpers/route.php';
     require_once JPATH_SITE . '/administrator/components/com_search/helpers/search.php';
     $sContent = $this->params->get('search_content', 1);
     $sArchived = $this->params->get('search_archived', 1);
     $limit = $this->params->def('search_limit2', 200);
     $ordering = $this->params->def('ordering', "");
     $menuitemid = JRequest::getInt('Itemid');
     if ($menuitemid) {
         $menu = JSite::getMenu();
         $menuparams = $menu->getParams($menuitemid);
         //echo $menuparams;
         $params = new JRegistry($menuparams);
         $params->merge($menuparams);
     } else {
         //If not menu associate search menu
         $params = new JRegistry();
         JError::raiseWarning(100, JText::_("MOD_FIELDSATTACHSEARCH_ERROR_LINK_MENU"));
     }
     $ordering = $params->get('ordering');
     $rules = $params->get('paramrules');
     $condition = $params->get('conditionmode', "OR");
     $linkconditions = $params->get('paramlinkconditions');
     $linkconditionsarray = explode(",", $linkconditions);
     $nullDate = $db->getNullDate();
     $date = JFactory::getDate();
     $wheres = array();
     $morder = '';
     switch ($ordering) {
         case 'oldest':
             $order = '5 ASC';
             break;
         case 'alpha':
             $order = '2 ASC';
             break;
         case 'category':
             $order = '10 ASC, 2 ASC';
             $morder = '2 ASC';
             break;
         case 'newest':
         default:
             $order = '5 DESC';
             break;
     }
     //
     /*
     if(count($orderidtmp)==2){
         if(is_numeric($orderidtmp[0]))
         {
           $order = '14 '.$orderidtmp[1];
     		      $specialSort = true; 
         }
     }else{
         if(is_numeric($orderidtmp[0]))
         {
           $order = '14 ';
     		      $specialSort = true; 
         }
     }
     */
     $rows = array();
     $query = $db->getQuery(true);
     $query2 = $db->getQuery(true);
     $specialSort = false;
     //QUERY GENERAL
     $query = plgAdvancedsearchfieldsattachment::getQuerySorted($text, $phrase, $order, $areas, $categories, $fieldsfilter, $limit, "", "", "", $rules);
     //echo "<br><br>".$query;
     $db->setQuery($query, 0, $limit);
     $list = $db->loadObjectList();
     //GET LINK URL
     $limit -= count($list);
     if (isset($list)) {
         foreach ($list as $key => $item) {
             $list[$key]->href = ContentHelperRoute::getArticleRoute($item->slug, $item->catslug);
         }
     }
     //Determine num of filter *******
     $maxnumfilters = 0;
     //echo "<br>--->".$fieldsfilter."<br>";
     $arrayfieldsid = explode(",", $fieldsfilter);
     foreach ($arrayfieldsid as $fieldsid) {
         $tmp1 = explode("_", $fieldsid);
         $tmpfieldid = $tmp1[0];
         $valuefieldid = "";
         if (count($tmp1) > 1) {
             $valuefieldid = $tmp1[1];
         }
         if (!empty($valuefieldid)) {
             $maxnumfilters++;
         }
     }
     $fieldsarray = array();
     //Build a array with all fieldsattach an ID *********************************
     //Example COL: 	articleId,  total, 	field1id, 	field2id, 	field3id
     //		2, 		2	Valor1, 	Valor2, 	Valor3
     //		3, 		2 	Valor12, 	Valor22, 	Valor33
     //***************************************************************************
     if (isset($list)) {
         //Build
         foreach ($list as $key => $item) {
             $fieldsarray[$item->id]->{'fields_' . $item->fieldsid} = $item->value;
             if (isset($fieldsarray[$item->id]->total)) {
                 $fieldsarray[$item->id]->total = $fieldsarray[$item->id]->total + 1;
             } else {
                 $fieldsarray[$item->id]->total = 1;
             }
         }
         //DELETE FILTER IF AND
         if ($condition == "AND") {
             foreach ($fieldsarray as $key => $item) {
                 if ($item->total < $maxnumfilters) {
                     unset($fieldsarray[$key]);
                 }
             }
         }
         //print_r($fieldsarray);
         //ADD Others extra fields
         foreach ($fieldsarray as $key => $item) {
             //echo "<br>--------------<br>KEY: ->".$key;
             foreach ($arrayfieldsid as $fieldsid) {
                 //echo "<br>REPASAR: ->".$fieldsid;
                 $tmp1 = explode("_", $fieldsid);
                 $tmpfieldid = $tmp1[0];
                 if (!isset($fieldsarray[$key]->{'fields_' . $tmpfieldid})) {
                     //echo "<br>CREATE::: ".$key.' -> fields_'.$tmpfieldid;
                     $fieldsarray[$key]->{'fields_' . $tmpfieldid} = "";
                 }
             }
             //echo "<br>******************<br>";
         }
         //print_r($fieldsarray);
         //ADD PROPIETIES TO ARRAY OBJECTS
         foreach ($fieldsarray as $key => $item) {
             foreach ($list as $key2 => $item2) {
                 if ($item2->id == $key) {
                     foreach ($item2 as $key3 => $item3) {
                         $fieldsarray[$key]->{$key3} = $item3;
                     }
                 }
             }
         }
     }
     $tmp = array();
     foreach ($fieldsarray as $key => $item) {
         if (!empty($item->id)) {
             $tmp[] = $item;
         }
     }
     $fieldsarray = $tmp;
     //echo count($fieldsarray)." ---- cc";
     /*
     		for($cont=0; count($fieldsarray)>$cont; $cont++)
     		{
     			echo "<br>".$cont." --> ".$fieldsarray[$cont]->id." ".$fieldsarray[$cont]->fields_10;
     		}
     */
     $orderidtmp = explode(" ", $ordering);
     if (is_numeric($orderidtmp[0])) {
         //Recovery all data of $orderidtmp
         $allvalues = plgAdvancedsearchfieldsattachment::getQueryFiedsvalue($orderidtmp[0]);
         //ADD PROPIETIES TO ARRAY OBJECTS
         foreach ($fieldsarray as $key => $item) {
             foreach ($allvalues as $key2 => $item2) {
                 //echo "<br>AÑADIR".$item2->articleid." == ".$item->id;
                 if ($item2->articleid == $item->id) {
                     //echo "<br>AÑADIR".$key;
                     $fieldsarray[$key]->{"fields_" . $orderidtmp[0]} = $item2->value;
                 }
             }
         }
         //print_r($fieldsarray);
         $propertyvar = "fields_" . $orderidtmp[0];
         //echo "<br>PROPERTY:: ".$propertyvar."<br>";
         $fieldsarray = plgAdvancedsearchfieldsattachment::sortArrayofObjectByProperty($fieldsarray, $propertyvar);
         if (count($orderidtmp) > 1) {
             if ($orderidtmp[1] == "DESC") {
                 $fieldsarray = array_reverse($fieldsarray, true);
             }
         }
     }
     $results = $fieldsarray;
     JRequest::setVar("option", "com_content");
     return $results;
 }
 /**
  * Content Search method
  * The sql must return the following fields that are used in a common display
  * routine: href, title, section, created, text, browsernav
  * @param string Target search string
  * @param string mathcing option, exact|any|all
  * @param string ordering option, newest|oldest|popular|alpha|category
  * @param mixed An array if the search it to be restricted to areas, null if search all
  */
 function onContentSearch($text, $phrase = '', $ordering = '', $areas = null, $categories = null, $fieldsfilter = null, $limit = 50)
 {
     if (is_array($categories)) {
         $categories = implode(",", $categories);
     }
     $results = array();
     $db = JFactory::getDbo();
     $app = JFactory::getApplication();
     $user = JFactory::getUser();
     $groups = implode(',', $user->getAuthorisedViewLevels());
     $tag = JFactory::getLanguage()->getTag();
     require_once JPATH_SITE . '/components/com_content/helpers/route.php';
     require_once JPATH_SITE . '/administrator/components/com_search/helpers/search.php';
     $sContent = $this->params->get('search_content', 1);
     $sArchived = $this->params->get('search_archived', 1);
     $limit = $this->params->def('search_limit2', 200);
     $ordering = $this->params->def('ordering', "");
     $menuitemid = JRequest::getInt('Itemid');
     if ($menuitemid) {
         $menu = JSite::getMenu();
         $menuparams = $menu->getParams($menuitemid);
         //echo $menuparams;
         $params = new JRegistry($menuparams);
         $params->merge($menuparams);
     } else {
         //If not menu associate search menu
         $params = new JRegistry();
         JError::raiseWarning(100, JText::_("MOD_FIELDSATTACHSEARCH_ERROR_LINK_MENU"));
     }
     $ordering = $params->get('ordering');
     $rules = $params->get('paramrules');
     //$condition		= $params->get('conditionmode',		"OR");
     $linkconditions = $params->get('paramlinkconditions');
     $linkconditionsarray = explode(",", $linkconditions);
     $nullDate = $db->getNullDate();
     $date = JFactory::getDate();
     $wheres = array();
     $morder = '';
     switch ($ordering) {
         case 'oldest':
             $order = 'created ASC';
             break;
         case 'popular':
             $order = 'hits DESC';
             break;
         case 'alpha':
             $order = 'title ASC';
             break;
         case 'category':
             $order = 'title ASC, title ASC';
             break;
         case 'newest':
         default:
             $order = 'created DESC';
             break;
     }
     //echo "ORDER:: ".$ordering;
     /*switch ($ordering) {
     			case 'oldest':
     				$order = '5 ASC';
     				break;
     
     			 
     
     			case 'alpha':
     				$order = '2 ASC';
     				break;
     
     			case 'category':
     				$order = '10 ASC, 2 ASC';
     				$morder = '2 ASC';
     				break;
     
     			case 'newest':
                             default :
     				$order = '5 DESC';
     				break;
     		}*/
     $rows = array();
     $query = $db->getQuery(true);
     //QUERY GENERAL
     $query = plgAdvancedsearchfieldsattachment::getQuerySorted($text, $phrase, $order, $areas, $categories, $fieldsfilter, $limit, "", "", "", $rules);
     //echo "<br><br>".$query;
     $db->setQuery($query, 0, $limit);
     //$db->setQuery($query);
     $results = $db->loadObjectList();
     //HREF
     if (isset($results)) {
         foreach ($results as $key => $item) {
             $results[$key]->href = ContentHelperRoute::getArticleRoute($item->slug, $item->catslug);
         }
     }
     return $results;
 }