Ejemplo n.º 1
0
 /**
  * Get search results objects for module by Id
  *
  * @param array : the results score ids
  * @return array : results elements (cms_page)
  * @access public
  */
 function getSearchResults($resultsIds, &$user)
 {
     if (!$resultsIds || !is_array($resultsIds)) {
         return array();
     }
     $cms_language = $user->getLanguage();
     //get results object types
     $sql = "\n\t\t\tselect\n\t\t\t\tobject_type_id_moo as type, id_moo as id\n\t\t\tfrom\n\t\t\t\tmod_object_polyobjects\n\t\t\twhere\n\t\t\t\tid_moo in (" . sensitiveIO::sanitizeSQLString(implode(',', $resultsIds)) . ")\n\t\t";
     $q = new CMS_query($sql);
     $resultsType = array();
     while ($r = $q->getArray()) {
         $resultsType[$r['type']][] = $r['id'];
     }
     $results = array();
     foreach ($resultsType as $type => $ids) {
         //load current object definition
         $object = CMS_poly_object_catalog::getObjectDefinition($type);
         //create search object for current object
         $search = new CMS_object_search($object);
         $search->addWhereCondition("items", $ids);
         $search->search(CMS_object_search::POLYMOD_SEARCH_RETURN_INDIVIDUALS_OBJECTS);
         //launch search
         $objectLabel = $object->getLabel($cms_language);
         // Check if need to use a specific display for search results
         $resultsDefinition = $object->getValue('resultsDefinition');
         if ($resultsDefinition) {
             $definitionParsing = new CMS_polymod_definition_parsing($resultsDefinition, true, CMS_polymod_definition_parsing::PARSE_MODE);
             $itemsResourcesFiles = '';
             // Add specific css and js files we use the resultsDefinition
             if (file_exists(PATH_CSS_FS . '/modules/' . $this->getCodename() . '.css')) {
                 $itemsResourcesFiles .= '<link rel="stylesheet" type="text/css" href="' . PATH_CSS_WR . '/modules/' . $this->getCodename() . '.css" />';
             }
             $jsFiles = $this->getJSFiles();
             if ($jsFiles) {
                 foreach ($jsFiles as $jsfile) {
                     $itemsResourcesFiles .= '<script type="text/javascript" src="' . $jsfile . '"></script>' . "\n";
                 }
             }
         } else {
             //load fields objects for object
             $objectFields = CMS_poly_object_catalog::getFieldsDefinition($object->getID());
         }
         //loop on results items
         while ($item = $search->getNextResult()) {
             //Resource related informations
             $htmlStatus = $pubRange = '';
             $lock = $deleted = $primaryResource = false;
             if ($object->isPrimaryResource()) {
                 $status = $item->getStatus();
                 if (is_object($status)) {
                     $htmlStatus = $status->getHTML(false, $user, $this->getCodename(), $item->getID());
                     $pubRange = $status->getPublicationRange($cms_language);
                     $lock = $item->getLock();
                     $deleted = $item->getProposedLocation() == RESOURCE_LOCATION_DELETED;
                 }
                 $primaryResource = true;
             }
             //Edit
             $edit = false;
             if (!$deleted && (!$lock || $lock == $user->getUserId())) {
                 $edit = array('url' => PATH_ADMIN_MODULES_WR . '/' . MOD_POLYMOD_CODENAME . '/item.php', 'type' => 'window', 'params' => array('module' => $this->getCodename(), 'type' => $type, 'item' => $item->getID()));
             }
             //Previz
             $view = false;
             if ($object->getValue("previewURL")) {
                 $view = array('url' => $item->getPrevizPageURL(), 'type' => 'frame');
             }
             //HTML description
             $description = POLYMOD_DEBUG ? '<span class="atm-text-alert"> (ID : ' . $item->getID() . ')</span>' : '';
             if ($resultsDefinition) {
                 //set execution parameters
                 $parameters = array();
                 $parameters['module'] = $this->getCodename();
                 $parameters['objectID'] = $object->getID();
                 $parameters['public'] = false;
                 $parameters['item'] = $item;
                 $description .= $definitionParsing->getContent(CMS_polymod_definition_parsing::OUTPUT_RESULT, $parameters);
                 if ($itemsResourcesFiles) {
                     $description = $itemsResourcesFiles . $description;
                 }
             } else {
                 $itemFieldsObjects = $item->getFieldsObjects();
                 //Add all needed fields to description
                 foreach ($itemFieldsObjects as $fieldID => $itemField) {
                     //if field is a poly object
                     if ($objectFields[$fieldID]->getValue('searchlist')) {
                         $description .= $objectFields[$fieldID]->getLabel($cms_language) . ' : <strong>' . $itemField->getHTMLDescription() . '</strong><br />';
                     }
                 }
             }
             $results[$item->getID()] = array('id' => $item->getID(), 'type' => $objectLabel, 'status' => $htmlStatus, 'pubrange' => $pubRange, 'label' => $item->getLabel(), 'description' => $description, 'resource' => $primaryResource ? array('module' => $this->getCodename(), 'resource' => $item->getID(), 'action' => 'unlock') : false, 'edit' => $edit, 'view' => $view);
         }
     }
     return $results;
 }
