Example #1
0
 public static function getGroupContacts($group_ids)
 {
     foreach ($group_ids as $group_id) {
         $groucontact = GroupContact::find("group_id={$group_id}");
         $groucontactlist = array();
         foreach ($groucontact as $group_data) {
             $groucontactlist[] = $group_data->contacts->number;
         }
     }
     return $groucontactlist;
 }
Example #2
0
 public static function getGroupNumber($group_ids)
 {
     $number = array();
     foreach ($group_ids as $group_id) {
         $result = Groups::findFirst("id= '{$group_id}'");
         if ($result->id) {
             $groucontact = GroupContact::find("group_id='{$group_id}'");
             foreach ($groucontact as $group_data) {
                 $number[] = $group_data->contacts->number;
             }
         }
     }
     return implode(',', $number);
 }
 public function moveToGroupContactAction()
 {
     if ($this->request->isPost() == true) {
         $group_id = $this->request->getPost('group_id');
         $contact_ids = $this->request->getPost('contact_ids');
         $contacts = explode(',', $contact_ids);
         $i = 0;
         foreach ($contacts as $contact_id) {
             try {
                 $groucontact = new GroupContact();
                 $groucontact->assign(array('group_id' => $group_id, 'contact_id' => $contact_id, 'created_at' => date("Y-m-d H:i:s"), 'updated_at' => date("Y-m-d H:i:s")));
                 $groucontact->save();
                 $i++;
             } catch (Exception $ex) {
                 continue;
             }
         }
         if ($i == 0) {
             $this->response->setContent(json_encode(array('success' => 'error', 'code' => '1', 'msg' => 'Already Exist')));
         } else {
             $this->response->setContent(json_encode(array('success' => 'success', 'code' => '2', 'msg' => $i . ' Contacts Move Successfully')));
         }
         // $this->flash->error($groucontact->getMessages());
         $this->response->send();
     }
 }
 public function deleteContactAction()
 {
     if ($this->request->isPost() == true) {
         $this->response->setContentType('application/json');
         $user_id = $this->request->getPost('user_id');
         $contact_ids = $this->request->getPost('contact_ids');
         $contacts = Contacts::find('id IN (' . $contact_ids . ')');
         foreach ($contacts as $contact) {
             $group_contacts = GroupContact::find('contact_id =' . $contact->id);
             if ($group_contacts != false) {
                 foreach ($group_contacts as $group_contact) {
                     $group_contact->delete();
                 }
             }
             $contact->deleted = 1;
             $contact->save();
         }
         $data = array('status' => 'success', 'msg' => 'contact deleted', 'code' => 2);
         $this->response->setContent(json_encode($data));
         $this->response->send();
     }
 }
 public function sheduleSMSAction()
 {
     if ($this->request->isPost() == true) {
         $this->response->setContentType('application/json');
         $type = $this->request->getPost('type');
         $user_id = $this->request->getPost('user_id');
         $message = $this->request->getPost('message');
         $datetime = $this->request->getPost('datetime');
         $timezone = 'UTC';
         $scheduled_date_user_tz = new DateTime($datetime, new DateTimeZone($timezone));
         $scheduled_date_user_tz->setTimezone(new DateTimeZone('UTC'));
         $scheduled_date_UTC = $scheduled_date_user_tz->format('Y-m-d H:i:s');
         $schedule_date = date('Y-m-d H:i:s', strtotime($scheduled_date_UTC));
         // $scheduled_date_user_tz = new DateTime($datetime);
         // $scheduled_date_UTC = $scheduled_date_user_tz->format('Y-m-d H:i:s');
         // $schedule_date = date('Y-m-d H:i:s', strtotime($scheduled_date_UTC));
         if ($type == "CONTACTID") {
             $contact_ids = $this->request->getPost('contact_ids');
             $contacts_ids = explode(',', $contact_ids);
             $contacts = Contacts::find('id IN (' . $contact_ids . ')');
             $numbers = array();
             $contact_id = array();
             foreach ($contacts as $contact) {
                 $numbers[] = $contact->number;
                 $contact_id[] = $contact->id;
             }
         }
         if ($type == "GROUPID") {
             $group_id = $this->request->getPost('group_id');
             $groucontact = GroupContact::find("group_id={$group_id}");
             $groucontactlist = array();
             $contact_id = array();
             foreach ($groucontact as $group_data) {
                 $numbers[] = $group_data->contacts->number;
             }
             $contact_id = explode(',', $group_id);
         }
         $data = $this->sheduleSMSProcessData(array('message' => $message, 'user_id' => $user_id, 'ids' => $contact_id, 'type' => $type, 'contacts' => $numbers, 'schedule_date' => $schedule_date));
         $this->response->setContent(json_encode($data));
         $this->response->send();
     }
 }