示例#1
0
 public function storeCustomRecord($parameters)
 {
     $record = Record::find($this->request->input('ref'));
     $record->data_403 = json_decode($record->data_403);
     $form = $record->getForm;
     $state = $record->getState;
     $names = [];
     $usersEmails = [];
     $messages = [];
     $comment = Comment::create(['record_id_404' => $this->request->input('ref'), 'user_id_404' => auth('pulsar')->user()->id_010, 'date_404' => date('U'), 'subject_404' => $this->request->input('subject'), 'comment_404' => $this->request->input('comment')]);
     // check new recipients
     Miscellaneous::checkRecipients($record, $form);
     // get recipient emails to compare with new user email
     $recipients = Recipient::where('record_id_406', $this->request->input('ref'))->where('comments_406', true)->get();
     // set recipients
     foreach ($recipients as $recipient) {
         if ($recipient->email_406 != auth('pulsar')->user()->email_010) {
             $names[] = $recipient->name_406;
             $usersEmails[] = $recipient->email_406;
         }
     }
     // get users with the emails recipients
     $users = User::whereIn('email_010', $usersEmails)->get();
     $matchAuthor = false;
     foreach ($recipients as $recipient) {
         if ($recipient->email_406 == auth('pulsar')->user()->email_010) {
             $matchAuthor = true;
         } else {
             // send to all recipients less Author recipient
             // get user and permissions
             $matchUser = null;
             foreach ($users as $user) {
                 if ($user->email_010 == $recipient->email_406) {
                     $matchUser = $user;
                     break;
                 }
             }
             if ($matchUser != null) {
                 $userAcl = AclLibrary::getProfileAcl($matchUser->profile_id_010);
             }
             $messages[] = ['type_id_405' => 'comment', 'record_id_405' => $record->id_403, 'date_405' => date('U'), 'recipient_id_405' => $recipient->id_406, 'forward_405' => $recipient->forward_406, 'subject_405' => 'forms::pulsar.subject_comment', 'name_405' => $recipient->name_406, 'email_405' => $recipient->email_406, 'form_id_405' => $form->id_401, 'user_id_405' => $matchUser == null ? null : $matchUser->id_010, 'template_405' => 'forms::emails.comment', 'text_template_405' => 'forms::emails.text_comment', 'data_message_405' => json_encode(['name_form_405' => $form->name_401, 'author_comment_405' => auth('pulsar')->user()->name_010 . ' ' . auth('pulsar')->user()->surname_010, 'date_comment_405' => date(config('pulsar.datePattern')), 'subject_comment_405' => $comment->subject_404, 'comment_405' => $comment->comment_404, 'name_state_405' => $state->name_400, 'color_state_405' => $state->color_400, 'names_405' => implode(", ", $names), 'permission_state_405' => $matchUser == null ? false : $userAcl->allows('forms-record', 'edit', $matchUser->profile_id_010), 'permission_comment_405' => $matchUser == null ? false : $userAcl->allows('forms-comment', 'create', $matchUser->profile_id_010), 'permission_forward_405' => $matchUser == null ? false : $userAcl->allows('forms-form', 'edit', $matchUser->profile_id_010), 'permission_record_405' => $matchUser == null ? false : $userAcl->allows('forms-record', 'show', $matchUser->profile_id_010)]), 'data_405' => json_encode($record->toArray())];
         }
     }
     if (!$matchAuthor) {
         // Include Author to recipients but not forward
         Recipient::create(['record_id_406' => $record->id_403, 'forward_406' => false, 'name_406' => auth('pulsar')->user()->name_010 . ' ' . auth('pulsar')->user()->surname_010, 'email_406' => auth('pulsar')->user()->email_010, 'comments_406' => true, 'states_406' => true]);
     }
     if (count($messages) > 0) {
         Message::insert($messages);
     }
     $parameters['redirectParentJs'] = true;
     return $parameters;
 }
