public function run()
 {
     $state = $this->getState();
     if ($state->getContext($this->name . ':message') === FALSE && !empty($this->optInPathId)) {
         // Opt user into a Mobile Commons path.
         $mobile = $state->getContext('sms_number');
         dosomething_sms_mobilecommons_opt_in($mobile, $this->optInPathId);
         // Bypass conductor_sms error thrown when no text response is given.
         $state->setContext('ignore_no_response_error', TRUE);
         // Wait for user response before going to next activity in workflow.
         $state->markSuspended();
         return;
     }
     parent::run();
 }
 public function run()
 {
     $state = $this->getState();
     $mobile = $state->getContext('sms_number');
     $mdataID = intval($_REQUEST['mdata_id']);
     // Find the routing info for replies through this mdata id
     if (array_key_exists($mdataID, $this->routes)) {
         $route = $this->routes[$mdataID];
         // Opt the user out of the transactional campaign
         dosomething_sms_mobilecommons_opt_out($mobile, $route['out_campaign_id']);
         // Opt the user into a path in the actual campaign
         dosomething_sms_mobilecommons_opt_in($mobile, $route['opt_in_path_id']);
     }
     $state->setContext('ignore_no_response_error', TRUE);
     $state->markCompleted();
 }
コード例 #3
0
 public function run()
 {
     $state = $this->getState();
     // Process user's response, expecting any mms to be in $_REQUEST['mms_image_url'].
     // If none is set, jump to the end of the workflow.
     $mms_image_url = $_REQUEST['mms_image_url'];
     if (!empty($mms_image_url)) {
         $state->setContext($this->name . ':mms', $mms_image_url);
     } elseif (!empty($this->noMmsResponse)) {
         // Send user a response for no MMS being sent.
         $mobile = $state->getContext('sms_number');
         dosomething_sms_mobilecommons_opt_in($mobile, $this->noMmsResponse);
         // Bypass conductor_sms error thrown when no text response is given.
         $state->setContext('ignore_no_response_error', TRUE);
         // Send user to the end of the workflow.
         self::useOutput('end');
     }
     $state->markCompleted();
 }
 /**
  * Called when this activity gets activated and run by the containing
  * ConductorWorkflow's controller.
  */
 public function run()
 {
     $state = $this->getState();
     $mobile = $state->getContext('sms_number');
     // Get the mData id the request came from.
     $mdataId = intval($_REQUEST['mdata_id']);
     // Find the set with the matching mdata_id.
     if (array_key_exists($mdataId, $this->paths)) {
         $path = $this->paths[$mdataId];
         // Get last opt-in path user was sent to. Function returns an array.
         $lastOptInArray = dosomething_sms_game_get_paths($mobile, $path['gameId']);
         // Select next opt-in path to send the user to.
         $lastOptIn = $lastOptInArray[0];
         $lastOptInIndex = array_search($lastOptIn, $path['optInPaths']);
         $nextOptInIndex = $lastOptInIndex + 1;
         if ($nextOptInIndex >= count($path['optInPaths']) || $lastOptInIndex === FALSE) {
             $nextOptInIndex = 0;
         }
         // Send user to selected opt-in path
         if ($nextOptInIndex >= 0 && $nextOptInIndex < count($path['optInPaths'])) {
             dosomething_sms_mobilecommons_opt_in($mobile, $path['optInPaths'][$nextOptInIndex]);
             // Save path to database
             try {
                 // If no existing record, create one
                 if (empty($lastOptIn)) {
                     dosomething_sms_game_create_record($mobile, $path['gameId']);
                 }
                 // Update existing record, adding the newly selected path
                 $currentOptIn = array($path['optInPaths'][$nextOptInIndex]);
                 dosomething_sms_game_set_paths($mobile, $path['gameId'], $currentOptIn);
             } catch (Exception $e) {
                 watchdog('dosomething_sms', 'ConductorActivityMobileCommonsGamePaths exception - ' . $e->getMessage());
             }
         }
     }
     $state->setContext('ignore_no_response_error', TRUE);
     $state->markCompleted();
 }
 /**
  * Called when this activity gets activated and run by the containing
  * ConductorWorkflow's controller.
  */
 public function run()
 {
     $state = $this->getState();
     $mobile = $state->getContext('sms_number');
     // Mobile Commons sends the international code in its payload. Remove it.
     $mobile = substr($mobile, -10);
     // Get user by mobile number if it exists. Otherwise create it.
     $user = dosomething_user_get_user_by_mobile($mobile);
     if (!$user) {
         $user = dosomething_user_create_user_by_mobile($mobile);
     }
     // Initialize reportback values, defaulting to create a new reportback.
     $values = array('rbid' => 0);
     // Check for a previously submitted reportback to update instead.
     if ($rbid = dosomething_reportback_exists($this->nid, $user->uid)) {
         $values['rbid'] = $rbid;
     }
     // Get the MMS URL from the provided context.
     $pictureUrl = $state->getContext($this->mmsContext);
     // Get the location for where file should be saved to.
     $fileDest = dosomething_reportback_get_file_dest(basename($pictureUrl), $this->nid, $user->uid);
     // Download and save file to that location.
     $pictureContents = file_get_contents($pictureUrl);
     $file = file_save_data($pictureContents, $fileDest);
     // Save UID and permanent status.
     $file->uid = $user->uid;
     $file->status = FILE_STATUS_PERMANENT;
     file_save($file);
     // Get the fid to submit with the report back.
     $values['fid'] = $file->fid;
     // Get answers from context and set them to their appropriate properties.
     foreach ($this->propertyToContextMap as $property => $context) {
         $values[$property] = $state->getContext($context);
     }
     // Set nid and uid.
     $values['nid'] = $this->nid;
     $values['uid'] = $user->uid;
     // Create/update a report back submission.
     $rbid = dosomething_reportback_save($values);
     // Update user's profile if this is the first completed campaign.
     $updateArgs = array();
     if (empty($_REQUEST['profile_first_completed_campaign_id']) && !empty($this->mobileCommonsCompletedCampaignId)) {
         $updateArgs['person[first_completed_campaign_id]'] = $this->mobileCommonsCompletedCampaignId;
     }
     // Opt the user out of the main campaign.
     if (!empty($this->optOutCampaignId)) {
         dosomething_sms_mobilecommons_opt_out($mobile, $this->optOutCampaignId);
     }
     // Opt user into a path to send the confirmation message.
     dosomething_sms_mobilecommons_opt_in($mobile, $this->optInPathId, $updateArgs);
     $state->setContext('ignore_no_response_error', TRUE);
     $state->markCompleted();
 }