All Data Structures Functions Variables Pages
ConversationsSearchDataProviderMetadataAdapter.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 Zurmo Inc.
5  *
6  * Zurmo is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  *
13  * Zurmo is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  *
23  * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive
24  * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
25  *
26  * The interactive user interfaces in original and modified versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  *
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the Zurmo
32  * logo and Zurmo copyright notice. If the display of the logo is not reasonably
33  * feasible for technical reasons, the Appropriate Legal Notices must display the words
34  * "Copyright Zurmo Inc. 2017. All rights reserved".
35  ********************************************************************************/
36 
42  {
47  const LIST_TYPE_CREATED = 1;
48 
53  const LIST_TYPE_PARTICIPANT = 2;
54 
59  const LIST_TYPE_CLOSED = 3;
60 
61  protected $type;
62 
66  public function __construct($model, $userId, $metadata, $type)
67  {
68  assert('$type == self::LIST_TYPE_CREATED || $type == self::LIST_TYPE_PARTICIPANT || $type == self::LIST_TYPE_CLOSED');
69  parent::__construct($model, $userId, $metadata);
70  $this->type = $type;
71  }
72 
78  public function getAdaptedMetadata($appendStructureAsAnd = true)
79  {
80  $adaptedMetadata = parent::getAdaptedMetadata($appendStructureAsAnd);
81  $clauseCount = count($adaptedMetadata['clauses']);
82  $startingCount = $clauseCount + 1;
83  $structure = '';
84 
85  if ($this->type == self::LIST_TYPE_CREATED)
86  {
87  $adaptedMetadata['clauses'][$startingCount] = array(
88  'attributeName' => 'isClosed',
89  'operatorType' => 'isNull',
90  'value' => null
91  );
92  $adaptedMetadata['clauses'][$startingCount + 1] = array(
93  'attributeName' => 'isClosed',
94  'operatorType' => 'equals',
95  'value' => 0
96  );
97  $adaptedMetadata['clauses'][$startingCount + 2] = array(
98  'attributeName' => 'owner',
99  'operatorType' => 'equals',
100  'value' => Yii::app()->user->userModel->id
101  );
102  $structure .= '( ' . $startingCount . ' or ' . ($startingCount + 1) . ' ) and ' . ($startingCount + 2);
103  }
104  elseif ($this->type == self::LIST_TYPE_PARTICIPANT)
105  {
106  $adaptedMetadata['clauses'][$startingCount] = array(
107  'attributeName' => 'isClosed',
108  'operatorType' => 'isNull',
109  'value' => null
110  );
111  $adaptedMetadata['clauses'][$startingCount + 1] = array(
112  'attributeName' => 'isClosed',
113  'operatorType' => 'equals',
114  'value' => 0
115  );
116  $adaptedMetadata['clauses'][$startingCount + 2] = array(
117  'attributeName' => 'conversationParticipants',
118  'relatedAttributeName' => 'person',
119  'operatorType' => 'equals',
120  'value' => Yii::app()->user->userModel->getClassId('Item')
121  );
122  $adaptedMetadata['clauses'][$startingCount + 3] = array(
123  'attributeName' => 'owner',
124  'operatorType' => 'equals',
125  'value' => Yii::app()->user->userModel->id
126  );
127  $structure .= '( ' . $startingCount . ' or ' . ($startingCount + 1) . ' ) and (' . ($startingCount + 2) . ' or ' . ($startingCount + 3) . ')';
128  }
129  elseif ($this->type == self::LIST_TYPE_CLOSED)
130  {
131  $adaptedMetadata['clauses'][$startingCount] = array(
132  'attributeName' => 'isClosed',
133  'operatorType' => 'equals',
134  'value' => true
135  );
136  $adaptedMetadata['clauses'][$startingCount + 1] = array(
137  'attributeName' => 'conversationParticipants',
138  'relatedAttributeName' => 'person',
139  'operatorType' => 'equals',
140  'value' => Yii::app()->user->userModel->getClassId('Item')
141  );
142  $adaptedMetadata['clauses'][$startingCount + 2] = array(
143  'attributeName' => 'owner',
144  'operatorType' => 'equals',
145  'value' => Yii::app()->user->userModel->id
146  );
147  $structure .= $startingCount . ' and (' . ($startingCount + 1) . ' or ' . ($startingCount + 2) . ')';
148  }
149  if (empty($metadata['structure']))
150  {
151  $adaptedMetadata['structure'] = '(' . $structure . ')';
152  }
153  else
154  {
155  $adaptedMetadata['structure'] = '(' . $adaptedMetadata['structure'] . ') and (' . $structure . ')';
156  }
157  return $adaptedMetadata;
158  }
159  }
160 ?>
Generated on Tue May 26 2020 07:10:30