示例#2
0
 /**
  *  Funtion to check news recipients
  *
  * @access  public
  * @param   \Syscover\Forms\Models\Record    $record
  * @param   \Syscover\Forms\Models\Form      $form
  * @return  void
  */
 public static function checkRecipients($record, $form)
 {
     $forwards = $form->getForwards;
     $newRecipients = [];
     $oldRecipients = [];
     $recipients = Recipient::where('record_id_406', $record->id_403)->where('forward_406', true)->get();
     // found new recipients
     foreach ($forwards as $forward) {
         $matchRecipient = false;
         foreach ($recipients as $recipient) {
             if ($forward->email_402 == $recipient->email_406) {
                 $matchRecipient = true;
                 break;
             }
         }
         if (!$matchRecipient) {
             $newRecipients[] = ['record_id_406' => $record->id_403, 'forward_406' => true, 'name_406' => $forward->name_402, 'email_406' => $forward->email_402, 'comments_406' => $forward->comments_402, 'states_406' => $forward->states_402];
         }
     }
     // found recipients to delete
     foreach ($recipients as $recipient) {
         $matchForward = false;
         foreach ($forwards as $forward) {
             if ($forward->email_402 == $recipient->email_406) {
                 $matchForward = true;
                 break;
             }
         }
         if (!$matchForward) {
             $oldRecipients[] = $recipient->id_406;
         }
     }
     if (count($newRecipients) > 0) {
         Recipient::insert($newRecipients);
     }
     if (count($oldRecipients) > 0) {
         Recipient::whereIn('id_406', $oldRecipients)->delete();
     }
 }
示例#3
0
 /**
  *  Change state record
  *
  * @access	public
  * @return  json
  */
 public function jsonSetStateRecordForm()
 {
     $record = Record::find($this->request->input('record'));
     $record->data_403 = json_decode($record->data_403);
     $form = $record->getForm;
     $oldState = $record->getState;
     $state = State::find($this->request->input('value'));
     $names = [];
     $usersEmails = [];
     Record::where('id_403', $this->request->input('record'))->update(['state_id_403' => $this->request->input('value')]);
     // check new recipients
     Miscellaneous::checkRecipients($record, $form);
     // get recipients emails to compare with new user email
     $recipients = Recipient::where('record_id_406', $this->request->input('record'))->where('states_406', true)->get();
     // set recipients
     foreach ($recipients as $recipient) {
         $names[] = $recipient->name_406;
         $usersEmails[] = $recipient->email_406;
     }
     // get users with the emails recipients
     $users = User::whereIn('email_010', $usersEmails)->get();
     foreach ($recipients as $recipient) {
         // get user and permissions
         $matchUser = null;
         foreach ($users as $user) {
             if ($user->email_010 == $recipient->email_406) {
                 $matchUser = $user;
                 break;
             }
         }
         if ($matchUser != null) {
             $userAcl = AclLibrary::getProfileAcl($matchUser->profile_id_010);
         }
         $messages[] = ['type_id_405' => 'state', 'record_id_405' => $record->id_403, 'date_405' => date('U'), 'recipient_id_405' => $recipient->id_406, 'forward_405' => $recipient->forward_406, 'subject_405' => 'forms::pulsar.subject_change_state', 'name_405' => $recipient->name_406, 'email_405' => $recipient->email_406, 'form_id_405' => $form->id_401, 'user_id_405' => $user == null ? null : $user->id_010, 'template_405' => 'forms::emails.state', 'text_template_405' => 'forms::emails.text_state', 'data_message_405' => json_encode(['name_form_405' => $form->name_401, 'name_old_state_405' => $oldState->name_400, 'color_old_state_405' => $oldState->color_400, 'name_state_405' => $state->name_400, 'color_state_405' => $state->color_400, 'names_405' => implode(", ", $names), 'permission_state_405' => $user == null ? false : $userAcl->allows('forms-record', 'edit', $user->profile_id_010), 'permission_comment_405' => $user == null ? false : $userAcl->allows('forms-comment', 'create', $user->profile_id_010), 'permission_forward_405' => $user == null ? false : $userAcl->allows('forms-form', 'edit', $user->profile_id_010), 'permission_record_405' => $user == null ? false : $userAcl->allows('forms-record', 'show', $user->profile_id_010)]), 'data_405' => json_encode($record->toArray())];
     }
     if (count($messages) > 0) {
         Message::insert($messages);
     }
     $response = ['success' => true, 'record' => $this->request->input('record'), 'value' => $this->request->input('value')];
     return response()->json($response);
 }