Ejemplo n.º 2
0
    if (CMS_session::getSessionVar('sort_' . $object->getID())) {
        $search->addOrderCondition(CMS_session::getSessionVar('sort_' . $object->getID()), CMS_session::getSessionVar('direction_' . $object->getID()));
    } else {
        $search->addOrderCondition('objectID', CMS_session::getSessionVar('direction_' . $object->getID()));
    }
}
//launch search
$search->search(CMS_object_search::POLYMOD_SEARCH_RETURN_INDIVIDUALS_OBJECTS);
// Vars for lists output purpose and pages display, see further
$itemsDatas['total'] = $search->getNumRows();
//Get parsed result definition
if ($resultsDefinition) {
    $definitionParsing = new CMS_polymod_definition_parsing($resultsDefinition, true, CMS_polymod_definition_parsing::PARSE_MODE);
}
//loop on results items
while ($item = $search->getNextResult()) {
    //Process actions on item if any
    //Unlock item
    if ($unlock && $object->isPrimaryResource()) {
        $item->unlock();
    }
    //Delete item
    if ($delete) {
        $item->delete();
        if (!$object->isPrimaryResource()) {
            unset($item);
            $itemsDatas['total']--;
            continue;
        }
    }
    //Undelete item
Ejemplo n.º 3
0
 /**
  * Return a list of all objects names of given type
  *
  * @param mixed $objectID the object ID to get names (integer or 'multi|objectID')
  * @param boolean $public are the needed datas public ? (default false)
  * @param array $searchConditions, search conditions to add. Format : array(conditionType => conditionValue)
  * @return array(integer objectID => string objectName)
  * @access public
  * @static
  */
 static function getListOfNamesForObject($objectID, $public = false, $searchConditions = array(), $loadSubObjects = false)
 {
     static $listNames;
     $paramsHash = md5(serialize(func_get_args()));
     if (isset($listNames[$paramsHash])) {
         return $listNames[$paramsHash];
     }
     $listNames[$paramsHash] = array();
     //load current object definition
     $object = CMS_poly_object_catalog::getObjectDefinition($objectID);
     //create search
     $search = new CMS_object_search($object, $public);
     //add conditions
     if (is_array($searchConditions) && $searchConditions) {
         foreach ($searchConditions as $conditionType => $conditionValue) {
             $search->addWhereCondition($conditionType, $conditionValue);
         }
     }
     //launch search
     $search->search(CMS_object_search::POLYMOD_SEARCH_RETURN_INDIVIDUALS_OBJECTS);
     //set result mode
     $mode = $loadSubObjects ? CMS_object_search::POLYMOD_SEARCH_RETURN_OBJECTS : CMS_object_search::POLYMOD_SEARCH_RETURN_OBJECTSLIGHT_EDITED;
     //fetch results
     while ($item = $search->getNextResult($mode)) {
         $listNames[$paramsHash][$item->getID()] = $item->getLabel();
     }
     //natsort objects by name case insensitive
     uasort($listNames[$paramsHash], array('CMS_poly_object_catalog', '_natecasecomp'));
     return $listNames[$paramsHash];
 }