/** * Gets a validation for a given item * * @param integer $itemID The item we want the validations for * @param CMS_user $user The user we want the validations for * @param integer $getEditionType The validation type we want. * by default function return RESOURCE_EDITION_LOCATION then RESOURCE_EDITION_CONTENT then RESOURCE_EDITION_SIBLINGSORDER * @return array(CMS_resourceValidation) The resourceValidations objects, false if none found for the given user. * @access public */ function getValidationByID($itemID, &$user, $getEditionType = false) { if (!$user instanceof CMS_profile_user) { $this->raiseError("User is not a valid CMS_profile_user object"); return false; } if (!$user->hasValidationClearance($this->_codename)) { return false; } if (CMS_poly_object_catalog::hasPrimaryResource($this->getCodename())) { //get object type ID $objectID = CMS_poly_object_catalog::getPrimaryResourceObjectType($this->getCodename()); //get viewvable objects list for current user if (CMS_poly_object_catalog::objectHasCategories($objectID)) { $objects = CMS_poly_object_catalog::getAllObjects($objectID, false, array(), false); //$where = (is_array($objects) && $objects) ? ' and objectID in ('.implode(',',$objects).')' : ''; if (is_array($objects) && $objects) { $where = ' and objectID in (' . implode(',', $objects) . ')'; } else { return false; } } else { $where = ''; } $this->getPrimaryResourceDefinition(); if (!$getEditionType) { $getEditionType = RESOURCE_EDITION_LOCATION + RESOURCE_EDITION_CONTENT; } $sql = "\n\t\t\t\t\tselect\n\t\t\t\t\t\tobjectID as id,\n\t\t\t\t\t\tlocation_rs as location,\n\t\t\t\t\t\tproposedFor_rs as proposedFor,\n\t\t\t\t\t\tvalidationsRefused_rs as validationsRefused,\n\t\t\t\t\t\teditions_rs as editions,\n\t\t\t\t\t\tmod_subobject_integer_edited.id as fieldID\n\t\t\t\t\tfrom\n\t\t\t\t\t\tmod_subobject_integer_edited,\n\t\t\t\t\t\tmod_object_polyobjects,\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\tobjectID = '" . $itemID . "'\n\t\t\t\t\t\tand value = id_res\n\t\t\t\t\t\tand object_type_id_moo = '" . $objectID . "'\n\t\t\t\t\t\tand id_moo = objectID\n\t\t\t\t\t\tand objectFieldID = 0\n\t\t\t\t\t\tand objectSubFieldID = 0\n\t\t\t\t\t\tand status_res = id_rs\n\t\t\t\t\t\t{$where}\n\t\t\t\t"; $q = new CMS_query($sql); if ($q->getNumRows() >= 1) { $r = $q->getArray(); $id = $r["id"]; //here, this is an ugly hack to resolve a strange bug (multiple resources for an unique object). //not time to found the real cause for now ... if ($q->getNumRows() > 1) { while ($exceptionFiledID = $q->getValue('fieldID')) { $sql_delete = "delete from mod_subobject_integer_edited where id = '" . $exceptionFiledID . "'"; $q_delete = new CMS_query($sql_delete); } } //search the type of edition //RESOURCE_EDITION_LOCATION if ($r["location"] == RESOURCE_LOCATION_USERSPACE && $r["proposedFor"] != 0 && !($r["validationsRefused"] & RESOURCE_EDITION_LOCATION) && $getEditionType & RESOURCE_EDITION_LOCATION) { $language = $user->getLanguage(); $item = $this->getResourceByID($id); $validation = new CMS_resourceValidation($this->_codename, RESOURCE_EDITION_LOCATION, $item); if (!$validation->hasError()) { $validation->setValidationTypeLabel($language->getMessage(self::MESSAGE_MOD_POLYMOD_VALIDATION_LOCATIONCHANGE, array($this->_primaryResourceObjectDefinition->getLabel($language)), MOD_POLYMOD_CODENAME)); $validation->setValidationLabel($language->getMessage(self::MESSAGE_MOD_POLYMOD_VALIDATION_LOCATIONCHANGE_OFRESOURCE, array($this->_primaryResourceObjectDefinition->getLabel($language)), MOD_POLYMOD_CODENAME) . " " . io::decodeEntities($item->{$this->_resourceNameMethod}())); $validation->setValidationShortLabel(io::decodeEntities($item->{$this->_resourceNameMethod}())); $previzURL = $item->getPrevizPageURL(); if ($previzURL) { $validation->addHelpUrl($language->getMessage(self::MESSAGE_PAGE_ACTION_PREVIZ), $previzURL); } $validation->setEditorsStack($item->getEditorsStack()); return $validation; } else { return false; } //RESOURCE_EDITION_CONTENT } elseif ($r["location"] == RESOURCE_LOCATION_USERSPACE && $r["proposedFor"] == 0 && ($r["editions"] & RESOURCE_EDITION_CONTENT && !($r["validationsRefused"] & RESOURCE_EDITION_CONTENT)) && $getEditionType & RESOURCE_EDITION_CONTENT) { $language = $user->getLanguage(); $editions = $r["editions"]; //RESOURCE_EDITION_CONTENT $item = $this->getResourceByID($id); $validation = new CMS_resourceValidation($this->_codename, $editions, $item); if (!$validation->hasError()) { $validation->setValidationTypeLabel($language->getMessage(self::MESSAGE_MOD_POLYMOD_VALIDATION_EDITION, array($this->_primaryResourceObjectDefinition->getLabel($language)), MOD_POLYMOD_CODENAME)); $validation->setValidationLabel($language->getMessage(self::MESSAGE_MOD_POLYMOD_VALIDATION_EDITION_OFRESOURCE, array($this->_primaryResourceObjectDefinition->getLabel($language)), MOD_POLYMOD_CODENAME) . " " . io::decodeEntities($item->{$this->_resourceNameMethod}())); $validation->setValidationShortLabel(io::decodeEntities($item->{$this->_resourceNameMethod}())); $previzURL = $item->getPrevizPageURL(); if ($previzURL) { $validation->addHelpUrl($language->getMessage(self::MESSAGE_PAGE_ACTION_PREVIZ), $previzURL); } $validation->setEditorsStack($item->getEditorsStack()); return $validation; } else { return false; } } } elseif ($q->getNumRows() == 0) { return false; } else { $this->raiseError("Can't have more than one item for a given ID"); return false; } } else { return false; } }
/** * Gets the module validations Info for the given editions and user * * @param CMS_user $user The user we want the validations for * @param integer $editions The editions we want the validations of * @param boolean $returnCount only return the count of validations * @return array(CMS_resourceValidation) The resourceValidations objects, false if noen found * @access public */ function getValidationsInfoByEditions(&$user, $editions, $returnCount = false) { $language = $user->getLanguage(); $validations = array(); $validationsCount = 0; if (is_array($this->_resourceInfo) && $this->_resourceInfo) { $primaryResource = $this->getPrimaryResourceInfo(); if ($editions & RESOURCE_EDITION_CONTENT) { //content and/or base data change $sql = "\n\t\t\t\t\tselect\n\t\t\t\t\t\t" . $primaryResource['key'] . " as id\n\t\t\t\t\tfrom\n\t\t\t\t\t\t" . $primaryResource['tableName'] . "_edited,\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\t" . $primaryResource['resource'] . " = 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 proposedFor_rs = 0\n\t\t\t\t\t\tand (editions_rs & " . RESOURCE_EDITION_CONTENT . "\n\t\t\t\t\t\t\t\tand not (validationsRefused_rs & " . RESOURCE_EDITION_CONTENT . "))\n\t\t\t\t"; $q = new CMS_query($sql); if ($returnCount) { $validationsCount += $q->getNumRows(); } else { while ($id = $q->getValue("id")) { $validation = new CMS_resourceValidationInfo($this->_codename, RESOURCE_EDITION_CONTENT, $id); if (!$validation->hasError()) { $validation->setValidationTypeLabel($language->getMessage($this->getModuleValidationLabel("edition"), false, $this->_codename)); $validations[] = $validation; } } } } if ($editions & RESOURCE_EDITION_LOCATION) { //Location change $sql = "\n\t\t\t\t\tselect\n\t\t\t\t\t\t" . $primaryResource['key'] . " as id\n\t\t\t\t\tfrom\n\t\t\t\t\t\t" . $primaryResource['tableName'] . "_edited,\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\t" . $primaryResource['resource'] . " = 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 proposedFor_rs != 0\n\t\t\t\t\t\tand not (validationsRefused_rs & " . RESOURCE_EDITION_LOCATION . ")\n\t\t\t\t"; $q = new CMS_query($sql); if ($returnCount) { $validationsCount += $q->getNumRows(); } else { while ($id = $q->getValue("id")) { $validation = new CMS_resourceValidationInfo($this->_codename, RESOURCE_EDITION_LOCATION, $id); if (!$validation->hasError()) { $validation->setValidationTypeLabel($language->getMessage($this->getModuleValidationLabel("locationChange"), false, $this->_codename)); $validations[] = $validation; } } } } } return $returnCount ? $validationsCount : $validations; }
/** * Write to persistence * * @return boolean true on success, false on failure * @access public */ function writeToPersistence() { $sql_fields = "\n\t\t\t\tuser_log='" . SensitiveIO::sanitizeSQLString($this->_user->getUserId()) . "',\n\t\t\t\taction_log='" . SensitiveIO::sanitizeSQLString($this->_action) . "',\n\t\t\t\tdatetime_log='" . SensitiveIO::sanitizeSQLString($this->_datetime->getDBValue()) . "',\n\t\t\t\ttextData_log='" . SensitiveIO::sanitizeSQLString($this->_textData) . "',\n\t\t\t\tlabel_log='" . SensitiveIO::sanitizeSQLString($this->_label) . "',\n\t\t\t\tmodule_log='" . SensitiveIO::sanitizeSQLString($this->_module) . "',\n\t\t\t\tresource_log='" . SensitiveIO::sanitizeSQLString($this->_resource) . "',\n\t\t\t\trsAfterLocation_log='" . SensitiveIO::sanitizeSQLString($this->_resourceStatusAfter->getLocation()) . "',\n\t\t\t\trsAfterProposedFor_log='" . SensitiveIO::sanitizeSQLString($this->_resourceStatusAfter->getProposedFor()) . "',\n\t\t\t\trsAfterEditions_log='" . SensitiveIO::sanitizeSQLString($this->_resourceStatusAfter->getEditions()) . "',\n\t\t\t\trsAfterValidationsRefused_log='" . SensitiveIO::sanitizeSQLString($this->_resourceStatusAfter->getValidationRefused()) . "',\n\t\t\t\trsAfterPublication_log='" . SensitiveIO::sanitizeSQLString($this->_resourceStatusAfter->getPublication()) . "'\t\n\t\t\t"; if ($this->_id) { $sql = "\n\t\t\t\t\tupdate\n\t\t\t\t\t\tlog\n\t\t\t\t\tset\n\t\t\t\t\t\t" . $sql_fields . "\n\t\t\t\t\twhere\n\t\t\t\t\t\tid_log='" . $this->_id . "'\n\t\t\t\t"; } else { $sql = "\n\t\t\t\t\tinsert into\n\t\t\t\t\t\tlog\n\t\t\t\t\tset\n\t\t\t\t\t\t" . $sql_fields; } $q = new CMS_query($sql); if ($q->hasError()) { return false; } else { $this->_id = $q->getLastInsertedID(); } return true; }
/** * Gets the module validations for the given editions and user * * @param CMS_user $user The user we want the validations for * @param integer $editions The editions we want the validations of * @return array(CMS_resourceValidation) The resourceValidations objects, false if noen found * @access public */ function getValidationsByEditions(&$user, $editions) { $language = $user->getLanguage(); $validations = array(); $nb_loc = $nb_cont = $nb_ord = '0'; if ($editions & RESOURCE_EDITION_LOCATION) { //Location change $sql_loc = "\n\t\t\t\tselect\n\t\t\t\t\tid_pag\n\t\t\t\tfrom\n\t\t\t\t\tpages,\n\t\t\t\t\tresources,\n\t\t\t\t\tresourceStatuses\n\t\t\t\twhere\n\t\t\t\t\tresource_pag = id_res\n\t\t\t\t\tand status_res = id_rs\n\t\t\t\t\tand location_rs = '" . RESOURCE_LOCATION_USERSPACE . "'\n\t\t\t\t\tand proposedFor_rs != 0\n\t\t\t\t\tand not (validationsRefused_rs & " . RESOURCE_EDITION_LOCATION . ")\n\t\t\t"; $q_loc = new CMS_query($sql_loc); $nb_loc = $q_loc->getNumRows(); } if ($editions & RESOURCE_EDITION_CONTENT || $editions & RESOURCE_EDITION_BASEDATA) { //content and/or base data change $sql_cont = "\n\t\t\t\tselect\n\t\t\t\t\tid_pag,\n\t\t\t\t\teditions_rs\n\t\t\t\tfrom\n\t\t\t\t\tpages,\n\t\t\t\t\tresources,\n\t\t\t\t\tresourceStatuses\n\t\t\t\twhere\n\t\t\t\t\tresource_pag = id_res\n\t\t\t\t\tand status_res = id_rs\n\t\t\t\t\tand location_rs = '" . RESOURCE_LOCATION_USERSPACE . "'\n\t\t\t\t\tand proposedFor_rs = 0\n\t\t\t\t\tand ((editions_rs & " . RESOURCE_EDITION_CONTENT . "\n\t\t\t\t\t\t\tand not (validationsRefused_rs & " . RESOURCE_EDITION_CONTENT . "))\n\t\t\t\t\t\tor (editions_rs & " . RESOURCE_EDITION_BASEDATA . "\n\t\t\t\t\t\t\tand not (validationsRefused_rs & " . RESOURCE_EDITION_BASEDATA . ")))\n\t\t\t"; $q_cont = new CMS_query($sql_cont); $nb_cont = $q_cont->getNumRows(); } if ($editions & RESOURCE_EDITION_SIBLINGSORDER) { //siblings order change $sql_ord = "\n\t\t\t\tselect\n\t\t\t\t\tid_pag\n\t\t\t\tfrom\n\t\t\t\t\tpages,\n\t\t\t\t\tresources,\n\t\t\t\t\tresourceStatuses\n\t\t\t\twhere\n\t\t\t\t\tresource_pag = id_res\n\t\t\t\t\tand status_res = id_rs\n\t\t\t\t\tand location_rs = '" . RESOURCE_LOCATION_USERSPACE . "'\n\t\t\t\t\tand proposedFor_rs = 0\n\t\t\t\t\tand editions_rs & " . RESOURCE_EDITION_SIBLINGSORDER . "\n\t\t\t\t\tand not (validationsRefused_rs & " . RESOURCE_EDITION_SIBLINGSORDER . ")\n\t\t\t"; $q_ord = new CMS_query($sql_ord); $nb_ord = $q_ord->getNumRows(); } if ($editions & RESOURCE_EDITION_MOVE) { //siblings order change $sql_mov = "\n\t\t\t\tselect\n\t\t\t\t\tid_pag\n\t\t\t\tfrom\n\t\t\t\t\tpages,\n\t\t\t\t\tresources,\n\t\t\t\t\tresourceStatuses\n\t\t\t\twhere\n\t\t\t\t\tresource_pag = id_res\n\t\t\t\t\tand status_res = id_rs\n\t\t\t\t\tand location_rs = '" . RESOURCE_LOCATION_USERSPACE . "'\n\t\t\t\t\tand proposedFor_rs = 0\n\t\t\t\t\tand editions_rs & " . RESOURCE_EDITION_MOVE . "\n\t\t\t\t\tand not (validationsRefused_rs & " . RESOURCE_EDITION_MOVE . ")\n\t\t\t"; $q_mov = new CMS_query($sql_mov); $nb_mov = $q_mov->getNumRows(); } //Location change if ($nb_loc) { while ($id = $q_loc->getValue("id_pag")) { //check if the page is editable by the user. If not, can't validate it if (!$user->hasPageClearance($id, CLEARANCE_PAGE_EDIT)) { continue; } $page = $this->getResourceByID($id); $validation = new CMS_resourceValidation($this->_codename, RESOURCE_EDITION_LOCATION, $page); if (!$validation->hasError()) { $validation->setValidationTypeLabel($language->getMessage(self::MESSAGE_MOD_STANDARD_VALIDATION_LOCATIONCHANGE)); $validation->setValidationLabel($language->getMessage(self::MESSAGE_MOD_STANDARD_VALIDATION_LOCATIONCHANGE_OFPAGE) . " " . $page->getTitle()); $validation->setValidationShortLabel($page->getTitle()); $validation->addHelpUrl($language->getMessage(self::MESSAGE_MOD_STANDARD_URL_PREVIZ), PATH_ADMIN_WR . '/page-previsualization.php?currentPage=' . $id); if ($page->getPublication() == RESOURCE_PUBLICATION_PUBLIC) { $validation->addHelpUrl($language->getMessage(self::MESSAGE_MOD_STANDARD_URL_ONLINE), $page->getURL()); } //Back to edition location $validation->addHelpUrl($language->getMessage(self::MESSAGE_MOD_STANDARD_URL_EDIT), PATH_ADMIN_WR . '/page-content.php?page=' . $id, "_self", 'Automne.tabPanels.setActiveTab(\'edit\');Automne.utils.getPageById(' . $id . ');'); $validation->setEditorsStack($page->getEditorsStack()); $validations[] = $validation; } } } //content and/or base data change if ($nb_cont) { while ($data = $q_cont->getArray()) { $id = $data["id_pag"]; //check if the page is editable by the user. If not, can't validate it if (!$user->hasPageClearance($id, CLEARANCE_PAGE_EDIT)) { continue; } $editions = RESOURCE_EDITION_CONTENT + RESOURCE_EDITION_BASEDATA; $page = $this->getResourceByID($id); $validation = new CMS_resourceValidation($this->_codename, $editions, $page); if (!$validation->hasError()) { $validation->setValidationTypeLabel($language->getMessage(self::MESSAGE_MOD_STANDARD_VALIDATION_EDITION)); $validation->setValidationLabel($language->getMessage(self::MESSAGE_MOD_STANDARD_VALIDATION_EDITION_OFPAGE) . " " . $page->getTitle()); $validation->setValidationShortLabel($page->getTitle()); $validation->addHelpUrl($language->getMessage(self::MESSAGE_MOD_STANDARD_URL_PREVIZ), PATH_ADMIN_WR . '/page-previsualization.php?currentPage=' . $id); if ($page->getPublication() == RESOURCE_PUBLICATION_PUBLIC) { $validation->addHelpUrl($language->getMessage(self::MESSAGE_MOD_STANDARD_URL_ONLINE), $page->getURL()); } //Back to edition location $validation->addHelpUrl($language->getMessage(self::MESSAGE_MOD_STANDARD_URL_EDIT), PATH_ADMIN_WR . '/page-content.php?page=' . $id, "_self", 'Automne.tabPanels.setActiveTab(\'edit\');Automne.utils.getPageById(' . $id . ');'); $validation->setEditorsStack($page->getEditorsStack()); $validations[] = $validation; } } } //siblings order change if ($nb_ord) { while ($data = $q_ord->getArray()) { $id = $data["id_pag"]; //check if the page is editable by the user. If not, can't validate it if (!$user->hasPageClearance($id, CLEARANCE_PAGE_EDIT)) { continue; } $editions = RESOURCE_EDITION_SIBLINGSORDER; $page = $this->getResourceByID($id); $validation = new CMS_resourceValidation($this->_codename, $editions, $page); if (!$validation->hasError()) { $validation->setValidationTypeLabel($language->getMessage(self::MESSAGE_MOD_STANDARD_VALIDATION_SIBLINGSORDER)); $validation->setValidationLabel($language->getMessage(self::MESSAGE_MOD_STANDARD_VALIDATION_SIBLINGSORDER_OFPAGE) . " " . $page->getTitle()); $validation->setValidationShortLabel($page->getTitle()); $validation->addHelpUrl($language->getMessage(self::MESSAGE_MOD_STANDARD_URL_PREVIZ), PATH_ADMIN_WR . '/page-previsualization.php?currentPage=' . $id); if ($page->getPublication() == RESOURCE_PUBLICATION_PUBLIC) { $validation->addHelpUrl($language->getMessage(self::MESSAGE_MOD_STANDARD_URL_ONLINE), $page->getURL()); } //Back to edition location $validation->addHelpUrl($language->getMessage(self::MESSAGE_MOD_STANDARD_URL_EDIT), PATH_ADMIN_WR . '/page-content.php?page=' . $id, "_self", 'Automne.tabPanels.setActiveTab(\'edit\');Automne.utils.getPageById(' . $id . ');'); $validation->setEditorsStack($page->getEditorsStack()); $validations[] = $validation; } } } //move change if ($nb_mov) { while ($data = $q_mov->getArray()) { $id = $data["id_pag"]; //check if the page is editable by the user. If not, can't validate it if (!$user->hasPageClearance($id, CLEARANCE_PAGE_EDIT)) { continue; } $editions = RESOURCE_EDITION_MOVE; $page = $this->getResourceByID($id); $validation = new CMS_resourceValidation($this->_codename, $editions, $page); if (!$validation->hasError()) { $validation->setValidationTypeLabel($language->getMessage(self::MESSAGE_MOD_STANDARD_VALIDATION_MOVE)); $validation->setValidationLabel($language->getMessage(self::MESSAGE_MOD_STANDARD_VALIDATION_MOVE_OFPAGE) . " " . $page->getTitle()); $validation->setValidationShortLabel($page->getTitle()); $validation->addHelpUrl($language->getMessage(self::MESSAGE_MOD_STANDARD_URL_PREVIZ), PATH_ADMIN_WR . '/page-previsualization.php?currentPage=' . $id); if ($page->getPublication() == RESOURCE_PUBLICATION_PUBLIC) { $validation->addHelpUrl($language->getMessage(self::MESSAGE_MOD_STANDARD_URL_ONLINE), $page->getURL()); } //Back to edition location $validation->addHelpUrl($language->getMessage(self::MESSAGE_MOD_STANDARD_URL_EDIT), PATH_ADMIN_WR . '/page-content.php?page=' . $id, "_self", 'Automne.tabPanels.setActiveTab(\'edit\');Automne.utils.getPageById(' . $id . ');'); $validation->setEditorsStack($page->getEditorsStack()); $validations[] = $validation; } } } return $validations; }