[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/modules/Campaigns/models/ -> Relation.php (source)

   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  class Campaigns_Relation_Model extends Vtiger_Relation_Model {
  12  
  13      /**
  14       * Function to get Email enabled modules list for detail view of record
  15       * @return <array> List of modules
  16       */
  17  	public function getEmailEnabledModulesInfoForDetailView() {
  18          return array(
  19                  'Leads' => array('fieldName' => 'leadid', 'tableName' => 'vtiger_campaignleadrel'),
  20                  'Accounts' => array('fieldName' => 'accountid', 'tableName' => 'vtiger_campaignaccountrel'),
  21                  'Contacts' => array('fieldName' => 'contactid', 'tableName' => 'vtiger_campaigncontrel')
  22          );
  23      }
  24  
  25      /**
  26       * Function to get Campaigns Relation status values
  27       * @return <array> List of status values
  28       */
  29  	public function getCampaignRelationStatusValues() {
  30          $statusValues = array();
  31          $db = PearDatabase::getInstance();
  32          $result = $db->pquery("SELECT campaignrelstatusid, campaignrelstatus FROM vtiger_campaignrelstatus", array());
  33          $numOfRows = $db->num_rows($result);
  34  
  35          for ($i=0; $i<$numOfRows; $i++) {
  36              $statusValues[$db->query_result($result, $i, 'campaignrelstatusid')] = $db->query_result($result, $i, 'campaignrelstatus');
  37          }
  38          return $statusValues;
  39      }
  40  
  41      /**
  42       * Function to update the status of relation
  43       * @param <Number> Campaign record id
  44       * @param <array> $statusDetails
  45       */
  46  	public function updateStatus($sourceRecordId, $statusDetails = array()) {
  47          if ($sourceRecordId && $statusDetails) {
  48              $relatedModuleName = $this->getRelationModuleModel()->getName();
  49              $emailEnabledModulesInfo = $this->getEmailEnabledModulesInfoForDetailView();
  50  
  51              if (array_key_exists($relatedModuleName, $emailEnabledModulesInfo)) {
  52                  $fieldName = $emailEnabledModulesInfo[$relatedModuleName]['fieldName'];
  53                  $tableName = $emailEnabledModulesInfo[$relatedModuleName]['tableName'];
  54                  $db = PearDatabase::getInstance();
  55  
  56                  $updateQuery = "UPDATE $tableName SET campaignrelstatusid = CASE $fieldName ";
  57                  foreach ($statusDetails as $relatedRecordId => $status) {
  58                      $updateQuery .= " WHEN $relatedRecordId THEN $status ";
  59                  }
  60                  $updateQuery .= "ELSE campaignrelstatusid END WHERE campaignid = ?";
  61                  $db->pquery($updateQuery, array($sourceRecordId));
  62              }
  63          }
  64      }
  65  }


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1