[ Index ] |
PHP Cross Reference of vtigercrm-6.1.0 |
[Summary view] [Print] [Text view]
1 <?php 2 /*+*********************************************************************************** 3 * The contents of this file are subject to the vtiger CRM Public License Version 1.0 4 * ("License"); You may not use this file except in compliance with the License 5 * The Original Code is: vtiger CRM Open Source 6 * The Initial Developer of the Original Code is vtiger. 7 * Portions created by vtiger are Copyright (C) vtiger. 8 * All Rights Reserved. 9 *************************************************************************************/ 10 11 vimport('~~/vtlib/Vtiger/Module.php'); 12 13 /** 14 * Calendar Module Model Class 15 */ 16 class Calendar_Module_Model extends Vtiger_Module_Model { 17 18 /** 19 * Function returns the default view for the Calendar module 20 * @return <String> 21 */ 22 public function getDefaultViewName() { 23 return $this->getCalendarViewName(); 24 } 25 26 /** 27 * Function returns the calendar view name 28 * @return <String> 29 */ 30 public function getCalendarViewName() { 31 return 'Calendar'; 32 } 33 34 /** 35 * Function returns the url for Calendar view 36 * @return <String> 37 */ 38 public function getCalendarViewUrl() { 39 return 'index.php?module='.$this->get('name').'&view='.$this->getCalendarViewName(); 40 } 41 42 /** 43 * Function to check whether the module is summary view supported 44 * @return <Boolean> - true/false 45 */ 46 public function isSummaryViewSupported() { 47 return false; 48 } 49 50 /** 51 * Function returns the URL for creating Events 52 * @return <String> 53 */ 54 public function getCreateEventRecordUrl() { 55 return 'index.php?module='.$this->get('name').'&view='.$this->getEditViewName().'&mode=Events'; 56 } 57 58 /** 59 * Function returns the URL for creating Task 60 * @return <String> 61 */ 62 public function getCreateTaskRecordUrl() { 63 return 'index.php?module='.$this->get('name').'&view='.$this->getEditViewName().'&mode=Calendar'; 64 } 65 66 /** 67 * Function that returns related list header fields that will be showed in the Related List View 68 * @return <Array> returns related fields list. 69 */ 70 public function getRelatedListFields() { 71 $entityInstance = CRMEntity::getInstance($this->getName()); 72 $list_fields = $entityInstance->list_fields; 73 $list_fields_name = $entityInstance->list_fields_name; 74 $relatedListFields = array(); 75 foreach ($list_fields as $key => $fieldInfo) { 76 foreach ($fieldInfo as $columnName) { 77 if(array_key_exists($key, $list_fields_name)){ 78 if($columnName == 'lastname' || $columnName == 'activity' || $columnName == 'due_date' || $columnName == 'time_end') continue; 79 if ($columnName == 'status') $relatedListFields[$columnName] = 'taskstatus'; 80 else $relatedListFields[$columnName] = $list_fields_name[$key]; 81 } 82 } 83 } 84 return $relatedListFields; 85 } 86 87 /** 88 * Function to get list of field for related list 89 * @return <Array> empty array 90 */ 91 public function getConfigureRelatedListFields() { 92 return array(); 93 } 94 95 /** 96 * Function to get list of field for summary view 97 * @return <Array> empty array 98 */ 99 public function getSummaryViewFieldsList() { 100 return array(); 101 } 102 /** 103 * Function to get the Quick Links for the module 104 * @param <Array> $linkParams 105 * @return <Array> List of Vtiger_Link_Model instances 106 */ 107 public function getSideBarLinks($linkParams) { 108 $linkTypes = array('SIDEBARLINK', 'SIDEBARWIDGET'); 109 $links = Vtiger_Link_Model::getAllByType($this->getId(), $linkTypes, $linkParams); 110 111 $quickLinks = array( 112 array( 113 'linktype' => 'SIDEBARLINK', 114 'linklabel' => 'LBL_CALENDAR_VIEW', 115 'linkurl' => $this->getCalendarViewUrl(), 116 'linkicon' => '', 117 ), 118 array( 119 'linktype' => 'SIDEBARLINK', 120 'linklabel' => 'LBL_SHARED_CALENDAR', 121 'linkurl' => $this->getSharedCalendarViewUrl(), 122 'linkicon' => '', 123 ), 124 array( 125 'linktype' => 'SIDEBARLINK', 126 'linklabel' => 'LBL_RECORDS_LIST', 127 'linkurl' => $this->getListViewUrl(), 128 'linkicon' => '', 129 ), 130 ); 131 foreach($quickLinks as $quickLink) { 132 $links['SIDEBARLINK'][] = Vtiger_Link_Model::getInstanceFromValues($quickLink); 133 } 134 135 $quickWidgets = array(); 136 137 if ($linkParams['ACTION'] == 'Calendar') { 138 $quickWidgets[] = array( 139 'linktype' => 'SIDEBARWIDGET', 140 'linklabel' => 'LBL_ACTIVITY_TYPES', 141 'linkurl' => 'module='.$this->get('name').'&view=ViewTypes&mode=getViewTypes', 142 'linkicon' => '' 143 ); 144 } 145 146 if ($linkParams['ACTION'] == 'SharedCalendar') { 147 $quickWidgets[] = array( 148 'linktype' => 'SIDEBARWIDGET', 149 'linklabel' => 'LBL_ADDED_CALENDARS', 150 'linkurl' => 'module='.$this->get('name').'&view=ViewTypes&mode=getSharedUsersList', 151 'linkicon' => '' 152 ); 153 } 154 155 $quickWidgets[] = array( 156 'linktype' => 'SIDEBARWIDGET', 157 'linklabel' => 'LBL_RECENTLY_MODIFIED', 158 'linkurl' => 'module='.$this->get('name').'&view=IndexAjax&mode=showActiveRecords', 159 'linkicon' => '' 160 ); 161 162 foreach($quickWidgets as $quickWidget) { 163 $links['SIDEBARWIDGET'][] = Vtiger_Link_Model::getInstanceFromValues($quickWidget); 164 } 165 166 return $links; 167 } 168 169 /** 170 * Function returns the url that shows Calendar Import result 171 * @return <String> url 172 */ 173 public function getImportResultUrl() { 174 return 'index.php?module='.$this->getName().'&view=ImportResult'; 175 } 176 177 /** 178 * Function to get export query 179 * @return <String> query; 180 */ 181 public function getExportQuery($focus = '', $where = '') { 182 $currentUserModel = Users_Record_Model::getCurrentUserModel(); 183 $userId = $currentUserModel->getId(); 184 $query = "SELECT vtiger_activity.*, vtiger_crmentity.description, vtiger_activity_reminder.reminder_time FROM vtiger_activity 185 INNER JOIN vtiger_crmentity ON vtiger_activity.activityid = vtiger_crmentity.crmid 186 LEFT JOIN vtiger_activity_reminder ON vtiger_activity_reminder.activity_id = vtiger_activity.activityid AND vtiger_activity_reminder.recurringid = 0 187 WHERE vtiger_crmentity.deleted = 0 AND vtiger_crmentity.smownerid = $userId AND vtiger_activity.activitytype NOT IN ('Emails')"; 188 return $query; 189 } 190 191 /** 192 * Function to set event fields for export 193 */ 194 public function setEventFieldsForExport() { 195 $moduleFields = array_flip($this->getColumnFieldMapping()); 196 $userModel = Users_Privileges_Model::getCurrentUserPrivilegesModel(); 197 198 $keysToReplace = array('taskpriority'); 199 $keysValuesToReplace = array('taskpriority' => 'priority'); 200 201 foreach($moduleFields as $fieldName => $fieldValue) { 202 $fieldModel = Vtiger_Field_Model::getInstance($fieldName, $this); 203 if($fieldName != 'id' && $fieldModel->getPermissions()) { 204 if(!in_array($fieldName, $keysToReplace)) { 205 $eventFields[$fieldName] = 'yes'; 206 } else { 207 $eventFields[$keysValuesToReplace[$fieldName]] = 'yes'; 208 } 209 } 210 } 211 $this->set('eventFields', $eventFields); 212 } 213 214 /** 215 * Function to set todo fields for export 216 */ 217 public function setTodoFieldsForExport() { 218 $moduleFields = array_flip($this->getColumnFieldMapping()); 219 $userModel = Users_Privileges_Model::getCurrentUserPrivilegesModel(); 220 221 $keysToReplace = array('taskpriority', 'taskstatus'); 222 $keysValuesToReplace = array('taskpriority' => 'priority', 'taskstatus' => 'status'); 223 224 foreach($moduleFields as $fieldName => $fieldValue) { 225 $fieldModel = Vtiger_Field_Model::getInstance($fieldName, $this); 226 if($fieldName != 'id' && $fieldModel->getPermissions()) { 227 if(!in_array($fieldName, $keysToReplace)) { 228 $todoFields[$fieldName] = 'yes'; 229 } else { 230 $todoFields[$keysValuesToReplace[$fieldName]] = 'yes'; 231 } 232 } 233 } 234 $this->set('todoFields', $todoFields); 235 } 236 237 /** 238 * Function to get the url to view Details for the module 239 * @return <String> - url 240 */ 241 public function getDetailViewUrl($id) { 242 return 'index.php?module=Calendar&view='.$this->getDetailViewName().'&record='.$id; 243 } 244 245 /** 246 * To get the lists of sharedids 247 * @param $id -- user id 248 * @returns <Array> $sharedids 249 */ 250 public static function getCaledarSharedUsers($id){ 251 $db = PearDatabase::getInstance(); 252 253 $query = "SELECT vtiger_users.user_name, vtiger_sharedcalendar.* FROM vtiger_sharedcalendar 254 LEFT JOIN vtiger_users ON vtiger_sharedcalendar.sharedid=vtiger_users.id WHERE userid=?"; 255 $result = $db->pquery($query, array($id)); 256 $rows = $db->num_rows($result); 257 258 $sharedids = Array(); 259 $focus = new Users(); 260 for($i=0; $i<$rows; $i++){ 261 $sharedid = $db->query_result($result,$i,'sharedid'); 262 $userId = $db->query_result($result, $i, 'userid'); 263 $sharedids[$sharedid]=$userId; 264 } 265 return $sharedids; 266 } 267 268 /** 269 * To get the lists of sharedids 270 * @param $id -- user id 271 * @returns <Array> $sharedids 272 */ 273 public static function getSharedUsersOfCurrentUser($id){ 274 $db = PearDatabase::getInstance(); 275 276 $query = "SELECT vtiger_users.first_name,vtiger_users.last_name, vtiger_users.id as userid 277 FROM vtiger_sharedcalendar RIGHT JOIN vtiger_users ON vtiger_sharedcalendar.userid=vtiger_users.id and status= 'Active' 278 WHERE sharedid=? OR (vtiger_users.status='Active' AND vtiger_users.calendarsharedtype='public' AND vtiger_users.id <> ?);"; 279 $result = $db->pquery($query, array($id, $id)); 280 $rows = $db->num_rows($result); 281 282 $userIds = Array(); 283 for($i=0; $i<$rows; $i++){ 284 $id = $db->query_result($result,$i,'userid'); 285 $userName = $db->query_result($result,$i,'first_name').' '.$db->query_result($result,$i,'last_name'); 286 $userIds[$id] =$userName; 287 } 288 289 return $sharedids[$id] = $userIds; 290 } 291 292 /** 293 * To get the lists of sharedids and colors 294 * @param $id -- user id 295 * @returns <Array> $sharedUsers 296 */ 297 public static function getSharedUsersInfoOfCurrentUser($id){ 298 $db = PearDatabase::getInstance(); 299 300 $query = "SELECT shareduserid,color,visible FROM vtiger_shareduserinfo where userid = ?"; 301 $result = $db->pquery($query, array($id)); 302 $rows = $db->num_rows($result); 303 304 $sharedUsers = Array(); 305 for($i=0; $i<$rows; $i++){ 306 $sharedUserId = $db->query_result($result,$i,'shareduserid'); 307 $color = $db->query_result($result,$i,'color'); 308 $visible = $db->query_result($result,$i,'visible'); 309 $sharedUsers[$sharedUserId] = array('visible' => $visible , 'color' => $color); 310 } 311 312 return $sharedUsers; 313 } 314 315 /** 316 * To get the lists of sharedids and colors 317 * @param $id -- user id 318 * @returns <Array> $sharedUsers 319 */ 320 public static function getCalendarViewTypes($id){ 321 $db = PearDatabase::getInstance(); 322 323 $query = "SELECT * FROM vtiger_calendar_user_activitytypes 324 INNER JOIN vtiger_calendar_default_activitytypes on vtiger_calendar_default_activitytypes.id=vtiger_calendar_user_activitytypes.defaultid 325 WHERE vtiger_calendar_user_activitytypes.userid=?"; 326 $result = $db->pquery($query, array($id)); 327 $rows = $db->num_rows($result); 328 329 $calendarViewTypes = Array(); 330 for($i=0; $i<$rows; $i++){ 331 $activityTypes = $db->query_result_rowdata($result, $i); 332 $moduleInstance = Vtiger_Module::getInstance($activityTypes['module']); 333 $fieldInstance = Vtiger_Field::getInstance($activityTypes['fieldname'], $moduleInstance); 334 if($fieldInstance) { 335 $fieldLabel = $fieldInstance->label; 336 } else { 337 $fieldLabel = $activityTypes['fieldname']; 338 } 339 if($activityTypes['visible'] == '1') { 340 $calendarViewTypes['visible'][] = array('module'=>$activityTypes['module'], 'fieldname'=>$activityTypes['fieldname'], 'fieldlabel'=>$fieldLabel, 'visible' => $activityTypes['visible'] , 'color' => $activityTypes['color']); 341 } else { 342 $calendarViewTypes['invisible'][] = array('module'=>$activityTypes['module'], 'fieldname'=>$activityTypes['fieldname'], 'fieldlabel'=>$fieldLabel, 'visible' => $activityTypes['visible'] , 'color' => $activityTypes['color']); 343 } 344 } 345 return $calendarViewTypes; 346 } 347 348 /** 349 * Function returns the url for Shared Calendar view 350 * @return <String> 351 */ 352 public function getSharedCalendarViewUrl() { 353 return 'index.php?module='.$this->get('name').'&view=SharedCalendar'; 354 } 355 356 /** 357 * Function to delete shared users 358 * @param type $currentUserId 359 */ 360 public function deleteSharedUsers($currentUserId){ 361 $db = PearDatabase::getInstance(); 362 $delquery = "DELETE FROM vtiger_sharedcalendar WHERE userid=?"; 363 $db->pquery($delquery, array($currentUserId)); 364 } 365 366 /** 367 * Function to insert shared users 368 * @param type $currentUserId 369 * @param type $sharedIds 370 */ 371 public function insertSharedUsers($currentUserId, $sharedIds, $sharedType = FALSE){ 372 $db = PearDatabase::getInstance(); 373 foreach ($sharedIds as $sharedId) { 374 if($sharedId != $currentUserId) { 375 $sql = "INSERT INTO vtiger_sharedcalendar VALUES (?,?)"; 376 $db->pquery($sql, array($currentUserId, $sharedId)); 377 } 378 } 379 } 380 381 /** 382 * Function to get shared type 383 * @param type $currentUserId 384 * @param type $sharedIds 385 */ 386 public function getSharedType($currentUserId){ 387 $db = PearDatabase::getInstance(); 388 389 $query = "SELECT calendarsharedtype FROM vtiger_users WHERE id=?"; 390 $result = $db->pquery($query, array($currentUserId)); 391 if($db->num_rows($result) > 0){ 392 $sharedType = $db->query_result($result,0,'calendarsharedtype'); 393 } 394 return $sharedType; 395 } 396 397 /** 398 * Function to get Alphabet Search Field 399 */ 400 public function getAlphabetSearchField(){ 401 return 'subject'; 402 } 403 404 /** 405 * Function to get the list of recently visisted records 406 * @param <Number> $limit 407 * @return <Array> - List of Calendar_Record_Model 408 */ 409 public function getRecentRecords($limit=10) { 410 $db = PearDatabase::getInstance(); 411 412 $currentUserModel = Users_Record_Model::getCurrentUserModel(); 413 $deletedCondition = parent::getDeletedRecordCondition(); 414 $nonAdminQuery .= Users_Privileges_Model::getNonAdminAccessControlQuery($this->getName()); 415 416 $query = 'SELECT * FROM vtiger_crmentity '; 417 if($nonAdminQuery){ 418 $query .= " INNER JOIN vtiger_activity ON vtiger_crmentity.crmid = vtiger_activity.activityid ".$nonAdminQuery; 419 } 420 $query .= ' WHERE setype=? AND '.$deletedCondition.' AND modifiedby = ? ORDER BY modifiedtime DESC LIMIT ?'; 421 $params = array($this->getName(), $currentUserModel->id, $limit); 422 $result = $db->pquery($query, $params); 423 $noOfRows = $db->num_rows($result); 424 $recentRecords = array(); 425 for($i=0; $i<$noOfRows; ++$i) { 426 $row = $db->query_result_rowdata($result, $i); 427 $row['id'] = $row['crmid']; 428 $recentRecords[$row['id']] = $this->getRecordFromArray($row); 429 } 430 return $recentRecords; 431 } 432 433 /** 434 * Function returns Calendar Reminder record models 435 * @return <Array of Calendar_Record_Model> 436 */ 437 public static function getCalendarReminder() { 438 $db = PearDatabase::getInstance(); 439 $currentUserModel = Users_Record_Model::getCurrentUserModel(); 440 $activityReminder = $currentUserModel->getCurrentUserActivityReminderInSeconds(); 441 $recordModels = array(); 442 443 if($activityReminder != '' ) { 444 $currentTime = time(); 445 $date = date('Y-m-d', strtotime("+$activityReminder seconds", $currentTime)); 446 $time = date('H:i', strtotime("+$activityReminder seconds", $currentTime)); 447 $reminderActivitiesResult = "SELECT reminderid, recordid FROM vtiger_activity_reminder_popup 448 INNER JOIN vtiger_activity on vtiger_activity.activityid = vtiger_activity_reminder_popup.recordid 449 INNER JOIN vtiger_crmentity ON vtiger_activity_reminder_popup.recordid = vtiger_crmentity.crmid 450 WHERE vtiger_activity_reminder_popup.status = 0 451 AND vtiger_crmentity.smownerid = ? AND vtiger_crmentity.deleted = 0 452 AND ((DATE_FORMAT(vtiger_activity_reminder_popup.date_start,'%Y-%m-%d') <= ?) 453 AND (TIME_FORMAT(vtiger_activity_reminder_popup.time_start,'%H:%i') <= ?)) 454 AND vtiger_activity.eventstatus <> 'Held' LIMIT 20"; 455 $result = $db->pquery($reminderActivitiesResult, array($currentUserModel->getId(), $date, $time)); 456 $rows = $db->num_rows($result); 457 for($i=0; $i<$rows; $i++) { 458 $recordId = $db->query_result($result, $i, 'recordid'); 459 $recordModels[] = Vtiger_Record_Model::getInstanceById($recordId, 'Calendar'); 460 } 461 } 462 return $recordModels; 463 } 464 465 /** 466 * Function gives fields based on the type 467 * @param <String> $type - field type 468 * @return <Array of Vtiger_Field_Model> - list of field models 469 */ 470 public function getFieldsByType($type) { 471 $restrictedField = array('picklist'=>array('eventstatus', 'recurringtype', 'visibility', 'duration_minutes')); 472 473 if(!is_array($type)) { 474 $type = array($type); 475 } 476 $fields = $this->getFields(); 477 $fieldList = array(); 478 foreach($fields as $field) { 479 $fieldType = $field->getFieldDataType(); 480 if(in_array($fieldType,$type)) { 481 $fieldName = $field->getName(); 482 if($fieldType == 'picklist' && in_array($fieldName, $restrictedField[$fieldType])) { 483 } else { 484 $fieldList[$fieldName] = $field; 485 } 486 } 487 } 488 return $fieldList; 489 } 490 491 /** 492 * Function returns Settings Links 493 * @return Array 494 */ 495 public function getSettingLinks() { 496 $currentUserModel = Users_Record_Model::getCurrentUserModel(); 497 $settingLinks = array(); 498 499 if($currentUserModel->isAdminUser()) { 500 $settingLinks[] = array( 501 'linktype' => 'LISTVIEWSETTING', 502 'linklabel' => 'LBL_EDIT_FIELDS', 503 'linkurl' => 'index.php?parent=Settings&module=LayoutEditor&sourceModule='.$this->getName(), 504 'linkicon' => Vtiger_Theme::getImagePath('LayoutEditor.gif') 505 ); 506 507 $settingLinks[] = array( 508 'linktype' => 'LISTVIEWSETTING', 509 'linklabel' => 'LBL_EDIT_PICKLIST_VALUES', 510 'linkurl' => 'index.php?parent=Settings&module=Picklist&view=Index&source_module='.$this->getName(), 511 'linkicon' => '' 512 ); 513 } 514 return $settingLinks; 515 } 516 517 /** 518 * Function to get orderby sql from orderby field 519 */ 520 public function getOrderBySql($orderBy){ 521 if($orderBy == 'status'){ 522 return $orderBy; 523 } 524 return parent::getOrderBySql($orderBy); 525 } 526 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:08:37 2014 | Cross-referenced by PHPXref 0.7.1 |