/** * Sort and limit found ids by orders and limit clauses * This method limit results to existant objects too * * @access private * @return array of object ids sorted */ protected function _sortIds() { $statusSuffix = $this->_public ? "_public" : "_edited"; $ids = array(); if ($this->_orderConditions) { //reverse order conditions (needed to get natural order) $orderConditions = array_reverse($this->_orderConditions, true); //loop on each order conditions foreach ($orderConditions as $type => $value) { $sql = ''; if (!isset($value['direction']) || !$value['direction']) { $value['direction'] = 'asc'; } if (!isset($value['operator']) || !$value['operator']) { $value['operator'] = ''; } $direction = $value['direction']; $operator = $value['operator']; //add previously found ids to where clause if (is_array($this->_resultsIds) && $this->_resultsIds) { //update tmp table with found ids $this->_updateTmpList($this->_resultsIds); $where = ' and objectID in (' . $this->_getSQLTmpList() . ')'; } else { $where = ''; } switch ($type) { case "publication date after": // Date start // Date start case "publication date before": // Date start // Date start case "publication date start": // Date start $sql = "\n\t\t\t\t\t\t\t\tselect\n\t\t\t\t\t\t\t\t\tdistinct objectID\n\t\t\t\t\t\t\t\tfrom\n\t\t\t\t\t\t\t\t\tmod_subobject_integer" . $statusSuffix . ",\n\t\t\t\t\t\t\t\t\tresources,\n\t\t\t\t\t\t\t\t\tresourceStatuses\n\t\t\t\t\t\t\t\twhere\n\t\t\t\t\t\t\t\t\tobjectFieldID = '0'\n\t\t\t\t\t\t\t\t\tand value = id_res\n\t\t\t\t\t\t\t\t\tand status_res=id_rs\n\t\t\t\t\t\t\t\t\t{$where}\n\t\t\t\t\t\t\t\torder by publicationDateStart_rs " . $direction; break; case "publication date end": // Date end $sql = "\n\t\t\t\t\t\t\t\tselect\n\t\t\t\t\t\t\t\t\tdistinct objectID\n\t\t\t\t\t\t\t\tfrom\n\t\t\t\t\t\t\t\t\tmod_subobject_integer" . $statusSuffix . ",\n\t\t\t\t\t\t\t\t\tresources,\n\t\t\t\t\t\t\t\t\tresourceStatuses\n\t\t\t\t\t\t\t\twhere\n\t\t\t\t\t\t\t\t\tobjectFieldID = '0'\n\t\t\t\t\t\t\t\t\tand value = id_res\n\t\t\t\t\t\t\t\t\tand status_res=id_rs\n\t\t\t\t\t\t\t\t\t{$where}\n\t\t\t\t\t\t\t\torder by publicationDateEnd_rs " . $direction; break; case 'objectID': $ids = $ids ? $ids : $this->_resultsIds; ksort($ids, SORT_NUMERIC); $ids = $direction == 'asc' ? $ids : array_reverse($ids, true); break; case 'itemsOrdered': $orderedIds = $direction == 'asc' ? $this->_orderConditions['itemsOrdered']['order'] : array_reverse($this->_orderConditions['itemsOrdered']['order'], true); $ids = array_intersect($orderedIds, $ids ? $ids : $this->_resultsIds); unset($orderedIds); break; case 'random': $tmpIds = $ids ? $ids : $this->_resultsIds; shuffle($tmpIds); $ids = array(); foreach ($tmpIds as $id) { $ids[$id] = $id; } break; case "relevance": //this order condition is replaced by an itemsOrdered order at the end of _getIds method break; default: if (sensitiveIO::isPositiveInteger($type)) { if (!isset($this->_fieldsDefinitions[$type]) || !is_object($this->_fieldsDefinitions[$type])) { //get object fields definition $this->_fieldsDefinitions = CMS_poly_object_catalog::getFieldsDefinition($this->_object->getID()); } if (isset($this->_fieldsDefinitions[$type])) { //get type object for field $objectField = $this->_fieldsDefinitions[$type]->getTypeObject(); $operator = isset($operator) ? $operator : ''; $sql = $objectField->getFieldOrderSQL($type, $direction, $operator, $where, $this->_public); } else { $this->raiseError('Unknown field ' . $type . ' to use as order with value ' . print_r($value, true)); } } break; } if ($sql) { if (isset($ids) && $ids) { $sql .= " , field(objectID, " . implode(',', array_reverse($ids)) . ") desc "; } $q = new CMS_query($sql); $orderedIds = array(); if (!$q->hasError()) { //save ordered ids while ($id = $q->getValue('objectID')) { $orderedIds[$id] = $id; } } $ids = $orderedIds; } } } else { $ids = $this->_resultsIds; } //check for results existance in objects datas tables if ($ids) { //update tmp table with found ids $this->_updateTmpList($ids); $where = ' objectID in (' . $this->_getSQLTmpList() . ')'; $sql = "\n\t\t\t\tselect\n\t\t\t\t\tdistinct objectID\n\t\t\t\tfrom\n\t\t\t\t\tmod_subobject_text" . $statusSuffix . "\n\t\t\t\twhere\n\t\t\t\t\t{$where}\n\t\t\t\tunion distinct\n\t\t\t\tselect\n\t\t\t\t\tdistinct objectID\n\t\t\t\tfrom\n\t\t\t\t\tmod_subobject_integer" . $statusSuffix . "\n\t\t\t\twhere\n\t\t\t\t\t{$where}\n\t\t\t\tunion distinct\n\t\t\t\tselect\n\t\t\t\t\tdistinct objectID\n\t\t\t\tfrom\n\t\t\t\t\tmod_subobject_string" . $statusSuffix . "\n\t\t\t\twhere\n\t\t\t\t\t{$where}\n\t\t\t\tunion distinct\n\t\t\t\tselect\n\t\t\t\t\tdistinct objectID\n\t\t\t\tfrom\n\t\t\t\t\tmod_subobject_date" . $statusSuffix . "\n\t\t\t\twhere\n\t\t\t\t\t{$where}\n\t\t\t"; $q = new CMS_query($sql); if ($q->getNumRows() != count($ids)) { $foundIds = $q->getAll(PDO::FETCH_COLUMN, 0); if ($foundIds) { $ids = array_intersect($ids, $foundIds); //update count of results $this->_numRows = sizeof($ids); } else { $ids = array(); $this->_numRows = 0; } } } //Limit results if needed if ($ids && $this->_numRows > 0 && $this->_itemsPerPage > 0) { $ids = array_slice($ids, $this->_page * $this->_itemsPerPage, $this->_itemsPerPage, true); } return $ids; }
if (sizeof($objectFields)) { $selected = $field->getValue("type") == $anObjectType->getID() ? ' selected="selected"' : ''; $content .= '<option value="' . $anObjectType->getID() . '"' . $selected . ' title="' . htmlspecialchars($anObjectType->getDescription($cms_language)) . '">' . $anObjectType->getObjectLabel($cms_language) . ' (' . $objectModule->getLabel($cms_language) . ')</option>'; } } } $content .= '</optgroup>'; } if (sizeof($poly_types) > 1) { $content .= '<optgroup label="' . $cms_language->getMessage(MESSAGE_PAGE_FIELD_MULTI) . ' ' . $cms_language->getMessage(MESSAGE_PAGE_FIELD_POLY_OBJECTS) . '">'; //multi poly objects foreach ($poly_types as $anObjectType) { //a poly object can't use itself or can't use an object who already use itself (infinite loop) if ($object->getID() != $anObjectType->getID() && !in_array($anObjectType->getID(), $objectUseage)) { //load fields objects for object $objectFields = CMS_poly_object_catalog::getFieldsDefinition($anObjectType->getID()); $objectModule = CMS_modulesCatalog::getByCodename(CMS_poly_object_catalog::getModuleCodenameForObjectType($anObjectType->getID())); //a poly object can't be empty if (sizeof($objectFields)) { $selected = $field->getValue("type") == 'multi|' . $anObjectType->getID() ? ' selected="selected"' : ''; $content .= '<option value="multi|' . $anObjectType->getID() . '"' . $selected . ' title="' . htmlspecialchars($anObjectType->getDescription($cms_language)) . '">' . $anObjectType->getObjectLabel($cms_language) . ' (' . $objectModule->getLabel($cms_language) . ')</option>'; } } } $content .= '</optgroup>'; } $content .= ' </select>'; } else { $content .= ' <strong>' . $typeObject->getObjectLabel($cms_language) . '</strong>
/** * get HTML admin subfields parameters (used to enter object search parameters values in admin) * * @return string : the html admin * @access public */ function getHTMLSubFieldsParametersSearch($language, $prefixName) { global $polymodCodename; $input = ''; //get params values $params = $this->getParamsValues(); $values = $params['searchedObjects']; //get object definition $objectDef = $this->getObjectDefinition(); //load object fields $objectFields = CMS_poly_object_catalog::getFieldsDefinition($this->_objectID); //Add all subobjects or special fields (like categories) to search if any foreach ($objectFields as $fieldID => $field) { //check if field is searchable if ($field->getValue('searchable')) { //check if field has a method to provide a list of names $objectType = $field->getTypeObject(); if (method_exists($objectType, 'getListOfNamesForObject')) { $objectsNames = $objectType->getListOfNamesForObject(false, array(), false); if (is_array($objectsNames) && $objectsNames) { $s_object_listbox = CMS_moduleCategories_catalog::getListBox(array('field_name' => $prefixName . 'searchedObjects[' . $fieldID . ']', 'items_possible' => $objectsNames, 'default_value' => $values[$fieldID], 'attributes' => 'class="admin_input_text" style="width:250px;"')); $input .= ' <tr> <td class="admin" align="right">' . $field->getLabel($language) . ' :</td> <td class="admin">' . $s_object_listbox . '</td> </tr>'; } } } } $input = $input ? '<table border="0" cellpadding="3" cellspacing="0" style="border-left:1px solid #4d4d4d;">' . $input . '</table>' : ''; return $input; }
/** * get HTML admin subfields parameters (used to enter object parameters values in admin) * * @return string : the html admin * @access public */ function getHTMLSubFieldsParameters($language, $prefixName) { if (!is_a($language, 'CMS_language')) { $this->raiseError("Language must be a CMS_language object : " . print_r($language, true)); return false; } $values = $this->_parameterValues; $html = ''; $parameters = $this->getSubFieldParameters(); foreach ($parameters as $parameterID => $parameter) { $paramValue = $values[$parameterID]; switch ($parameter['type']) { case 'boolean': $yes = $paramValue ? ' selected="selected"' : ''; $input = '<select name="' . $prefixName . $parameter['internalName'] . '" class="admin_input_text"> <option value="0">' . $language->getMessage(self::MESSAGE_FIELD_NO) . '</option> <option value="1"' . $yes . '>' . $language->getMessage(self::MESSAGE_FIELD_YES) . '</option> </select>'; break; case 'integer': case 'date': case 'string': $input = '<input type="text" size="30" name="' . $prefixName . $parameter['internalName'] . '" class="admin_input_text" value="' . io::htmlspecialchars($paramValue) . '" />'; break; case 'text': $input = '<textarea cols="70" rows="4" name="' . $prefixName . $parameter['internalName'] . '" class="admin_input_text">' . io::htmlspecialchars($paramValue) . '</textarea>'; break; case 'fields': //get all fields for current object $fields = CMS_poly_object_catalog::getFieldsDefinition($this->_field->getValue('objectID')); $selectValues = array(); foreach ($fields as $field) { $label = new CMS_object_i18nm($field->getValue("labelID")); $selectValues[$field->getID()] = $label->getValue($language->getCode()); } $selectedValues = explode(';', $paramValue); $listboxesParameters = array('field_name' => $prefixName . $parameter['internalName'], 'items_possible' => $selectValues, 'items_selected' => $selectedValues, 'select_width' => '300px', 'select_height' => '200px', 'form_name' => 'frm'); $input = CMS_dialog_listboxes::getListBoxes($listboxesParameters); break; default: if ($parameter['type'] && method_exists($this, "getHTMLSubFieldsParameters" . $parameter['type'])) { $method = "getHTMLSubFieldsParameters" . $parameter['type']; $input = $this->{$method}($language, $prefixName, $parameter); } else { $this->raiseError("Can't get parameter HTML for type : " . $parameter['type']); return false; } break; } if ($input) { $paramLabel = sensitiveIO::isPositiveInteger($parameter['externalName']) ? $language->getMessage($parameter['externalName'], false, $this->_messagesModule) : 'Undefined'; $paramDescription = isset($parameter['description']) && sensitiveIO::isPositiveInteger($parameter['description']) ? '<br /><small>' . $language->getMessage($parameter['description'], false, $this->_messagesModule) . '</small>' : ''; $required = $parameter['required'] ? '<span class="admin_text_alert">*</span>' : ''; $html .= ' <tr> <td class="admin" align="right" valign="top">' . $required . $paramLabel . '</td> <td class="admin" valign="top">' . $input . $paramDescription . '</td> </tr>'; } } $html = $html ? '<table border="0" cellpadding="3" cellspacing="0" style="border-left:1px solid #4d4d4d;">' . $html . '</table>' : ''; return $html; }
protected function _getFieldsFiles($item, &$files) { //get object fields definitions $objectFields = CMS_poly_object_catalog::getFieldsDefinition($item->getObjectID()); $itemFieldsObjects =& $item->getFieldsObjects(); foreach ($itemFieldsObjects as $fieldID => $itemField) { //check field type $fieldType = $objectFields[$fieldID]->getValue('type'); if (sensitiveIO::isPositiveInteger($fieldType)) { //this field is a poly_object so recurse on his values $this->_getFieldsFiles($itemField, $files); } elseif (io::strpos($fieldType, "multi|") !== false) { //this field is a multi_poly_object so recurse on all poly_objects it contain $params = $itemField->getParamsValues(); if ($itemField->getValue('count')) { $items = $itemField->getValue('fields'); foreach ($items as $anItem) { $this->_getFieldsFiles($anItem, $files); } } } else { //if this field is a file, check for file if ($fieldType == 'CMS_object_file') { if ($itemField->getValue('filename')) { $files[] = PATH_REALROOT_FS . $itemField->getValue('filePath') . '/' . $itemField->getValue('filename'); } } } } return; }
/** * Constructor. * initialize object. * * @param integer $objectID the object type id in catalog (relative to id in mod_object_def table) * @param integer $id the object id (relative to id in mod_object_polyobjects table) * @param array $datas the object and sub objects values * @param boolean $public, object values are public or edited ? (default is edited) * @param boolean $loadObject, load object values from db if not found in params ? * @param boolean $loadSubObjectsValues, /!\ Experimental /!\ Load subobjects datas. Default : true. Only for public objects. * in case of large objects to manage, we can limit the memory usage by disallow loading of sub objects datas structure. * @return void * @access public */ function __construct($objectID, $id = 0, $datas = array(), $public = false, $loadObject = true, $loadSubObjectsValues = true) { //check object type id if (sensitiveIO::isPositiveInteger($objectID)) { //set $this->_objectID $this->_objectID = $objectID; //set $this->_objectFieldsDefinition $this->_objectFieldsDefinition = CMS_poly_object_catalog::getFieldsDefinition($objectID); //get Object definition $objectDef = $this->getObjectDefinition(); //set $this->_objectName $this->_objectName = $objectDef->getValue("labelID"); //set $this->_objectDesc $this->_objectDesc = $objectDef->getValue("descriptionID"); //set $this->_objectResourceStatus $this->_objectResourceStatus = $objectDef->getValue("resourceUsage"); } else { $this->raiseError("ObjectID is not a positive Integer : " . $objectID); return; } //set $this->_public $this->_public = $public; $this->_loadSubObjectsValues = $this->_public && !$loadSubObjectsValues ? false : true; //set $this->_ID if (sensitiveIO::isPositiveInteger($id)) { $this->_ID = $id; } //set $this->_subObjectsDefinitions if ($this->_objectFieldsDefinition) { $this->_populateSubObjectsDefinitions(); } //set $this->_objectValues if ($this->_ID && $this->_subObjectsDefinitions && $loadObject && !isset($datas[$this->_ID])) { //set $this->_objectValues from DB if (!$this->_loadObject()) { $this->_ID = ''; } else { //set $this->_composedLabel if any (only if object is loaded) $this->_composedLabel = $objectDef->getValue("composedLabel"); } } elseif ($this->_ID && is_array($datas) && isset($datas[$this->_ID]) && $datas[$this->_ID]) { //set $this->_objectValues from given datas $this->_populateSubObjectsValues($datas); //set $this->_composedLabel if any (only if object is loaded) $this->_composedLabel = $objectDef->getValue("composedLabel"); } elseif (!$this->_ID) { //load clean subObjects and set $this->_objectValues $this->_populateSubObjects(); } }
</select> </form> <table border="0" cellpadding="2" cellspacing="2"> <tr>'; if (is_object($object)) { $objectUseage = CMS_poly_object_catalog::getObjectUsage($object->getID(), true); if (!sizeof($objectUseage)) { $objectUseageLabel = $cms_language->getMessage(MESSAGE_PAGE_FIELD_NO) . '<br />'; } else { $objectUseageLabel = $cms_language->getMessage(MESSAGE_PAGE_FIELD_OBJECT_USED) . ' : <ul>'; foreach ($objectUseage as $anObjectWhichUse) { $objectUseageLabel .= '<li>' . $anObjectWhichUse->getLabel() . '</li>'; } $objectUseageLabel .= '</ul>'; } $fields = CMS_poly_object_catalog::getFieldsDefinition($object->getID(), true); //get all RSS def for object $RRSDefinitions = CMS_poly_object_catalog::getAllRSSDefinitionsForObject($object->getID()); //get all plugin def for object $pluginDefinitions = CMS_poly_object_catalog::getAllPluginDefinitionsForObject($object->getID()); $content .= ' <strong>ID :</strong> ' . $object->getID() . '<br /> <strong>' . $cms_language->getMessage(MESSAGE_PAGE_FIELD_DESCRIPTION) . ' :</strong> ' . $object->getDescription($cms_language) . '<br /> <strong>' . $cms_language->getMessage(MESSAGE_PAGE_FIELD_RESOURCE) . ' :</strong> ' . $cms_language->getMessage($resourceStatus[$object->getValue("resourceUsage")]) . '<br /> <strong>' . $cms_language->getMessage(MESSAGE_PAGE_FIELD_EDITABLE) . ' :</strong> ' . $cms_language->getMessage($adminEditableStatus[$object->getValue("admineditable")]) . '<br /> <strong>' . $cms_language->getMessage(MESSAGE_PAGE_FIELD_COMPOSED_LABEL) . ' :</strong> ' . $cms_language->getMessage($adminEditableStatus[$object->getValue("composedLabel") ? 0 : 1]) . '<br /> <strong>' . $cms_language->getMessage(MESSAGE_PAGE_FIELD_OBJECT_USEAGE) . ' :</strong> ' . $objectUseageLabel; if (class_exists('CMS_module_ase') && CMS_module_ase::isActive()) { $content .= '<strong>' . $cms_language->getMessage(MESSAGE_PAGE_FIELD_OBJECT_INDEXABLE, false, MOD_POLYMOD_CODENAME) . ' :</strong> ' . $cms_language->getMessage($adminIndexableStatus[$object->getValue("indexable") ? 0 : 1]) . '<br />'; } $content .= '
/** * Returns all categories IDs who has used by this type of object (ie : this field) * * @param mixed (boolean or array) $restrictToItemsIds, restrict results to given items ids. False to restrict to only used categories (default) * @access public * @return array(interger id => integer id) the object ids * @static */ function getAllUsedCategoriesForField($restrictToItemsIds = false) { if (is_array($restrictToItemsIds) && (!$restrictToItemsIds || !implode($restrictToItemsIds, ', '))) { //restrict to no ids so return nothing return array(); } //get field of categories for searched object type (assume it uses categories) $categoriesFields = CMS_poly_object_catalog::objectHasCategories(CMS_poly_object_catalog::getObjectIDForField($this->_field->getID())); $fieldsDefinitions = array(); //bypass field categories rights if needed foreach ($categoriesFields as $key => $catFieldID) { if (!isset($fieldsDefinitions[$catFieldID]) || !is_object($fieldsDefinitions[$catFieldID])) { //get object fields definition $fieldsDefinitions = CMS_poly_object_catalog::getFieldsDefinition(CMS_poly_object_catalog::getObjectIDForField($this->_field->getID())); } /*if ($fieldsDefinitions[$catFieldID]->getParameter('bypassRights')) { unset($categoriesFields[$key]); }*/ } if (!$categoriesFields) { return array(); } //if this field is the only one which use categories if (sizeof($categoriesFields) == 1 && in_array($this->_field->getID(), $categoriesFields)) { if ($this->_public) { //check for publication dates $sql = "\n\t\t\t\t\tselect\n\t\t\t\t\t\tdistinct objectID\n\t\t\t\t\tfrom\n\t\t\t\t\t\tmod_subobject_integer_public,\n\t\t\t\t\t\tresources,\n\t\t\t\t\t\tresourceStatuses\n\t\t\t\t\twhere\n\t\t\t\t\t\tobjectFieldID = '0'\n\t\t\t\t\t\tand value = id_res\n\t\t\t\t\t\tand status_res=id_rs\n\t\t\t\t\t\tand location_rs='" . RESOURCE_LOCATION_USERSPACE . "'\n\t\t\t\t\t\tand publication_rs='" . RESOURCE_PUBLICATION_PUBLIC . "'\n\t\t\t\t\t\tand publicationDateStart_rs <= '" . date('Y-m-d') . "'\n\t\t\t\t\t\tand publicationDateStart_rs != '0000-00-00'\n\t\t\t\t\t\tand (publicationDateEnd_rs >= '" . date('Y-m-d') . "'\n\t\t\t\t\t\tor publicationDateEnd_rs = '0000-00-00')\n\t\t\t\t\t"; if ($restrictToItemsIds) { $sql .= " and objectID in (" . implode($restrictToItemsIds, ', ') . ")"; } else { $sql .= " and objectID in (select objectID from mod_subobject_integer_public where objectFieldID = '" . $this->_field->getID() . "')"; } $q = new CMS_query($sql); $restrictToItemsIds = array(); if ($q->getNumRows()) { while ($arr = $q->getArray()) { $restrictToItemsIds[] = $arr['objectID']; } } } $table = $this->_public ? 'mod_subobject_integer_public' : 'mod_subobject_integer_edited'; $sql = "\n\t\t\t\tselect\n\t\t\t\t\tvalue\n\t\t\t\tfrom\n\t\t\t\t\t{$table}\n\t\t\t\twhere\n\t\t\t\t\tobjectFieldID = '" . $this->_field->getID() . "'\n\t\t\t"; if ($restrictToItemsIds) { $sql .= " and objectID in (" . implode($restrictToItemsIds, ', ') . ")"; } $q = new CMS_query($sql); $r = array(); if ($q->getNumRows()) { while ($arr = $q->getArray()) { //check for value because it can be null ! if ($arr['value']) { $r[$arr['value']] = $arr['value']; } } } } else { //if this field is not only one which use categories global $cms_user; if (APPLICATION_ENFORCES_ACCESS_CONTROL && !is_object($cms_user)) { $this->raiseError("Valid user missing"); return false; } if (!is_object($cms_user)) { //TODO : ugly but missing time (need to redo the getAllCategoriesAsArray to accept no valid cms_user : append only in frontend without APPLICATION_ENFORCES_ACCESS_CONTROL. Medias module already doing something like this) $user = new CMS_profile_user(ROOT_PROFILEUSER_ID); } else { $user = $cms_user; } //get a list of all viewvable categories for current user $viewvableCats = array_keys(CMS_moduleCategories_catalog::getViewvableCategoriesForProfile($user, CMS_poly_object_catalog::getModuleCodenameForField($this->_field->getID()), true)); //if no viewvable categories, user has no rights to view anything if (!$viewvableCats) { return array(); } $table = $this->_public ? 'mod_subobject_integer_public' : 'mod_subobject_integer_edited'; $sql = "\n\t\t\t\tselect\n\t\t\t\t\tdistinct objectID\n\t\t\t\tfrom\n\t\t\t\t\t{$table}\n\t\t\t\twhere\n\t\t\t\t\tobjectFieldID in (" . @implode(',', $categoriesFields) . ")\n\t\t\t\t\tand value in (" . @implode(',', $viewvableCats) . ")\n\t\t\t\t\t"; if ($restrictToItemsIds) { $sql .= " and objectID in (" . implode($restrictToItemsIds, ', ') . ")"; } $q = new CMS_query($sql); $r = array(); if ($q->getNumRows()) { while ($arr = $q->getArray()) { //check for value because it can be null ! if ($arr['objectID']) { $r[$arr['objectID']] = $arr['objectID']; } } } if (!$r) { return array(); } //add previously found IDs to where clause $sql = "\n\t\t\t\tselect\n\t\t\t\t\tdistinct value\n\t\t\t\tfrom\n\t\t\t\t\t{$table}\n\t\t\t\twhere\n\t\t\t\t\tobjectFieldID = '" . $this->_field->getID() . "'\n\t\t\t\t\tand objectID in(" . @implode(',', $r) . ")\n\t\t\t"; $q = new CMS_query($sql); $r = array(); if ($q->getNumRows()) { while ($arr = $q->getArray()) { //check for value because it can be null ! if ($arr['value']) { $r[$arr['value']] = $arr['value']; } } } } return $r; }
/** * 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; }