Пример #1
0
 public static function getStatus($lead_id = null)
 {
     if (is_null($lead_id)) {
         $lead_id = Conversation::get('lead_id');
     }
     return Lead::where('lead_id', $lead_id)->first()->pluck('auto_stop');
 }
Пример #2
0
 /**
  * Get subscribers of channels
  *
  * Parameters:
  *
  * 1 -> returns any subscribers in channel 1
  * 'foo' -> returns any subscribers in channel foo
  * [1, 'foo'] -> returns any subscribers in both channel 1 and foo
  * '1, foo' -> returns any subscriber in either channel 1 or foo
  */
 private function getSubscribers($channels = 1)
 {
     $all = is_array($channels);
     if (is_string($channels) || is_numeric($channels)) {
         $channels = explode(',', $channels);
     }
     $channels = array_map('trim', $channels);
     $regexp = implode('|', $channels);
     $leads = Lead::where('subscribe', 'REGEXP', $regexp)->get();
     $subscribers = [];
     foreach ($leads as $lead) {
         $lead_channels = array_map('trim', explode(',', $lead->subscribe));
         // Array should in another array
         if ($all && !array_diff($channels, $lead_channels)) {
             $subscribers[] = $lead->user_id;
             continue;
         }
         // One element of array in another array
         if (!$all && array_intersect($channels, $lead_channels)) {
             $subscribers[] = $lead->user_id;
         }
     }
     return array_unique($subscribers);
 }
Пример #3
0
 /**
  * Search in collection
  *
  * @param $terms
  * @param string $relation
  * @return mixed
  */
 private function search($terms, $relation = 'and')
 {
     return Lead::where($terms)->get();
 }