/kernel/classes/ezcollaborationitemgrouplink.php

https://github.com/lserwatka/ezpublish · PHP · 191 lines · 136 code · 16 blank · 39 comment · 9 complexity · 67e5ab9598f6de02f4120c4a328d27fa MD5 · raw file

  1. <?php
  2. //
  3. // Definition of eZCollaborationItemGroupLink class
  4. //
  5. // Created on: <22-Jan-2003 15:51:09 amos>
  6. //
  7. // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
  8. // SOFTWARE NAME: eZ Publish
  9. // SOFTWARE RELEASE: 4.1.x
  10. // COPYRIGHT NOTICE: Copyright (C) 1999-2010 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. // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
  29. //
  30. /*! \file
  31. */
  32. /*!
  33. \class eZCollaborationItemGroupLink ezcollaborationitemgrouplink.php
  34. \brief The class eZCollaborationItemGroupLink does
  35. */
  36. class eZCollaborationItemGroupLink extends eZPersistentObject
  37. {
  38. /*!
  39. Constructor
  40. */
  41. function eZCollaborationItemGroupLink( $row )
  42. {
  43. $this->eZPersistentObject( $row );
  44. }
  45. static function definition()
  46. {
  47. return array( 'fields' => array( 'collaboration_id' => array( 'name' => 'CollaborationID',
  48. 'datatype' => 'integer',
  49. 'default' => 0,
  50. 'required' => true,
  51. 'foreign_class' => 'eZCollaborationItem',
  52. 'foreign_attribute' => 'id',
  53. 'multiplicity' => '1..*' ),
  54. 'group_id' => array( 'name' => 'GroupID',
  55. 'datatype' => 'integer',
  56. 'default' => 0,
  57. 'required' => true,
  58. 'foreign_class' => 'eZCollaborationGroup',
  59. 'foreign_attribute' => 'id',
  60. 'multiplicity' => '1..*' ),
  61. 'user_id' => array( 'name' => 'UserID',
  62. 'datatype' => 'integer',
  63. 'default' => 0,
  64. 'required' => true,
  65. 'foreign_class' => 'eZUser',
  66. 'foreign_attribute' => 'contentobject_id',
  67. 'multiplicity' => '1..*' ),
  68. 'is_read' => array( 'name' => 'IsRead',
  69. 'datatype' => 'integer',
  70. 'default' => 0,
  71. 'required' => true ),
  72. 'is_active' => array( 'name' => 'IsActive',
  73. 'datatype' => 'integer',
  74. 'default' => 1,
  75. 'required' => true ),
  76. 'last_read' => array( 'name' => 'LastRead',
  77. 'datatype' => 'integer',
  78. 'default' => 0,
  79. 'required' => true ),
  80. 'created' => array( 'name' => 'Created',
  81. 'datatype' => 'integer',
  82. 'default' => 0,
  83. 'required' => true ),
  84. 'modified' => array( 'name' => 'Modified',
  85. 'datatype' => 'integer',
  86. 'default' => 0,
  87. 'required' => true ) ),
  88. 'keys' => array( 'collaboration_id', 'group_id', 'user_id' ),
  89. 'function_attributes' => array( 'user' => 'user',
  90. 'collaboration_item' => 'collaborationItem',
  91. 'collaboration_group' => 'collaborationGroup' ),
  92. 'class_name' => 'eZCollaborationItemGroupLink',
  93. 'sort' => array( 'modified' => 'asc' ),
  94. 'name' => 'ezcollab_item_group_link' );
  95. }
  96. static function create( $collaborationID, $groupID, $userID )
  97. {
  98. $date_time = time();
  99. $row = array(
  100. 'collaboration_id' => $collaborationID,
  101. 'group_id' => $groupID,
  102. 'is_read' => false,
  103. 'is_active' => true,
  104. 'last_read' => 0,
  105. 'user_id' => $userID,
  106. 'created' => $date_time,
  107. 'modified' => $date_time );
  108. return new eZCollaborationItemGroupLink( $row );
  109. }
  110. static function addItem( $groupID, $collaborationID, $userID )
  111. {
  112. $groupLink = eZCollaborationItemGroupLink::create( $collaborationID, $groupID, $userID );
  113. $db = eZDB::instance();
  114. $db->begin();
  115. $groupLink->store();
  116. $itemStatus = eZCollaborationItemStatus::create( $collaborationID, $userID );
  117. $itemStatus->store();
  118. $db->commit();
  119. return $groupLink;
  120. }
  121. function fetch( $collaborationID, $groupID, $userID = false, $asObject = true )
  122. {
  123. if ( $userID == false )
  124. $userID == eZUser::currentUserID();
  125. return eZPersistentObject::fetchObject( eZCollaborationItemGroupLink::definition(),
  126. null,
  127. array( 'collaboration_id' => $collaborationID,
  128. 'group_id' => $groupID,
  129. 'user_id' => $userID ),
  130. $asObject );
  131. }
  132. function fetchList( $collaborationID, $userID = false, $asObject = true )
  133. {
  134. if ( $userID == false )
  135. $userID == eZUser::currentUserID();
  136. return eZPersistentObject::fetchObjectList( eZCollaborationItemGroupLink::definition(),
  137. null,
  138. array( 'collaboration_id' => $collaborationID,
  139. 'user_id' => $userID ),
  140. null, null,
  141. $asObject );
  142. }
  143. function user()
  144. {
  145. if ( isset( $this->UserID ) and $this->UserID )
  146. {
  147. return eZUser::fetch( $this->UserID );
  148. }
  149. return null;
  150. }
  151. function collaborationItem()
  152. {
  153. if ( isset( $this->CollaborationID ) and $this->CollaborationID )
  154. {
  155. return eZCollaborationItem::fetch( $this->CollaborationID, $this->UserID );
  156. }
  157. return null;
  158. }
  159. function collaborationGroup()
  160. {
  161. if ( isset( $this->GroupID ) and $this->GroupID )
  162. {
  163. return eZCollaborationGroup::fetch( $this->GroupID, $this->UserID );
  164. }
  165. return null;
  166. }
  167. /// \privatesection
  168. public $CollaborationID;
  169. public $GroupID;
  170. public $UserID;
  171. public $Created;
  172. public $Modified;
  173. }
  174. ?>