示例#1
0
 /**
  * Takes an associative array and creates a campaign object.
  *
  * the function extract all the params it needs to initialize the create a
  * contact object. the params array could contain additional unused name/value
  * pairs
  *
  * @param array $params
  *   (reference ) an assoc array of name/value pairs.
  *
  * @return CRM_Campaign_DAO_Campaign
  */
 public static function create(&$params)
 {
     if (empty($params)) {
         return NULL;
     }
     if (!CRM_Utils_Array::value('id', $params)) {
         if (!CRM_Utils_Array::value('created_id', $params)) {
             $session = CRM_Core_Session::singleton();
             $params['created_id'] = $session->get('userID');
         }
         if (!CRM_Utils_Array::value('created_date', $params)) {
             $params['created_date'] = date('YmdHis');
         }
         if (!CRM_Utils_Array::value('name', $params)) {
             $params['name'] = CRM_Utils_String::titleToVar($params['title'], 64);
         }
         CRM_Utils_Hook::pre('create', 'Campaign', NULL, $params);
     } else {
         CRM_Utils_Hook::pre('edit', 'Campaign', $params['id'], $params);
     }
     $campaign = new CRM_Campaign_DAO_Campaign();
     $campaign->copyValues($params);
     $campaign->save();
     if (!empty($params['id'])) {
         CRM_Utils_Hook::post('edit', 'Campaign', $campaign->id, $campaign);
     } else {
         CRM_Utils_Hook::post('create', 'Campaign', $campaign->id, $campaign);
     }
     /* Create the campaign group record */
     $groupTableName = CRM_Contact_BAO_Group::getTableName();
     if (isset($params['groups']) && !empty($params['groups']['include']) && is_array($params['groups']['include'])) {
         foreach ($params['groups']['include'] as $entityId) {
             $dao = new CRM_Campaign_DAO_CampaignGroup();
             $dao->campaign_id = $campaign->id;
             $dao->entity_table = $groupTableName;
             $dao->entity_id = $entityId;
             $dao->group_type = 'Include';
             $dao->save();
             $dao->free();
         }
     }
     //store custom data
     if (!empty($params['custom']) && is_array($params['custom'])) {
         CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_campaign', $campaign->id);
     }
     return $campaign;
 }
 /**
  * adds $value['foo_display'] for each $value['foo'] enum from civicrm_campaign_group
  *
  * @param array $values (reference)  the array up for enhancing
  * @return void
  */
 static function addDisplayEnums(&$values)
 {
     $enumFields =& CRM_Campaign_DAO_CampaignGroup::getEnums();
     foreach ($enumFields as $enum) {
         if (isset($values[$enum])) {
             $values[$enum . '_display'] = CRM_Campaign_DAO_CampaignGroup::tsEnum($enum, $values[$enum]);
         }
     }
 }
