[ Index ]
 

Code source de eZ Publish 3.9.0

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

title

Body

[fermer]

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

   1  <?php
   2  //
   3  // Definition of eZCollaborationGroup class
   4  //
   5  // Created on: <22-Jan-2003 15:31:16 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 ezcollaborationgroup.php
  30  */
  31  
  32  /*!
  33    \class eZCollaborationGroup ezcollaborationgroup.php
  34    \brief The class eZCollaborationGroup does
  35  
  36  */
  37  
  38  include_once ( 'kernel/classes/ezpersistentobject.php' );
  39  include_once ( 'kernel/classes/ezcollaborationitem.php' );
  40  
  41  class eZCollaborationGroup extends eZPersistentObject
  42  {
  43      /*!
  44       Constructor
  45      */
  46      function eZCollaborationGroup( $row )
  47      {
  48          $this->eZPersistentObject( $row );
  49      }
  50  
  51      function definition()
  52      {
  53          return array( 'fields' => array( 'id' => array( 'name' => 'ID',
  54                                                          'datatype' => 'integer',
  55                                                          'default' => 0,
  56                                                          'required' => true ),
  57                                           'parent_group_id' => array( 'name' => 'ParentGroupID',
  58                                                                       'datatype' => 'integer',
  59                                                                       'default' => 0,
  60                                                                       'required' => true,
  61                                                                       'foreign_class' => 'eZCollaborationGroup',
  62                                                                       'foreign_attribute' => 'id',
  63                                                                       'multiplicity' => '1..*' ),
  64                                           'depth' => array( 'name' => 'Depth',
  65                                                             'datatype' => 'integer',
  66                                                             'default' => 0,
  67                                                             'required' => true ),
  68                                           'path_string' => array( 'name' => 'PathString',
  69                                                                   'datatype' => 'string',
  70                                                                   'default' => '',
  71                                                                   'required' => true ),
  72                                           'is_open' => array( 'name' => 'IsOpen',
  73                                                               'datatype' => 'integer',
  74                                                               'default' => '1',
  75                                                               'required' => true ),
  76                                           'user_id' => array( 'name' => 'UserID',
  77                                                               'datatype' => 'integer',
  78                                                               'default' => '0',
  79                                                               'required' => true,
  80                                                               'foreign_class' => 'eZUser',
  81                                                               'foreign_attribute' => 'contentobject_id',
  82                                                               'multiplicity' => '1..*' ),
  83                                           'title' => array( 'name' => 'Title',
  84                                                             'datatype' => 'string',
  85                                                             'default' => '',
  86                                                             'required' => true ),
  87                                           'created' => array( 'name' => 'Created',
  88                                                               'datatype' => 'integer',
  89                                                               'default' => '0',
  90                                                               'required' => true ),
  91                                           'modified' =>  array( 'name' => 'Modified',
  92                                                                 'datatype' => 'integer',
  93                                                                 'default' => '0',
  94                                                                 'required' => true ) ),
  95                        'keys' => array( 'id' ),
  96                        "function_attributes" => array( 'user' => 'user',
  97                                                        'parent_group' => 'parentGroup',
  98                                                        'item_list' => 'itemList',
  99                                                        'item_count' => 'itemCount' ),
 100                        'increment_key' => 'id',
 101                        'class_name' => 'eZCollaborationGroup',
 102                        'sort' => array( 'title' => 'asc' ),
 103                        'name' => 'ezcollab_group' );
 104      }
 105  
 106      /*!
 107       \note Transaction unsafe. If you call several transaction unsafe methods you must enclose
 108       the calls within a db transaction; thus within db->begin and db->commit.
 109       */
 110      function addChild( &$group, $store = true )
 111      {
 112          $pathString = $this->PathString;
 113          if ( $pathString != '' )
 114              $pathString .= '/';
 115          $pathString .= $this->ID;
 116          $depth = $this->Depth + 1;
 117          $parentGroupID = $this->ID;
 118          $group->setAttribute( 'path_string', $pathString );
 119          $group->setAttribute( 'parent_group_id', $parentGroupID );
 120          $group->setAttribute( 'depth', $depth );
 121          if ( $store )
 122              $group->sync();
 123      }
 124  
 125      /*!
 126       \note Transaction unsafe. If you call several transaction unsafe methods you must enclose
 127       the calls within a db transaction; thus within db->begin and db->commit.
 128       */
 129      function &instantiate( $userID, $title, $parentGroupID = 0, $isOpen = true )
 130      {
 131          $depth = 0;
 132          $pathString = '';
 133          if ( $parentGroupID > 0 )
 134          {
 135              $parentGroup = eZCollaborationGroup::fetch( $parentGroupID, $userID );
 136              $depth = $parentGroup->attribute( 'depth' ) + 1;
 137              $pathString = $parentGroup->attribute( 'path_string' );
 138          }
 139          $group = eZCollaborationGroup::create( $userID, $title, '', $depth, $parentGroupID, $isOpen );
 140  
 141          $db =& eZDB::instance();
 142          $db->begin();
 143  
 144          $group->store();
 145          if ( $pathString == '' )
 146              $pathString = $group->attribute( 'id' );
 147          else
 148              $pathString .= '/' . $group->attribute( 'id' );
 149          $group->setAttribute( 'path_string', $pathString );
 150          $group->sync();
 151  
 152          $db->commit();
 153          return $group;
 154      }
 155  
 156      function create( $userID, $title, $pathString = '', $depth = 0, $parentGroupID = 0, $isOpen = true )
 157      {
 158          $date_time = time();
 159          $row = array(
 160              'id' => null,
 161              'parent_group_id' => $parentGroupID,
 162              'path_string' => $pathString,
 163              'depth' => $depth,
 164              'is_open' => $isOpen,
 165              'user_id' => $userID,
 166              'title' => $title,
 167              'created' => $date_time,
 168              'modified' => $date_time );
 169          return new eZCollaborationGroup( $row );
 170      }
 171  
 172      function fetch( $id, $userID = false, $asObject = true )
 173      {
 174          $conditions = array( "id" => $id );
 175          if ( $userID !== false )
 176              $conditions['user_id'] = $userID;
 177          return eZPersistentObject::fetchObject( eZCollaborationGroup::definition(),
 178                                                  null,
 179                                                  $conditions,
 180                                                  $asObject );
 181      }
 182  
 183      /*!
 184       \return an array with collaboration items which are in this group.
 185      */
 186      function &itemList( $parameters = array() )
 187      {
 188          $itemList = eZCollaborationItem::fetchList( array_merge( array( 'parent_group_id' => $this->ID ),
 189                                                                   $parameters ) );
 190          return $itemList;
 191      }
 192  
 193      function &subTree( $parameters = array() )
 194      {
 195          $parameters = array_merge( array( 'parent_group_id' => false,
 196                                            'depth' => false,
 197                                            'sort_by' => false,
 198                                            'as_object' => true,
 199                                            'offset' => false,
 200                                            'limit' => false ),
 201                                     $parameters );
 202          $parentGroupID = $parameters['parent_group_id'];
 203          $depth = $parameters['depth'];
 204          $asObject = $parameters['as_object'];
 205          $offset = $parameters['offset'];
 206          $limit = $parameters['limit'];
 207  
 208          $group = null;
 209          if ( $parentGroupID > 0 )
 210              $group = eZCollaborationGroup::fetch( $parentGroupID );
 211  
 212          $sortCount = 0;
 213          $sortList = $parameters['sort_by'];
 214          if ( is_array( $sortList ) and
 215               count( $sortList ) > 0 )
 216          {
 217              if ( count( $sortList ) > 1 and
 218                   !is_array( $sortList[0] ) )
 219              {
 220                  $sortList = array( $sortList );
 221              }
 222          }
 223          if ( $sortList !== false )
 224          {
 225              $sortingFields = '';
 226              foreach ( $sortList as $sortBy )
 227              {
 228                  if ( is_array( $sortBy ) and count( $sortBy ) > 0 )
 229                  {
 230                      if ( $sortCount > 0 )
 231                          $sortingFields .= ', ';
 232                      $sortField = $sortBy[0];
 233                      switch ( $sortField )
 234                      {
 235                          case 'path':
 236                          {
 237                              $sortingFields .= 'path_string';
 238                          } break;
 239                          case 'created':
 240                          {
 241                              $sortingFields .= 'created';
 242                          } break;
 243                          case 'modified':
 244                          {
 245                              $sortingFields .= 'modified';
 246                          } break;
 247                          case 'depth':
 248                          {
 249                              $sortingFields .= 'depth';
 250                          } break;
 251                          case 'priority':
 252                          {
 253                              $sortingFields .= 'priority';
 254                          } break;
 255                          case 'title':
 256                          {
 257                              $sortingFields .= 'title';
 258                          } break;
 259                          default:
 260                          {
 261                              eZDebug::writeWarning( 'Unknown sort field: ' . $sortField, 'eZCollaboration::subTree' );
 262                              continue;
 263                          };
 264                      }
 265                      $sortOrder = true; // true is ascending
 266                      if ( isset( $sortBy[1] ) )
 267                          $sortOrder = $sortBy[1];
 268                      $sortingFields .= $sortOrder ? " ASC" : " DESC";
 269                      ++$sortCount;
 270                  }
 271              }
 272          }
 273          if ( $sortCount == 0 )
 274          {
 275              $sortingFields = " path_string ASC";
 276          }
 277  
 278          $pathString = '';
 279          if ( $group !== null )
 280              $pathString = $group->attribute( 'path_string' );
 281  
 282          $depthSQL = "";
 283          if ( $depth !== false )
 284              $depthSQL = "depth <= '$depth' AND";
 285          $pathSQL = '';
 286          if ( $pathString != '' )
 287              $pathSQL = "path_string like '$pathString%' AND";
 288  
 289          $user =& eZUser::currentUser();
 290          $userID =& $user->attribute( 'contentobject_id' );
 291  
 292          $sql = "SELECT *
 293                  FROM
 294                        ezcollab_group
 295                  WHERE
 296                        $pathSQL
 297                        $depthSQL
 298                        id != '$parentGroupID' AND
 299                        user_id = '$userID'
 300                  ORDER BY $sortingFields";
 301  
 302          $db =& eZDB::instance();
 303          $sqlParameters = array();
 304          if ( $offset !== false and $limit !== false )
 305          {
 306              $sqlParameters['offset'] = $offset;
 307              $sqlParameters['limit'] = $limit;
 308          }
 309          $groupListArray = $db->arrayQuery( $sql, $sqlParameters );
 310          $returnGroupList = eZPersistentObject::handleRows( $groupListArray, 'eZCollaborationGroup', $asObject );
 311          eZDebugSetting::writeDebug( 'collaboration-group-tree', $returnGroupList );
 312          return $returnGroupList;
 313      }
 314  
 315      function &itemCount( $parameters = array() )
 316      {
 317          $parameters = array_merge( array( 'as_object' => true ),
 318                                     $parameters );
 319          $asObject = $parameters['as_object'];
 320  
 321          $user =& eZUser::currentUser();
 322          $userID =& $user->attribute( 'contentobject_id' );
 323  
 324          $groupID = $this->ID;
 325  
 326          $db =& eZDB::instance();
 327          $sql = "SELECT   count( collaboration_id ) as count
 328                  FROM     ezcollab_item_group_link
 329                  WHERE    user_id = '$userID' AND
 330                           group_id = '$groupID'";
 331          $countArray = $db->arrayQuery( $sql );
 332          return $countArray[0]['count'];
 333      }
 334  
 335      function &user()
 336      {
 337          if ( isset( $this->UserID ) and $this->UserID )
 338          {
 339              include_once ( 'kernel/classes/datatypes/ezuser/ezuser.php' );
 340              $user = eZUser::fetch( $this->UserID );
 341          }
 342          else
 343              $user = null;
 344          return $user;
 345      }
 346  
 347      function &parentGroup()
 348      {
 349          if ( isset( $this->ParentGroupID ) and $this->ParentGroupID )
 350              $parentGroup = eZCollaborationGroup::fetch( $this->ParentGroupID );
 351          else
 352              $parentGroup = null;
 353          return $parentGroup;
 354      }
 355  
 356      /// \privatesection
 357      var $ID;
 358      var $ParentGroupID;
 359      var $UserID;
 360      var $Title;
 361      var $Created;
 362      var $Modified;
 363  }
 364  
 365  ?>


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