Esempio n. 1
0
 public function popularOffers()
 {
     $this->seo(array("title" => "Popular Offers", "view" => $this->getLayoutView()));
     $view = $this->getActionView();
     $organizations = Organization::all(array("live = ?" => true), array("id", "name"));
     $packages = Package::all(array(), array("title", "id"));
     $tests = Test::all(array(), array("title", "id"));
     $limit = RequestMethods::get("limit", 10);
     $page = RequestMethods::get("page", 1);
     $offers = Offer::all(array("live = ?" => 1), array("*"), "created", "desc", $limit, $page);
     $total = (int) Offer::count(array("live = ?" => 1));
     $results = array();
     foreach ($offers as $o) {
         $type = array();
         switch ($o->property) {
             case 'test':
                 $type['title'] = $tests[$o->property_id]->title;
                 $type['id'] = $o->property_id;
                 break;
             case 'package':
                 $type['title'] = $packages[$o->property_id]->title;
                 $type['id'] = $o->property_id;
                 break;
         }
         $data = array("id" => $o->id, "start" => StringMethods::datetime_to_text($o->start), "end" => StringMethods::datetime_to_text($o->end), "percent" => $o->percent, "type" => $o->property, "type_title" => $type['title'], "type_id" => $type['id'], "lab" => $organizations[$o->organization_id], "lab_id" => $o->organization_id);
         $results[] = ArrayMethods::toObject($data);
     }
     $view->set("offers", $results)->set("total", $total);
 }
Esempio n. 2
0
 /**
  * @before _secure, _vendor
  */
 public function reports()
 {
     $this->seo(array("title" => "Test Report", "view" => $this->getLayoutView()));
     $view = $this->getActionView();
     $centre_id = RequestMethods::get("centre_id", $this->member->centre_id);
     $appointments = Appointment::all(array("centre_id = ?" => $centre_id), array("id", "patient_id", "user_id", "service_id", "start"));
     $view->set("appointments", $appointments);
     if (RequestMethods::post("action") == "report") {
         $appt_id = RequestMethods::post("appointment_id");
         if (!array_key_exists($appt_id, $appointments)) {
             $view->set("message", "Invalid request!!");
             return;
         }
         $appt = $appointments[$appt_id];
         $job = Job::first(array("appointment_id = ?" => $appt->id));
         if (!$job) {
             $view->set("message", "Invalid Request!!");
             return;
         }
         // find emails
         $user = User::first(array("id = ?" => $appt->user_id), array("email"));
         $patient = User::first(array("id = ?" => $appt->patient_id), array("email"));
         if (!$user->email && !$patient->email) {
             $view->set("message", "No email to send message to");
             return;
         } elseif (!$patient->email) {
             $emails = $user->email;
         } else {
             $emails = array($user->email, $patient->email);
             $emails = array_unique($emails);
         }
         // upload file
         $file = $this->_upload('file', "files", array("extensions" => "pdf"));
         if (!$file) {
             $view->set("message", "File upload failed!!");
             return;
         }
         $file_path = APP_PATH . '/public/assets/uploads/files/' . $file;
         $name = $this->organization->name;
         Shared\Services\Mail::notify(array("emails" => $emails, "delivery" => "sendgrid", "template" => "sendReport", "lab" => $name, "apptime" => \Framework\StringMethods::datetime_to_text($appt->start), "subject" => RequestMethods::post("report_detail"), "attachment" => $file_path));
         unlink($file_path);
         $job->live = 1;
         $job->save();
         $view->set("message", "Sent Successfully");
     }
 }