Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
Dashboard.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 
38  {
39  const DEFAULT_USER_LAYOUT_ID = 1;
40 
46  public static function getByLayoutIdAndUser($layoutId, $user)
47  {
48  assert('is_integer($layoutId) && $layoutId >= 1');
49  assert('$user instanceof User && $user->id > 0');
50  $sql = 'select dashboard.id id ' .
51  'from dashboard, ownedsecurableitem ' .
52  'where ownedsecurableitem.owner__user_id = ' . $user->id .
53  ' and dashboard.ownedsecurableitem_id = ownedsecurableitem.id '.
54  ' and layoutid = ' . $layoutId .
55  ' order by layoutId;';
56  $ids = ZurmoRedBean::getCol($sql);
57  assert('count($ids) <= 1');
58  if (count($ids) == 0)
59  {
60  if ($layoutId == Dashboard::DEFAULT_USER_LAYOUT_ID)
61  {
63  }
64  throw new NotFoundException();
65  }
66  $bean = ZurmoRedBean::load(Dashboard::getTableName(), $ids[0]);
67  assert('$bean === false || $bean instanceof RedBean_OODBBean');
68  if ($bean === false)
69  {
70  throw new NotFoundException();
71  }
72  return self::makeModel($bean);
73  }
74 
79  public static function getRowsByUserId($userId)
80  {
81  assert('is_integer($userId) && $userId >= 1');
82  $sql = 'select dashboard.id id, dashboard.name name, layoutid layoutId ' .
83  'from dashboard, ownedsecurableitem ' .
84  'where ownedsecurableitem.owner__user_id = ' . $userId .
85  ' and dashboard.ownedsecurableitem_id = ownedsecurableitem.id ' .
86  'order by layoutId;';
87  return ZurmoRedBean::getAll($sql);
88  }
89 
90  public static function getNextLayoutId()
91  {
92  return max(2, (int)ZurmoRedBean::getCell('select max(layoutId) + 1 from dashboard'));
93  }
94 
95  protected static function translatedAttributeLabels($language)
96  {
97  return array_merge(parent::translatedAttributeLabels($language),
98  array(
99  'layoutId' => Zurmo::t('HomeModule', 'Layout Id', array(), null, $language),
100  'layoutType' => Zurmo::t('HomeModule', 'Layout Type', array(), null, $language),
101  'isDefault' => Zurmo::t('HomeModule', 'Is Default', array(), null, $language),
102  'name' => Zurmo::t('Core', 'Name', array(), null, $language),
103  )
104  );
105  }
106 
107  public function __toString()
108  {
109  try
110  {
111  if (trim($this->name) == '')
112  {
113  return Zurmo::t('Core', '(Unnamed)');
114  }
115  return $this->name;
116  }
118  {
119  return '';
120  }
121  }
122 
123  public static function getDefaultMetadata()
124  {
125  $metadata = parent::getDefaultMetadata();
126  $metadata[__CLASS__] = array(
127  'members' => array(
128  'layoutId',
129  'layoutType',
130  'isDefault',
131  'name',
132  ),
133  'rules' => array(
134  array('isDefault', 'boolean'),
135  array('layoutId', 'required'),
136  array('layoutId', 'type', 'type' => 'integer'),
137  array('layoutType', 'required'),
138  array('layoutType', 'type', 'type' => 'string'),
139  array('layoutType', 'length', 'max' => 10),
140  array('name', 'required'),
141  array('name', 'type', 'type' => 'string'),
142  array('name', 'length', 'min' => 1, 'max' => 64),
143  ),
144  'defaultSortAttribute' => 'name'
145  );
146  return $metadata;
147  }
148 
154  public static function setDefaultDashboardForUser($user)
155  {
156  assert('$user instanceof User && $user->id > 0');
157  $dashboard = new Dashboard();
158  $dashboard->name = Zurmo::t('ZurmoModule', 'Dashboard');
159  $dashboard->layoutId = Dashboard::DEFAULT_USER_LAYOUT_ID;
160  $dashboard->owner = $user;
161  $dashboard->layoutType = '50,50'; // Not Coding Standard
162  $dashboard->isDefault = true;
163  $saved = $dashboard->save();
164  assert('$saved'); // TODO - deal with the properly.
165  return $dashboard;
166  }
167 
168  public static function isTypeDeletable()
169  {
170  return true;
171  }
172 
173  public static function getModuleClassName()
174  {
175  return 'HomeModule';
176  }
177 
181  public static function getLayoutTypesData()
182  {
183  return array(
184  '100' => Zurmo::t('HomeModule', '{number} Column', array('{number}' => 1)),
185  '50,50' => Zurmo::t('HomeModule', '{number} Columns', array('{number}' => 2)), // Not Coding Standard
186  '75,25' => Zurmo::t('HomeModule', '{number} Columns Left Strong', array('{number}' => 2)), // Not Coding Standard
187  );
188  }
189 
195  protected static function getLabel($language = null)
196  {
197  return Zurmo::t('ZurmoModule', 'Dashboard', array(), null, $language);
198  }
199 
205  protected static function getPluralLabel($language = null)
206  {
207  return Zurmo::t('ZurmoModule', 'Dashboards', array(), null, $language);
208  }
209 
210  public static function getDefaultDashboardsByUser($user)
211  {
212  $searchAttributeData['clauses'] = array(
213  1 => array(
214  'attributeName' => 'owner',
215  'operatorType' => 'equals',
216  'value' => $user->id,
217  ),
218  2 => array(
219  'attributeName' => 'isDefault',
220  'operatorType' => 'equals',
221  'value' => 1,
222  )
223  );
224  $searchAttributeData['structure'] = '1 and 2';
225  $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter(get_called_class());
226  $where = RedBeanModelDataProvider::makeWhere(get_called_class(), $searchAttributeData, $joinTablesAdapter);
227  return self::getSubset($joinTablesAdapter, null, null, $where);
228  }
229  }
230 ?>
static getByLayoutIdAndUser($layoutId, $user)
Definition: Dashboard.php:46
static getRowsByUserId($userId)
Definition: Dashboard.php:79
static getPluralLabel($language=null)
Definition: Dashboard.php:205
static setDefaultDashboardForUser($user)
Definition: Dashboard.php:154
static getLabel($language=null)
Definition: Dashboard.php:195
static makeWhere($modelClassName, array $metadata, &$joinTablesAdapter)
static getTableName()
static getLayoutTypesData()
Definition: Dashboard.php:181
Generated on Sun Oct 25 2020 07:10:30
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.