~automne-team/automne/4.2

« back to all changes in this revision

Viewing changes to automne/classes/workflow/resourcevalidationscatalog.php

  • Committer: sebastien
  • Date: 2008-11-26 17:12:36 UTC
  • Revision ID: sebastien_sebastien-20081126171236-16r3kxfuz2kmq2qe
Tags: V4_0_0a0
4.0.0a0 :
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
/* vim: set expandtab tabstop=4 shiftwidth=4: */
 
4
// +----------------------------------------------------------------------+
 
5
// | Automne (TM)                                                                                                                 |
 
6
// +----------------------------------------------------------------------+
 
7
// | Copyright (c) 2000-2009 WS Interactive                                                               |
 
8
// +----------------------------------------------------------------------+
 
9
// | Automne is subject to version 2.0 or above of the GPL license.               |
 
10
// | The license text is bundled with this package in the file                    |
 
11
// | LICENSE-GPL, and is available through the world-wide-web at                  |
 
12
// | http://www.gnu.org/copyleft/gpl.html.                                                                |
 
13
// +----------------------------------------------------------------------+
 
14
// | Author: Antoine Pouch <antoine.pouch@ws-interactive.fr> &            |
 
15
// | Author: S�bastien Pauchet <sebastien.pauchet@ws-interactive.fr>      |
 
16
// +----------------------------------------------------------------------+
 
17
//
 
18
// $Id: resourcevalidationscatalog.php,v 1.1.1.1 2008/11/26 17:12:06 sebastien Exp $
 
19
 
 
20
/**
 
21
  * Class CMS_resourceValidationsCatalog
 
22
  *
 
23
  * Manages the catalog of resourceValidations
 
24
  *
 
25
  * @package CMS
 
26
  * @subpackage workflow
 
27
  * @author Antoine Pouch <antoine.pouch@ws-interactive.fr> &
 
28
  * @author S�bastien Pauchet <sebastien.pauchet@ws-interactive.fr>
 
29
  */
 
30
 
 
31
class CMS_resourceValidationsCatalog extends CMS_grandFather
 
32
{
 
33
        /**
 
34
          * Returns a resourceValidation object instance from a DB id or from GetValidationByID function if exists.
 
35
          * Static function.
 
36
          *
 
37
          * @param integer $id the id of the saved object
 
38
          * @return resourceValidation the instance unserialized, false if not found.
 
39
          * @access public
 
40
          */
 
41
        function getValidationInstance($id,$user=false)
 
42
        {
 
43
                if (!SensitiveIO::isPositiveInteger($id) && base64_decode($id) && $user) {
 
44
                        //load validation form encoded ID (new validations system)
 
45
                        $decodedID = explode('||',base64_decode($id));
 
46
                        $module = CMS_modulesCatalog::getByCodename($decodedID[0]);
 
47
                        $editions = $decodedID[1];
 
48
                        $resourceID = $decodedID[2];
 
49
                        if (isset($module) && isset($editions) && isset($resourceID)) {
 
50
                                return $module->getValidationByID($resourceID, $user, $editions);
 
51
                        }
 
52
                }
 
53
                
 
54
                $sql = "
 
55
                        select
 
56
                                serializedObject_rv as data
 
57
                        from
 
58
                                resourceValidations
 
59
                        where
 
60
                                id_rv='".$id."'
 
61
                ";
 
62
                $q = new CMS_query($sql);
 
63
                
 
64
                if ($q->getNumRows()) {
 
65
                        $instance = unserialize(stripslashes($q->getValue("data")));
 
66
                        $instance->setID($id);
 
67
                        return $instance;
 
68
                } else {
 
69
                        parent::raiseError("Unknown id : ".$id);
 
70
                        return false;
 
71
                }
 
72
        }
 
73
        
 
74
        /**
 
75
          * Returns all the resource validations the user can do
 
76
          * Static function.
 
77
          *
 
78
          * @param CMS_user $user The user we want the validations of
 
79
          * @param string $module_codebame The module codename we want the validations of, if ommitted, validations for all the modules will be returned
 
80
          * @return array(string=>CMS_resourceValidation) The validations to do, indexed by module codename
 
81
          * @access public
 
82
          */
 
83
        function getValidations(&$user, $module_codename = false)
 
84
        {
 
85
                if (!is_a($user, "CMS_user")) {
 
86
                        parent::raiseError("User is not a valid CMS_user object");
 
87
                        return;
 
88
                }
 
89
                if ($module_codename) {
 
90
                        if (!$module = CMS_resourceModulesCatalog::getByCodename($codename)) {
 
91
                                return;
 
92
                        }
 
93
                }
 
94
                
 
95
                if ($module) {
 
96
                        $modules = array($module);
 
97
                } else {
 
98
                        $modules = CMS_modulesCatalog::getAll();
 
99
                }
 
100
                
 
101
                $validations = array();
 
102
                foreach ($modules as $aModule) {
 
103
                        if (!$user->hasValidationClearance($aModule->getID())) {
 
104
                                continue;
 
105
                        }
 
106
                        $validations_to_add = $aModule->getValidations($user);
 
107
                        if ($validations_to_add) {
 
108
                                $validations[$aModule->getCodename()] = $validations_to_add;
 
109
                        }
 
110
                }
 
111
                
 
112
                return $validations;
 
113
        }
 
114
}
 
115
 
 
116
?>
 
 
b'\\ No newline at end of file'