示例#3
0
文件: Campaign.php 项目: kidaa30/yes
 /**
  * Form submission of new/edit campaign is processed.
  *
  *
  * @return void
  */
 public function postProcess()
 {
     // store the submitted values in an array
     $params = $this->controller->exportValues($this->_name);
     $session = CRM_Core_Session::singleton();
     $groups = array();
     if (isset($this->_campaignId)) {
         if ($this->_action & CRM_Core_Action::DELETE) {
             CRM_Campaign_BAO_Campaign::del($this->_campaignId);
             CRM_Core_Session::setStatus(ts('Campaign has been deleted.'), ts('Record Deleted'), 'success');
             $session->replaceUserContext(CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=campaign'));
             return;
         }
         $params['id'] = $this->_campaignId;
     } else {
         $params['created_id'] = $session->get('userID');
         $params['created_date'] = date('YmdHis');
     }
     // format params
     $params['start_date'] = CRM_Utils_Date::processDate($params['start_date'], $params['start_date_time']);
     $params['end_date'] = CRM_Utils_Date::processDate($params['end_date'], $params['end_date_time'], TRUE);
     $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
     $params['last_modified_id'] = $session->get('userID');
     $params['last_modified_date'] = date('YmdHis');
     if (is_array($params['includeGroups'])) {
         foreach ($params['includeGroups'] as $key => $id) {
             if ($id) {
                 $groups['include'][] = $id;
             }
         }
     }
     $params['groups'] = $groups;
     // delete previous includes/excludes, if campaign already existed
     $groupTableName = CRM_Contact_BAO_Group::getTableName();
     $dao = new CRM_Campaign_DAO_CampaignGroup();
     $dao->campaign_id = $this->_campaignId;
     $dao->entity_table = $groupTableName;
     $dao->find();
     while ($dao->fetch()) {
         $dao->delete();
     }
     //process custom data.
     $customFields = CRM_Core_BAO_CustomField::getFields('Campaign', FALSE, FALSE, CRM_Utils_Array::value('campaign_type_id', $params));
     $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_campaignId, 'Campaign');
     $result = CRM_Campaign_BAO_Campaign::create($params);
     if ($result) {
         CRM_Core_Session::setStatus(ts('Campaign %1 has been saved.', array(1 => $result->title)), ts('Saved'), 'success');
         $session->pushUserContext(CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=campaign'));
     }
     $buttonName = $this->controller->getButtonName();
     if ($buttonName == $this->getButtonName('upload', 'new')) {
         CRM_Core_Session::setStatus(ts(' You can add another Campaign.'), '', 'info');
         $session->replaceUserContext(CRM_Utils_System::url('civicrm/campaign/add', 'reset=1&action=add'));
     } else {
         $session->replaceUserContext(CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=campaign'));
     }
 }
示例#4
0
 /**
  * Returns the list of fields that can be exported
  *
  * @param bool $prefix
  *
  * @return array
  */
 static function &export($prefix = false)
 {
     if (!self::$_export) {
         self::$_export = array();
         $fields = self::fields();
         foreach ($fields as $name => $field) {
             if (CRM_Utils_Array::value('export', $field)) {
                 if ($prefix) {
                     self::$_export['campaign_group'] =& $fields[$name];
                 } else {
                     self::$_export[$name] =& $fields[$name];
                 }
             }
         }
     }
     return self::$_export;
 }
示例#5
0
 /**
  * Function to get Campaigns groups
  *
  * @param int $campaignId campaign id 
  *
  * @static
  */
 static function getCampaignGroups($campaignId)
 {
     $campaignGroups = array();
     if (!$campaignId) {
         return $campaignGroups;
     }
     require_once 'CRM/Campaign/DAO/CampaignGroup.php';
     $campGrp = new CRM_Campaign_DAO_CampaignGroup();
     $campGrp->campaign_id = $campaignId;
     $campGrp->group_type = 'Include';
     $campGrp->find();
     while ($campGrp->fetch()) {
         CRM_Core_DAO::storeValues($campGrp, $campaignGroups[$campGrp->id]);
     }
     return $campaignGroups;
 }
示例#6
0
 /**
  * Form submission of new/edit campaign is processed.
  *
  * @access public
  * @return None
  */
 public function postProcess()
 {
     // store the submitted values in an array
     $params = $this->controller->exportValues($this->_name);
     $session = CRM_Core_Session::singleton();
     $groups = array();
     if (isset($this->_campaignId)) {
         if ($this->_action & CRM_Core_Action::DELETE) {
             CRM_Campaign_BAO_Campaign::del($this->_campaignId);
             CRM_Core_Session::setStatus(ts(' Campaign has been deleted.'));
             $session->replaceUserContext(CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=campaign'));
             return;
         }
         $params['id'] = $this->_campaignId;
     } else {
         $params['created_id'] = $session->get('userID');
         $params['created_date'] = date('YmdHis');
     }
     // format params
     $params['start_date'] = CRM_Utils_Date::processDate($params['start_date'], $params['start_date_time']);
     $params['end_date'] = CRM_Utils_Date::processDate($params['end_date'], $params['end_date_time'], true);
     $params['is_active'] = CRM_Utils_Array::value('is_active', $params, false);
     $params['last_modified_id'] = $session->get('userID');
     $params['last_modified_date'] = date('YmdHis');
     if (is_array($params['includeGroups'])) {
         foreach ($params['includeGroups'] as $key => $id) {
             if ($id) {
                 $groups['include'][] = $id;
             }
         }
     }
     $params['groups'] = $groups;
     // delete previous includes/excludes, if campaign already existed
     $groupTableName = CRM_Contact_BAO_Group::getTableName();
     $dao = new CRM_Campaign_DAO_CampaignGroup();
     $dao->campaign_id = $this->_campaignId;
     $dao->entity_table = $groupTableName;
     $dao->find();
     while ($dao->fetch()) {
         $dao->delete();
     }
     require_once 'CRM/Campaign/BAO/Campaign.php';
     $result = CRM_Campaign_BAO_Campaign::create($params);
     if ($result) {
         CRM_Core_Session::setStatus(ts('Campaign %1 has been saved.', array(1 => $result->title)));
         $session->pushUserContext(CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=campaign'));
     }
     if ($this->_context == 'dialog') {
         $returnArray = array('returnSuccess' => true);
         echo json_encode($returnArray);
         CRM_Utils_System::civiExit();
     }
     $buttonName = $this->controller->getButtonName();
     if ($buttonName == $this->getButtonName('next', 'new')) {
         CRM_Core_Session::setStatus(ts(' You can add another Campaign.'));
         $session->replaceUserContext(CRM_Utils_System::url('civicrm/campaign/add', 'reset=1&action=add'));
     } else {
         $session->replaceUserContext(CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=campaign'));
     }
 }