* Copyright 2000, Quentin Cregan/Sourceforge
* Copyright 2002-2003, Tim Perdue/GForge, LLC
* Copyright 2009, Roland Mas
- * Copyright 2010, Franck Villaume - Capgemini
+ * Copyright 2010-2011, Franck Villaume - Capgemini
* http://fusionforge.org
*
- * This file is part of FusionForge.
+ * This file is part of FusionForge. FusionForge is free software;
+ * you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software
+ * Foundation; either version 2 of the Licence, or (at your option)
+ * any later version.
*
- * FusionForge is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published
- * by the Free Software Foundation; either version 2 of the License,
- * or (at your option) any later version.
+ * FusionForge is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
*
- * FusionForge is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with FusionForge; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
+ * You should have received a copy of the GNU General Public License along
+ * with FusionForge; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
require_once $gfcommon.'include/Error.class.php';
/**
* The Documents dictionary.
*
- * @var array Contains doc_group_id as key and the array of documents associated to that id.
+ * @var array Contains doc_group_id as key and the array of documents associated to that id.
*/
var $Documents;
/**
* The stateid limit
- * @var int Contains the stateid to limit return documents in getDocuments.
+ * @var integer Contains the stateid to limit return documents in getDocuments.
*/
var $stateid;
/**
* The doc_group_id limit
- * @var int Contains the doc_group id to limit return documents in getDocuments.
+ * @var integer Contains the doc_group id to limit return documents in getDocuments.
*/
var $docgroupid;
/**
* The columns order
- * @var array Contains the order of columns to sort before return documents in getDocuments.
+ * @var array Contains the order of columns to sort before return documents in getDocuments.
* Default value is title order
*/
var $order = array('title');
/**
* The limit
- * @var int Contains the limit of documents retrieve by getDocuments.
+ * @var integer Contains the limit of documents retrieve by getDocuments.
* Default value is 0 which means NO LIMIT
*/
var $limit = 0;
/**
* setStateID - call this before getDocuments() if you want to limit to a specific state.
*
- * @param int The stateid from the doc_states table.
+ * @param integer The stateid from the doc_states table.
* @access public
*/
function setStateID($stateid) {
/**
* setDocGroupID - call this before getDocuments() if you want to limit to a specific doc_group.
*
- * @param int The doc_group from the doc_groups table.
+ * @param integer The doc_group from the doc_groups table.
* @access public
*/
function setDocGroupID($docgroupid) {
/**
* getDocuments - returns an array of Document objects.
*
- * @param int no cache : force reinit $this->Documents : default: cache is used
- * @return array Document objects.
+ * @param integer no cache : force reinit $this->Documents : default: cache is used
+ * @return array Document objects.
* @access public
*/
function &getDocuments($nocache = 0) {
}
$return = array();
- $keys = array_keys($this->Documents);
+
+ // limit scope to the doc_group_id if any. Useful when you retrieve all documents
+ if ($this->docgroupid) {
+ $keys = array($this->docgroupid);
+ } else {
+ $keys = array_keys($this->Documents);
+ }
foreach ($keys as $key) {
- if (!array_key_exists($key, $this->Documents)) continue; // Should not happen
+ if (!array_key_exists($key, $this->Documents)) continue; // Should not happen
+
$count = count($this->Documents[$key]);
for ($i=0; $i < $count; $i++) {
$doc =& $this->Documents[$key][$i];
if (!$this->stateid) {
- if (session_loggedin()) {
- $perm =& $this->Group->getPermission();
- if (!$perm || !is_object($perm) || !$perm->isMember()) {
- if ($doc->getStateID() != 1) { // non-active document?
- $valid = false;
- }
- } else {
- if ($doc->getStateID() != 1 && /* not active */
- $doc->getStateID() != 4 && /* not hidden */
- $doc->getStateID() != 5) { /* not private */
- $valid = false;
- }
- }
- } else {
- if ($doc->getStateID() != 1) { // non-active document?
+ $perm =& $this->Group->getPermission();
+ if (!$perm || !is_object($perm)) {
+ if ($doc->getStateID() != 1) {
$valid = false;
+ echo 'LA';
+ }
+ if ($perm->isEditor()) {
+ $valid = true;
+ echo 'ICI';
}
}
} else {
}
}
- if (count($return) == 0) {
+ if (count($return) === 0) {
$this->setError(_('No Documents Found'));
$return = NULL;
return $return;
* getStates - Return an array of states that have documents associated to them
*/
function getUsedStates() {
- $result = db_query_params('SELECT DISTINCT doc_states.stateid,doc_states.name
+ $result = db_query_params('SELECT DISTINCT doc_states.stateid,doc_states.name
FROM doc_states,doc_data
WHERE doc_data.stateid=doc_states.stateid
ORDER BY doc_states.name ASC',