CampaignHelper.class.php
2 months ago
ContactForm7Helper.class.php
2 months ago
TopAffiliatesHelper.class.php
2 months ago
UpdateDB.class.php
2 months ago
CampaignHelper.class.php
98 lines
| 1 | <?php |
| 2 | if (!defined('ABSPATH')) exit; |
| 3 | |
| 4 | class postaffiliatepro_Util_CampaignHelper extends postaffiliatepro_Base { |
| 5 | |
| 6 | const CAMPAIGN_NAME = 'name'; |
| 7 | //const CAMPAIGN_STATUS = 'rstatus'; |
| 8 | const CAMPAIGN_TYPE = 'rtype'; |
| 9 | const CAMPAIGN_ID = 'id'; |
| 10 | |
| 11 | const CAMPAIGN_TYPE_PRIVATE = 'I'; |
| 12 | const CAMPAIGN_TYPE_PUBLIC = 'P'; |
| 13 | const CAMPAIGN_TYPE_PUBLIC_MANUAL = 'M'; |
| 14 | |
| 15 | /** |
| 16 | * |
| 17 | * @var Gpf_Data_RecordSet |
| 18 | */ |
| 19 | private static $campaignList = null; |
| 20 | |
| 21 | public function getTypeAsText($type) { |
| 22 | switch ($type) { |
| 23 | case self::CAMPAIGN_TYPE_PUBLIC: |
| 24 | return __('Public', 'postaffiliatepro'); |
| 25 | case self::CAMPAIGN_TYPE_PUBLIC_MANUAL: |
| 26 | return __('Public with manual approval', 'postaffiliatepro'); |
| 27 | case self::CAMPAIGN_TYPE_PRIVATE: |
| 28 | return __('Private', 'postaffiliatepro'); |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | public function getCampaignsCount($type = null) { |
| 33 | $campaignList = $this->getCampaignsList(); |
| 34 | if (empty($campaignList)) { |
| 35 | return 0; |
| 36 | } |
| 37 | if ($type === null) { |
| 38 | return $campaignList->getSize(); |
| 39 | } |
| 40 | $count = 0; |
| 41 | foreach ($campaignList as $campaign) { |
| 42 | if ($campaign->get(self::CAMPAIGN_TYPE) === $type) { |
| 43 | $count ++; |
| 44 | } |
| 45 | } |
| 46 | return $count; |
| 47 | } |
| 48 | |
| 49 | public function getCampaignType($campaignId) { |
| 50 | $campaignList = $this->getCampaignsList(); |
| 51 | foreach ($campaignList as $campaign) { |
| 52 | if ($campaign->get(self::CAMPAIGN_ID) === $campaignId) { |
| 53 | return $campaign->get(self::CAMPAIGN_TYPE); |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | public function getCampaignName($campaignId) { |
| 59 | $campaignList = $this->getCampaignsList(); |
| 60 | foreach ($campaignList as $campaign) { |
| 61 | if ($campaign->get(self::CAMPAIGN_ID) === $campaignId) { |
| 62 | return htmlspecialchars($campaign->get(self::CAMPAIGN_NAME)); |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * @return Gpf_Data_RecordSet; |
| 69 | */ |
| 70 | public function getCampaignsList() { |
| 71 | if (self::$campaignList !== null) { |
| 72 | return self::$campaignList; |
| 73 | } |
| 74 | $session = $this->getApiSession(); |
| 75 | if ($session === null || $session === '0') { |
| 76 | return array(); |
| 77 | } |
| 78 | $request = new Gpf_Rpc_GridRequest('Pap_Merchants_Campaign_CampaignsGrid', 'getRows', $session); |
| 79 | $request->setLimit(0, 9999); |
| 80 | $request->addParam('columns', new Gpf_Rpc_Array(array(array('id'), array('id')))); |
| 81 | |
| 82 | $filters = new Gpf_Rpc_Array(); |
| 83 | $filters->add(new Gpf_Data_Filter('rstatus', 'NE', 'D')); |
| 84 | $filters->add(new Gpf_Data_Filter('rstatus', 'NE', 'S')); |
| 85 | $filters->add(new Gpf_Data_Filter('rstatus', 'NE', 'W')); |
| 86 | |
| 87 | $request->addParam('filters', $filters); |
| 88 | try { |
| 89 | $request->sendNow(); |
| 90 | } catch(Exception $e) { |
| 91 | $this->_log('Can not obtain campaign list: '. $e->getMessage()); |
| 92 | return array(); |
| 93 | } |
| 94 | $grid = $request->getGrid(); |
| 95 | self::$campaignList = $grid->getRecordset(); |
| 96 | return self::$campaignList; |
| 97 | } |
| 98 | } |