Tuesday, November 30, 2021

Marge more than two array (marge by datetime) and display it

 Hello

Here I display how to marge more than two array according to datetime and display it bind together.


public function getTicketChatData($ticketID) {
$noteList = $this->customersupportmodel->getUserTicketNotes($ticketID);
$notes = json_decode($noteList)->Data[0]->Results;
$notesCount = count($notes);

$docList = $this->customersupportmodel->getUserTicketDocs($ticketID);
$docs = json_decode($docList)->Data[0]->Results;
$docsCount = count($docs);

// get job_workflow_history data 
$flowList = $this->customersupportmodel->getJobWorkflowHistory($ticketID);
$flowSteps = json_decode($flowList)->Data[0]->Results;
$flowCount = count($flowSteps);
//end jwh
//echo " c:".$flowCount;

$doc_data = $note_data = $chatData = $flowData = $chatData1 = $chatData2 = [];
if ( $notesCount > 0) {
foreach($notes as $n) {
$note_data[] = [
'type' => 1,
'date' => date('Y-m-d H:i:s', strtotime($n->key_update_date)),
'data' => $n
];
}
}
if ($docsCount > 0 ) {
foreach($docs as $d) {
$doc_data[] = [
'type' => 2,
'date' => date('Y-m-d H:i:s', strtotime($d->key_update_date)),
'data' => $d
];
}
}
if ($flowCount > 0 ) {
foreach($flowSteps as $f) {
$flowData[] = [
'type' => 3,
'date' => date('Y-m-d H:i:s', strtotime($f->key_update_date)),
'data' => $f
];
}
}

//echo "<pre>";print_r($flowData);

$chatData1 = array_merge($note_data, $doc_data);
uasort($chatData1, function ($a, $b) {
    return $a['date'] <=> $b['date'];
});

$chatData = array_merge($chatData1, $flowData);
uasort($chatData, function ($a, $b) {
    return $a['date'] <=> $b['date'];
});

return $chatData;
}


//now display it in view file



