当前位置: 首页>>代码示例>>PHP>>正文


PHP MCAPI::listStaticSegments方法代码示例

本文整理汇总了PHP中MCAPI::listStaticSegments方法的典型用法代码示例。如果您正苦于以下问题:PHP MCAPI::listStaticSegments方法的具体用法?PHP MCAPI::listStaticSegments怎么用?PHP MCAPI::listStaticSegments使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MCAPI的用法示例。


在下文中一共展示了MCAPI::listStaticSegments方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: onAfterWrite

 public function onAfterWrite()
 {
     parent::onAfterWrite();
     if ($this->isChanged("ID") && $this->getFirstWrite() && $this->getSyncMailChimp()) {
         $apikey = SiteConfig::current_site_config()->getMCAPIKey();
         $api = new MCAPI($apikey);
         $list = $this->getComponent("MCList");
         if (!empty($list)) {
             // Limitited to 50 Bytes (Hopefully 50 Chars)
             $SegmentTitle = substr($this->Title, 0, 45);
             $api->listStaticSegmentAdd($list->ListID, $SegmentTitle);
             if ($api->errorCode) {
                 SS_Log::log("API Call Failed: listStaticSegmentAdd(); | Error Code = " . $api->errorCode . " | Error Message = " . $api->errorMessage, SS_Log::ERR);
             } else {
                 SS_Log::log("API Call Success: listStaticSegmentAdd();", SS_Log::NOTICE);
                 // Make Second Call To Return MailChimp Segment ID
                 $segments = $api->listStaticSegments($list->ListID);
                 foreach ($segments as $segment) {
                     // Make Sure We Capture the WHOLE Event ID!
                     $id_chars = strlen((string) $this->EventID);
                     $id = substr($segment['name'], 6, $id_chars);
                     if ($id == $this->EventID) {
                         SS_Log::log("This Event ID = " . $this->EventID . ", Static Segment Named " . $segment['name'] . " Relates to Event ID " . $id, SS_Log::NOTICE);
                         SS_Log::log("We Have a Match", SS_Log::NOTICE);
                         $this->setField("MCListSegmentID", $segment['id']);
                         $this->write();
                         break;
                     }
                 }
             }
         }
     }
     // END: if($this->isChanged("ID")) {
     $this->setFirstWrite(false);
 }
开发者ID:quadra-digital,项目名称:silverstripe-mailchimp-module,代码行数:35,代码来源:MCListSegment.php

示例2: UpdateSegments

 public function UpdateSegments($list = null)
 {
     if (!is_object($list)) {
         SS_Log::log("UpdateSegments() Requireds a MCList Object Parameter!", SS_Log::ERR);
         return false;
     }
     $api = new MCAPI($this->apikey);
     $retval = $api->listStaticSegments($list->ListID);
     if ($api->errorCode) {
         SS_Log::log("API Call Failed: listStaticSegments('" . $list->ListID . "); Error Code = " . $api->errorCode . " | Error Message = " . $api->errorMessage, SS_Log::ERR);
         return false;
     } else {
         SS_Log::log("API Call Success: listStaticSegments('" . $list->ListID . ");", SS_Log::NOTICE);
         if (!empty($retval)) {
             $LiveSegmentIDs = array();
             foreach ($retval as $segment) {
                 $dl = new DataList("MCListSegment");
                 $seg = $dl->where("\"MCListSegmentID\" = '" . $segment['id'] . "'")->first();
                 // Create New Segment If It Doesnt Yet Exist On The Site (i.e. It Was Created On MailChimp)
                 if (empty($seg)) {
                     $seg = new MCListSegment();
                     $seg->setField("Title", $segment['name']);
                     $seg->setField("MCListSegmentID", $segment['id']);
                     $seg->setField("MCListID", $list->ID);
                     $seg->setSyncMailChimp(false);
                     $seg->write();
                 }
                 $LiveSegmentIDs[] = $segment['id'];
             }
         }
         // Get List of Segments Which Exist On Site But Not On MailChimp
         $where = "\"MCListID\" = '" . $list->ID . "'";
         $where .= !empty($LiveSegmentIDs) ? "AND \"MCListSegmentID\" NOT IN (" . $this->arrayToCSV($LiveSegmentIDs) . ")" : "";
         // Don't Delete Segments Which Still Exist
         $dl = new DataList("MCListSegment");
         $deadSegs = $dl->where($where);
         // Delete Dead Segments (Deleted On MailChimp Directly)
         if (!empty($deadSegs)) {
             foreach ($deadSegs as $deadSeg) {
                 $deadSeg->setSyncMailChimp(false);
                 $deadSeg->delete();
             }
         }
     }
     return true;
 }
开发者ID:quadra-digital,项目名称:silverstripe-mailchimp-module,代码行数:46,代码来源:MCSync.php


注:本文中的MCAPI::listStaticSegments方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。