[ Index ]
 

Code source de eZ Publish 3.9.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/kernel/classes/ -> ezcollaborationitemparticipantlink.php (source)

   1  <?php
   2  //
   3  // Definition of eZCollaborationItemParticipantLink class
   4  //
   5  // Created on: <22-Jan-2003 16:08:22 amos>
   6  //
   7  // SOFTWARE NAME: eZ publish
   8  // SOFTWARE RELEASE: 3.9.0
   9  // BUILD VERSION: 17785
  10  // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS
  11  // SOFTWARE LICENSE: GNU General Public License v2.0
  12  // NOTICE: >
  13  //   This program is free software; you can redistribute it and/or
  14  //   modify it under the terms of version 2.0  of the GNU General
  15  //   Public License as published by the Free Software Foundation.
  16  //
  17  //   This program is distributed in the hope that it will be useful,
  18  //   but WITHOUT ANY WARRANTY; without even the implied warranty of
  19  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20  //   GNU General Public License for more details.
  21  //
  22  //   You should have received a copy of version 2.0 of the GNU General
  23  //   Public License along with this program; if not, write to the Free
  24  //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  25  //   MA 02110-1301, USA.
  26  //
  27  //
  28  
  29  /*! \file ezcollaborationparticipantlink.php
  30  */
  31  
  32  /*!
  33    \class eZCollaborationItemParticipantLink ezcollaborationitemparticipantlink.php
  34    \brief The class eZCollaborationItemParticipantLink does
  35  
  36  */
  37  
  38  define( "EZ_COLLABORATION_PARTICIPANT_TYPE_USER", 1 );
  39  define( "EZ_COLLABORATION_PARTICIPANT_TYPE_USERGROUP", 2 );
  40  
  41  // Everything from 1024 and above is considered custom and is specific per collaboration handler.
  42  define( "EZ_COLLABORATION_PARTICIPANT_TYPE_CUSTOM", 1024 );
  43  
  44  define( "EZ_COLLABORATION_PARTICIPANT_ROLE_STANDARD", 1 );
  45  define( "EZ_COLLABORATION_PARTICIPANT_ROLE_OBSERVER", 2 );
  46  define( "EZ_COLLABORATION_PARTICIPANT_ROLE_OWNER", 3 );
  47  define( "EZ_COLLABORATION_PARTICIPANT_ROLE_APPROVER", 4 );
  48  define( "EZ_COLLABORATION_PARTICIPANT_ROLE_AUTHOR", 5 );
  49  
  50  // Everything from 1024 and above is considered custom and is specific per collaboration handler.
  51  define( "EZ_COLLABORATION_PARTICIPANT_ROLE_CUSTOM", 1024 );
  52  
  53  include_once ( 'kernel/classes/ezpersistentobject.php' );
  54  
  55  class eZCollaborationItemParticipantLink extends eZPersistentObject
  56  {
  57      /*!
  58       Constructor
  59      */
  60      function eZCollaborationItemParticipantLink( $row )
  61      {
  62          $this->eZPersistentObject( $row );
  63      }
  64  
  65      function definition()
  66      {
  67          return array( 'fields' => array( 'collaboration_id' => array( 'name' => 'CollaborationID',
  68                                                                        'datatype' => 'integer',
  69                                                                        'default' => 0,
  70                                                                        'required' => true,
  71                                                                        'foreign_class' => 'eZCollaborationItem',
  72                                                                        'foreign_attribute' => 'id',
  73                                                                        'multiplicity' => '1..*' ),
  74                                           'participant_id' => array( 'name' => 'ParticipantID',
  75                                                                      'datatype' => 'integer',
  76                                                                      'default' => 0,
  77                                                                      'required' => true,
  78                                                                      'foreign_class' => 'eZContentObject',
  79                                                                      'foreign_attribute' => 'id',
  80                                                                      'multiplicity' => '1..*' ),
  81                                           'participant_type' => array( 'name' => 'ParticipantType',
  82                                                                        'datatype' => 'integer',
  83                                                                        'default' => 1,
  84                                                                        'required' => true ),
  85                                           'participant_role' => array( 'name' => 'ParticipantRole',
  86                                                                        'datatype' => 'integer',
  87                                                                        'default' => 1,
  88                                                                        'required' => true ),
  89                                           'last_read' => array( 'name' => 'LastRead',
  90                                                                 'datatype' => 'integer',
  91                                                                 'default' => 0,
  92                                                                 'required' => true ),
  93                                           'created' => array( 'name' => 'Created',
  94                                                               'datatype' => 'integer',
  95                                                               'default' => 0,
  96                                                               'required' => true ),
  97                                           'modified' => array( 'name' => 'Modified',
  98                                                                'datatype' => 'integer',
  99                                                                'default' => 0,
 100                                                                'required' => true ) ),
 101                        'keys' => array( 'collaboration_id', 'participant_id' ),
 102                        'function_attributes' => array( 'collaboration_item' => 'collaborationItem',
 103                                                        'participant' => 'participant',
 104                                                        'participant_type_string' => 'participantTypeString',
 105                                                        'participant_role_string' => 'participantRoleString',
 106                                                        'is_builtin_type' => 'isBuiltinType',
 107                                                        'is_builtin_role' => 'isBuiltinRole' ),
 108                        'class_name' => 'eZCollaborationItemParticipantLink',
 109                        'name' => 'ezcollab_item_participant_link' );
 110      }
 111  
 112      function &create( $collaborationID, $participantID,
 113                        $participantRole = EZ_COLLABORATION_PARTICIPANT_ROLE_STANDARD, $participantType = EZ_COLLABORATION_PARTICIPANT_TYPE_USER )
 114      {
 115          $dateTime = time();
 116          $row = array(   'collaboration_id' => $collaborationID,
 117                          'participant_id' => $participantID,
 118                          'participant_role' => $participantRole,
 119                          'participant_type' => $participantType,
 120                          'created' => $dateTime,
 121                          'modified' => $dateTime );
 122          $newCollaborationItemParticipantLink = new eZCollaborationItemParticipantLink( $row );
 123          return $newCollaborationItemParticipantLink;
 124      }
 125  
 126      /*!
 127       \note transaction unsafe
 128       */
 129      function setLastRead( $collaborationID, $userID = false, $timestamp = false )
 130      {
 131          if ( $userID === false )
 132          {
 133              include_once ( 'kernel/classes/datatypes/ezuser/ezuser.php' );
 134              $userID = eZUser::currentUserID();
 135          }
 136          if ( $timestamp === false )
 137          {
 138              $timestamp = time();
 139          }
 140          include_once ( 'lib/ezdb/classes/ezdb.php' );
 141          $db =& eZDB::instance();
 142          $userID = (int) $userID;
 143          $timestamp = (int) $timestamp;
 144          $sql = "UPDATE ezcollab_item_participant_link set last_read='$timestamp'
 145                  WHERE  collaboration_id='$collaborationID' AND participant_id='$userID'";
 146          $db->query( $sql );
 147          $collabLink =& $GLOBALS["eZCollaborationItemParticipantLinkCache"][$collaborationID][$userID];
 148          if ( isset( $collabLink ) )
 149              $collabLink->setAttribute( 'last_read', $timestamp );
 150      }
 151  
 152      function &fetch( $collaborationID, $participantID, $asObject = true )
 153      {
 154          $collabLink =& $GLOBALS["eZCollaborationItemParticipantLinkCache"][$collaborationID][$participantID];
 155          if ( isset( $collabLink ) )
 156              return $collabLink;
 157          $collabLink = eZPersistentObject::fetchObject( eZCollaborationItemParticipantLink::definition(),
 158                                                         null,
 159                                                         array( "collaboration_id" => $collaborationID,
 160                                                                'participant_id' => $participantID ),
 161                                                         $asObject );
 162          return $collabLink;
 163      }
 164  
 165      function &fetchParticipantList( $parameters = array() )
 166      {
 167          $parameters = array_merge( array( 'as_object' => true,
 168                                            'item_id' => false,
 169                                            'offset' => false,
 170                                            'limit' => false,
 171                                            'sort_by' => false ),
 172                                     $parameters );
 173          $itemID = $parameters['item_id'];
 174          $asObject = $parameters['as_object'];
 175          $offset = $parameters['offset'];
 176          $limit = $parameters['limit'];
 177          $linkList = null;
 178          if ( !$offset and !$limit )
 179          {
 180              $linkList =& $GLOBALS['eZCollaborationItemParticipantLinkListCache'];
 181              if ( isset( $linkList ) )
 182                  return $linkList;
 183          }
 184          $limitArray = null;
 185          if ( $offset and $limit )
 186              $limitArray = array( 'offset' => $offset, 'length' => $limit );
 187          $linkList = eZPersistentObject::fetchObjectList( eZCollaborationItemParticipantLink::definition(),
 188                                                            null,
 189                                                            array( "collaboration_id" => $itemID ),
 190                                                            null, $limitArray,
 191                                                            $asObject );
 192          for ( $i = 0; $i < count( $linkList ); ++$i )
 193          {
 194              $linkItem =& $linkList[$i];
 195              if ( $asObject )
 196                  $participantID =& $linkItem->attribute( 'participant_id' );
 197              else
 198                  $participantID =& $linkItem['participant_id'];
 199              if ( !isset( $GLOBALS["eZCollaborationItemParticipantLinkCache"][$itemID][$participantID] ) )
 200                  $GLOBALS["eZCollaborationItemParticipantLinkCache"][$itemID][$participantID] =& $linkList[$i];
 201          }
 202          return $linkList;
 203      }
 204  
 205      function &fetchParticipantMap( $originalParameters = array() )
 206      {
 207          $parameters = array_merge( array( 'sort_field' => 'role' ),
 208                                     $originalParameters );
 209          $itemID = $parameters['item_id'];
 210          $sortField = $parameters['sort_field'];
 211          $list =& eZCollaborationItemParticipantLink::fetchParticipantList( $originalParameters );
 212          if ( $list === null )
 213          {
 214              $listMap = null;
 215              return $listMap;
 216          }
 217  
 218          $listKeys = array_keys( $list );
 219          $listMap = array();
 220          foreach ( $listKeys as $listKey )
 221          {
 222              $listItem =& $list[$listKey];
 223              $sortKey = null;
 224              if ( $sortField == 'role' )
 225              {
 226                  $sortKey = $listItem->attribute( 'participant_role' );
 227              }
 228              if ( $sortKey !== null )
 229              {
 230                  if ( !isset( $listMap[$sortKey] ) )
 231                  {
 232                      if ( $sortField == 'role' )
 233                      {
 234                          $sortName = eZCollaborationItemParticipantLink::roleName( $itemID, $sortKey );
 235                      }
 236                      $listMap[$sortKey] = array( 'name' => $sortName,
 237                                                  'items' => array() );
 238                  }
 239                  $listMap[$sortKey]['items'][] =& $listItem;
 240              }
 241          }
 242          return $listMap;
 243      }
 244  
 245      function &typeString( $participantType )
 246      {
 247          $typeMap =& $GLOBALS['eZCollaborationParticipantTypeMap'];
 248          if ( !isset( $typeMap ) )
 249          {
 250              $typeMap = array( EZ_COLLABORATION_PARTICIPANT_TYPE_USER => 'user',
 251                                EZ_COLLABORATION_PARTICIPANT_TYPE_USERGROUP => 'usergroup' );
 252          }
 253          if ( isset( $typeMap[$participantType] ) )
 254              $retString = $typeMap[$participantType];
 255          else
 256              $retString = null;
 257          return $retString;
 258      }
 259  
 260      function &roleString( $participantRole )
 261      {
 262          $roleMap =& $GLOBALS['eZCollaborationParticipantRoleMap'];
 263          if ( !isset( $roleMap ) )
 264          {
 265              $roleMap = array( EZ_COLLABORATION_PARTICIPANT_ROLE_STANDARD => 'standard',
 266                                EZ_COLLABORATION_PARTICIPANT_ROLE_OBSERVER => 'observer',
 267                                EZ_COLLABORATION_PARTICIPANT_ROLE_OWNER => 'owner',
 268                                EZ_COLLABORATION_PARTICIPANT_ROLE_APPROVER => 'approver',
 269                                EZ_COLLABORATION_PARTICIPANT_ROLE_AUTHOR => 'author' );
 270          }
 271          if ( isset( $roleMap[$participantRole] ) )
 272              $retString = $roleMap[$participantRole];
 273          else
 274              $retString = null;
 275          return $retString;
 276      }
 277  
 278      function &roleName( $collaborationID, $roleID )
 279      {
 280          if ( $roleID < EZ_COLLABORATION_PARTICIPANT_TYPE_CUSTOM )
 281          {
 282              $roleNameMap =& $GLOBALS['eZCollaborationParticipantRoleNameMap'];
 283              if ( !isset( $roleNameMap ) )
 284              {
 285                  include_once ( 'kernel/common/i18n.php' );
 286                  $roleNameMap = array( EZ_COLLABORATION_PARTICIPANT_ROLE_STANDARD => ezi18n( 'kernel/classes', 'Standard' ),
 287                                        EZ_COLLABORATION_PARTICIPANT_ROLE_OBSERVER => ezi18n( 'kernel/classes', 'Observer' ),
 288                                        EZ_COLLABORATION_PARTICIPANT_ROLE_OWNER => ezi18n( 'kernel/classes', 'Owner' ),
 289                                        EZ_COLLABORATION_PARTICIPANT_ROLE_APPROVER => ezi18n( 'kernel/classes', 'Approver' ),
 290                                        EZ_COLLABORATION_PARTICIPANT_ROLE_AUTHOR => ezi18n( 'kernel/classes', 'Author' ) );
 291              }
 292              if ( isset( $roleNameMap[$roleID] ) )
 293                  $retRoleName = $roleNameMap[$roleID];
 294              else
 295                  $retRoleName = null;
 296          }
 297          else
 298          {
 299              $item = eZCollaborationItem::fetch( $collaborationID );
 300              $itemHandler =& $item->handler();
 301              $retRoleName = $itemHandler->roleName( $collaborationID, $roleID );
 302          }
 303          return $retRoleName;
 304      }
 305  
 306      function &collaborationItem()
 307      {
 308          include_once ( 'kernel/classes/ezcollaborationitem.php' );
 309          $item = eZCollaborationItem::fetch( $this->CollaborationID );
 310          return $item;
 311      }
 312  
 313      function &participant()
 314      {
 315          if ( $this->ParticipantType == EZ_COLLABORATION_PARTICIPANT_TYPE_USER )
 316          {
 317              include_once ( 'kernel/classes/datatypes/ezuser/ezuser.php' );
 318              $participant = eZUser::fetch( $this->ParticipantID );
 319          }
 320          else if ( $this->ParticipantType == EZ_COLLABORATION_PARTICIPANT_TYPE_USERGROUP )
 321          {
 322              include_once ( 'kernel/classes/ezcontentobject.php' );
 323              $participant =& eZContentObject::fetch( $this->ParticipantID );
 324          }
 325          else
 326          {
 327              $participant = null;
 328          }
 329          return $participant;
 330      }
 331  
 332      function &participantTypeString()
 333      {
 334          if ( $this->ParticipantType < EZ_COLLABORATION_PARTICIPANT_TYPE_CUSTOM )
 335          {
 336              $typeString =& eZCollaborationItemParticipantLink::typeString( $this->ParticipantType );
 337          }
 338          else
 339          {
 340              $item = eZCollaborationItem::fetch( $this->CollaborationID );
 341              $itemHandler =& $item->handler();
 342              $typeString = $item->attribute( 'type_identifier' ) . '_' . $itemHandler->participantTypeString( $this->ParticipantType );
 343          }
 344          return $typeString;
 345      }
 346  
 347      function &participantRoleString()
 348      {
 349          if ( $this->ParticipantRole < EZ_COLLABORATION_PARTICIPANT_ROLE_CUSTOM )
 350          {
 351              $roleString =& eZCollaborationItemParticipantLink::roleString( $this->ParticipantRole );
 352          }
 353          else
 354          {
 355              $item = eZCollaborationItem::fetch( $this->CollaborationID );
 356              $itemHandler =& $item->handler();
 357              $roleString = $item->attribute( 'type_identifier' ) . '_' . $itemHandler->participantRoleString( $this->ParticipantRole );
 358          }
 359          return $roleString;
 360      }
 361  
 362      function &isBuiltinType()
 363      {
 364          $isBuiltinType = $this->ParticipantType < EZ_COLLABORATION_PARTICIPANT_TYPE_CUSTOM;
 365          return $isBuiltinType;
 366      }
 367  
 368      function &isBuiltinRole()
 369      {
 370          $isBuiltinRole = $this->ParticipantRole < EZ_COLLABORATION_PARTICIPANT_ROLE_CUSTOM;
 371          return $isBuiltinRole;
 372      }
 373  
 374      /// \privatesection
 375      var $CollaborationID;
 376      var $ParticipantID;
 377      var $ParticipantType;
 378      var $IsRead;
 379      var $IsActive;
 380      var $Created;
 381      var $Modified;
 382  }
 383  
 384  ?>


Généré le : Sat Feb 24 10:30:04 2007 par Balluche grâce à PHPXref 0.7