$noteHtml = '';
$loggedUserId = $this->session->userdata('UserID');
//echo $countDocNote = count($Notes);
$isDocStart = false;
$countDocNote = count($chatData);
    if ($countDocNote > 0) {
      foreach ($chatData as $key => $notesDocsData) {
        //echo "<pre>"; print_r($notesDocsData);
        $newUser = $notesDocsData['data']->userID;
        $create_by = $notesDocsData['data']->create_by;
        $type = $notesDocsData['type'];

        //$userFirstLetter = strtoupper($notesDocsData['data']->username[0]);

        if($type == 1){
          //echo "notes-"; // for notes
          if ($isDocStart) {
            $noteHtml.= "</div></div>";
            $isDocStart = false;
          }
          $note = $notesDocsData['data']->Note;
          $noteID = $notesDocsData['data']->NoteId;
          $notesCreateDate = $notesDocsData['data']->create_date;
          $notesdate =  date("M j, Y",strtotime($notesCreateDate)); 
          //$created_by_date = date("j M Y",strtotime($notesCreateDate)); 
          $newTimeForNote = new DateTime($notesCreateDate);
          $noteTime = $newTimeForNote->format("h:i a");
          $taskdate =  date("M j, Y",strtotime($notesCreateDate)); 
          //$newTime = new DateTime($taskdate);
          //$taskTime = $newTime->format("h:i a");
          //start display_name
          $fullname = $notesDocsData['data']->name_first." ".$notesDocsData['data']->name_last;
          $displayName = $notesDocsData['data']->display_name;
          if ($displayName == "") {
            $display_name = $notesDocsData['data']->name_first." ".$notesDocsData['data']->name_last;
          }elseif ($notesDocsData['data']->name_first == "" && $notesDocsData['data']->name_last == "") {
            $display_name = $notesDocsData['data']->username;
          }else{
            $display_name = $notesDocsData['data']->display_name;
          }
          $userFirstLetter = strtoupper($display_name[0]);
          //end dsiplay_name

          //if(empty($notesDocsData['data']->org_id)){
          //if($notesDocsData['data']->org_id == 0){ // customer right side support left side
          if($loggedUserId == $create_by) { // logged user chat is right side
            $chatClass = "bsit_chat_user";
          }else{
            $chatClass = "bsit_chat_support";
          }
          $noteHtml.= "<div class='$chatClass'> <div class='bsit_chat_section' id='div_$noteID' >";
            $noteHtml.= "<div class='bsit_chat_user_name'><span>".$userFirstLetter."</span>".$display_name."</div>";
            $noteHtml.= "<div class='bsit_chat_detail'> ".$note." <span class='bsit_chat_time'>".$taskdate." | ".$noteTime."</span></div>";
            //echo "<div class='bsit_chat_attachment'><img src='".base_url()."assets/core/images/attachment_chat.png'>(static)GoogleCloudPrinting.png</div>";
          $noteHtml.= "</div></div>";

        }elseif($type == 2){
          //echo "doc-";// display documents/ attachment
          //$fullname = $notesDocsData['data']->name_first." ".$notesDocsData['data']->name_last;
          //start display_name
          $fullname = $notesDocsData['data']->name_first." ".$notesDocsData['data']->name_last;
          $displayName = $notesDocsData['data']->display_name;
          if ($displayName == "") {
            $display_name = $notesDocsData['data']->name_first." ".$notesDocsData['data']->name_last;
          }elseif ($notesDocsData['data']->name_first == "" && $notesDocsData['data']->name_last == "") {
            $display_name = $notesDocsData['data']->username;
          }else{
            $display_name = $notesDocsData['data']->display_name;
          }
          $userFirstLetter = strtoupper($display_name[0]);
          //end dsiplay_name

          $notesCreateDate = $notesDocsData['data']->create_date;
          $newTimeForNote = new DateTime($notesCreateDate);
          //$notesdate =  date("M j, Y",strtotime($notesCreateDate)); 
          $noteTime = $newTimeForNote->format("h:i a");
          $taskdate =  date("M j, Y",strtotime($notesCreateDate));
          $a_id = $notesDocsData['data']->_id;
          $file_name = $notesDocsData['data']->file_name;
          $file_location = $notesDocsData['data']->file_location;
          $file_update_date = $notesDocsData['data']->key_update_date;
          //if(empty($notesDocsData['data']->org_id)){
          if($loggedUserId == $create_by) { // logged user chat is right side
            $chatClass = "bsit_chat_user";
          }else{
            $chatClass = "bsit_chat_support";
          }
          $documentDownloalLink = base_url()."page/downloadDocument?docid=".$a_id;
          if ($isDocStart && $newUser != $oldUser) {
            $noteHtml.= "</div></div>";
            $isDocStart = false;
          }
          if ($isDocStart == false) {
            $isDocStart = true;
            $noteHtml.= "<div class='$chatClass'> <div class='bsit_chat_section' id='div_$a_id' >";
            $noteHtml.= "<div class='bsit_chat_user_name'><span>".$userFirstLetter."</span>".$display_name."</div>";
          }
          
          $noteHtml.= "<div class='bsit_chat_attachment'><div class='attchment'><a href='".$documentDownloalLink."' title='Attachment' target='_blank'> <img src='".base_url()."assets/core/images/attachment_chat.png'>$file_name</a> </div><span class='bsit_chat_time'>".$taskdate." | ".$noteTime."</span></div>"; 
        }elseif($type == 3){
          //$fullname = $notesDocsData['data']->name_first." ".$notesDocsData['data']->name_last;
          //start display_name
          $fullname = $notesDocsData['data']->name_first." ".$notesDocsData['data']->name_last;
          $displayName = $notesDocsData['data']->display_name;
          if ($displayName == "") {
            $display_name = $notesDocsData['data']->name_first." ".$notesDocsData['data']->name_last;
          }elseif ($notesDocsData['data']->name_first == "" && $notesDocsData['data']->name_last == "") {
            $display_name = $notesDocsData['data']->username;
          }else{
            $display_name = $notesDocsData['data']->display_name;
          }
          $userFirstLetter = strtoupper($display_name[0]);
          //end dsiplay_name

          $notesCreateDate = $notesDocsData['data']->create_date;
          $newTimeForNote = new DateTime($notesCreateDate);
          //$notesdate =  date("M j, Y",strtotime($notesCreateDate)); 
          $noteTime = $newTimeForNote->format("h:i a");
          $taskdate =  date("j M Y",strtotime($notesCreateDate));
          $file_update_date = $notesDocsData['data']->key_update_date;
          $status_title = $notesDocsData['data']->status_title;
          if($status_title == 'Complete'){
            $noteHtml.="<div class='bsit_ticket_close_chat ticketComplete'><span>This ticket is closed by $display_name on $taskdate</span></div>";
          }elseif ($status_title == 'reopen') {
            $noteHtml.="<div class='bsit_ticket_status_chat ticketReOpen'><span>Reopen by $display_name on $taskdate</span></div>";
          }elseif ($status_title == 'Assigned'){
            $noteHtml.="<div class='bsit_ticket_status_chat ticketAccepted'><span>Assigned to $display_name on $taskdate</span></div>";
          }else{
            $noteHtml.="<div class='bsit_ticket_status_chat ticketNormal'><span>$status_title to $display_name on $taskdate</span></div>";
          }
          
        }
        $oldUser = $newUser;
      }
      if ($isDocStart) {
        $noteHtml.= "</div></div>";
        $isDocStart = false;
      }       
      
    }else{
      $noteHtml.= "<div class='noAnyNotesMainDiv'><span>This Ticket has no any notes or attachment!!!</span></div>";
    }
echo $noteHtml;

No comments:

Post a Comment