/** * Proceed to search and returns the array of results, null if none * found. All search options had been set yet. * * @access public * @param $return, the returned values in : * self::POLYMOD_SEARCH_RETURN_IDS for array of ids sorted * self::POLYMOD_SEARCH_RETURN_DATAS for db datas * self::POLYMOD_SEARCH_RETURN_OBJECTS for objetcs (default) * self::POLYMOD_SEARCH_RETURN_OBJECTSLIGHT for light objects (without subobjects datas) * self::POLYMOD_SEARCH_RETURN_OBJECTSLIGHT_EDITED for edited light objects. /!\ This method must not be used for objects which should be saved (used by getListOfNamesForObject only) /!\ * self::POLYMOD_SEARCH_RETURN_INDIVIDUALS_OBJECTS use this method to get individual results with method getNextResult * @param boolean $loadSubObjects : all the found objects can load theirs own sub objects (default false) * /!\ CAUTION : Pass this option to true can generate a lot of subqueries /!\ * @return mixed array(CMS_poly_object) or boolean (for POLYMOD_SEARCH_RETURN_INDIVIDUALS_OBJECTS) */ function search($return = self::POLYMOD_SEARCH_RETURN_OBJECTS, $loadSubObjects = false) { global $cms_user; if ($return == self::POLYMOD_SEARCH_RETURN_OBJECTSLIGHT && !$this->_public) { $this->raiseError('Return type can\'t be self::POLYMOD_SEARCH_RETURN_OBJECTSLIGHT in a non-public search.'); $return = self::POLYMOD_SEARCH_RETURN_OBJECTS; } //this is a hack to allow light search in edited userspace. /!\ Objects must not be saved after /!\ if ($return == self::POLYMOD_SEARCH_RETURN_OBJECTSLIGHT_EDITED) { $return = self::POLYMOD_SEARCH_RETURN_OBJECTSLIGHT; } $items = array(); if ($return == self::POLYMOD_SEARCH_RETURN_INDIVIDUALS_OBJECTS) { //reset result stack if needed reset($this->_sortedResultsIds); } $this->_searchMode = $return; // Check module rights : to get any results, user should has at least CLEARANCE_MODULE_VIEW if ((!$this->_public || $this->_public && APPLICATION_ENFORCES_ACCESS_CONTROL) && (!is_object($cms_user) || !$cms_user->hasModuleClearance($this->_object->getValue('module'), CLEARANCE_MODULE_VIEW))) { if (!is_object($cms_user)) { $this->_raiseError(__CLASS__ . ' : ' . __FUNCTION__ . ' : cms_user not loaded when trying to get objects subject to rights ...'); } return $return == self::POLYMOD_SEARCH_RETURN_INDIVIDUALS_OBJECTS ? false : $items; } //get all ids and numrows for search $this->_resultsIds = $this->_getIds(); //if results if (is_array($this->_resultsIds) && $this->_resultsIds) { //sort and limit ids to order and limit clause and to existant objects $this->_sortedResultsIds = $this->_sortIds(); //if return anything than ids if ($return != self::POLYMOD_SEARCH_RETURN_IDS && is_array($this->_sortedResultsIds) && $this->_sortedResultsIds) { //get subobjects ids if ($return != self::POLYMOD_SEARCH_RETURN_OBJECTSLIGHT) { $this->_resultsSubObjectsIds = $this->_getSubObjectsIds(); } //then load all values for objects and subobjects (if needed) $this->_values = $this->_getObjectValues(); } //clean tmp table $this->_updateTmpList(); } else { //clean tmp table $this->_updateTmpList(); return $return == self::POLYMOD_SEARCH_RETURN_INDIVIDUALS_OBJECTS ? true : array(); } //return datas if ($return == self::POLYMOD_SEARCH_RETURN_DATAS) { return $this->_values; } //return individuals objects with method getNextResult if ($return == self::POLYMOD_SEARCH_RETURN_INDIVIDUALS_OBJECTS) { return true; } //return ids if ($return == self::POLYMOD_SEARCH_RETURN_IDS) { return $this->_sortedResultsIds; } //return objects $count = 0; if ($this->_values && $this->_sortedResultsIds) { //1- create objects values : all subObjects found for searched objects $subObjectValues = array(); foreach ($this->_resultsSubObjectsIds as $subObjectId) { $subObjectValues[$subObjectId] =& $this->_values[$subObjectId]; } //load sub objects values $loadSubObjectsValues = $return != self::POLYMOD_SEARCH_RETURN_OBJECTSLIGHT; //create objects foreach ($this->_sortedResultsIds as $aResultID) { //2- add object values to objects values $objectValues = $subObjectValues; $objectValues[$aResultID] =& $this->_values[$aResultID]; //instanciate object $obj = new CMS_poly_object($this->_object->getID(), $aResultID, $objectValues, $this->_public, $loadSubObjects, $loadSubObjectsValues); if (!$obj->hasError()) { $items[$aResultID] = $obj; $count++; } } } return $items; }
CMS_grandFather::raiseError('Error, user has no rights on module : ' . $codename); $view->show(); } //load object if ($objectId) { $object = CMS_poly_object_catalog::getObjectDefinition($objectId); $objectLabel = sensitiveIO::sanitizeJSString($object->getLabel($cms_language)); } if (!isset($object) || $object->hasError()) { CMS_grandFather::raiseError('Error, objectId does not exists or has an error : ' . $objectId); $view->show(); } //load item if any if ($itemId) { $item = new CMS_poly_object($objectId, $itemId); if (!$item || $item->hasError()) { CMS_grandFather::raiseError('Error, unknown item Id : ' . $itemId); $view->show(); } $itemLabel = sensitiveIO::sanitizeJSString($item->getLabel()); if ($object->isPrimaryResource()) { //put a lock on the resource or warn user if item is already locked if ($lock = $item->getLock()) { $lockUser = CMS_profile_usersCatalog::getById($lock); $lockDate = $item->getLockDate(); $date = $lockDate ? $lockDate->getLocalizedDate($cms_language->getDateFormat() . ' @ H:i:s') : ''; $name = sensitiveIO::sanitizeJSString($lockUser->getFullName()); CMS_grandFather::raiseError('Error, item ' . $itemId . ' is locked by ' . $lockUser->getFullName()); $jscontent = "\n\t\t\tvar window = Ext.getCmp('{$winId}');\n\t\t\tif (window) {\n\t\t\t\twindow.close();\n\t\t\t}\n\t\t\tAutomne.message.popup({\n\t\t\t\tmsg: \t\t\t\t'{$cms_language->getJSMessage(MESSAGE_PAGE_ELEMENT_LOCKED, array($itemLabel, $name, $date), MOD_POLYMOD_CODENAME)}',\n\t\t\t\tbuttons: \t\t\tExt.MessageBox.OK,\n\t\t\t\tclosable: \t\t\tfalse,\n\t\t\t\ticon: \t\t\t\tExt.MessageBox.ERROR\n\t\t\t});"; $view->addJavascript($jscontent); $view->show();