model() public static method

Returns the static model of the specified AR class.
public static model ( $className = __CLASS__ ) : ElementOperation
return ElementOperation the static model class
示例#1
0
 public function actionDeleteLetterMacros()
 {
     $criteria = new CDbCriteria();
     $criteria->addInCondition('id', @$_POST['id']);
     if (LetterMacro::model()->deleteAll($criteria)) {
         echo '1';
     } else {
         echo '0';
     }
 }
示例#2
0
 /**
  * Ajax action to get macro data for populating the letter elements.
  *
  * @throws Exception
  */
 public function actionGetMacroData()
 {
     if (!($patient = Patient::model()->findByPk(@$_GET['patient_id']))) {
         throw new Exception('Patient not found: ' . @$_GET['patient_id']);
     }
     if (!($macro = LetterMacro::model()->findByPk(@$_GET['macro_id']))) {
         throw new Exception('Macro not found: ' . @$_GET['macro_id']);
     }
     $data = array();
     $macro->substitute($patient);
     if ($macro->recipient && $macro->recipient->name == 'Patient') {
         $data['sel_address_target'] = 'Patient' . $patient->id;
         $contact = $patient;
         if ($patient->isDeceased()) {
             echo json_encode(array('error' => 'DECEASED'));
             return;
         }
     }
     if ($macro->recipient && $macro->recipient->name == 'GP' && ($contact = $patient->gp ? $patient->gp : $patient->practice)) {
         $data['sel_address_target'] = get_class($contact) . $contact->id;
     }
     if (isset($contact)) {
         $address = $contact->getLetterAddress(array('patient' => $patient, 'include_name' => true, 'include_label' => true, 'delimiter' => "\n"));
         if ($address) {
             $data['text_ElementLetter_address'] = $address;
         } else {
             $data['alert'] = 'The contact does not have a valid address.';
             $data['text_ElementLetter_address'] = '';
         }
         $data['text_ElementLetter_introduction'] = $contact->getLetterIntroduction(array('nickname' => $macro->use_nickname));
     }
     $data['check_ElementLetter_use_nickname'] = $macro->use_nickname;
     if ($macro->body) {
         $data['text_ElementLetter_body'] = $macro->body;
     }
     $cc = array('text' => array(), 'targets' => array());
     if ($macro->cc_patient) {
         if ($patient->isDeceased()) {
             $data['alert'] = "Warning: the patient cannot be cc'd because they are deceased.";
         } elseif ($patient->contact->address) {
             $cc['text'][] = $patient->getLetterAddress(array('include_name' => true, 'include_label' => true, 'delimiter' => ', ', 'include_prefix' => true));
             $cc['targets'][] = '<input type="hidden" name="CC_Targets[]" value="Patient' . $patient->id . '" />';
         } else {
             $data['alert'] = "Letters to the GP should be cc'd to the patient, but this patient does not have a valid address.";
         }
     }
     if ($macro->cc_doctor && ($cc_contact = $patient->gp ? $patient->gp : $patient->practice)) {
         $cc['text'][] = $cc_contact->getLetterAddress(array('patient' => $patient, 'include_name' => true, 'include_label' => true, 'delimiter' => ', ', 'include_prefix' => true));
         $cc['targets'][] = '<input type="hidden" name="CC_Targets[]" value="' . get_class($cc_contact) . $cc_contact->id . '" />';
     }
     if ($macro->cc_drss) {
         $commissioningbodytype = CommissioningBodyType::model()->find('shortname = ?', array('CCG'));
         if ($commissioningbodytype && ($commissioningbody = $patient->getCommissioningBodyOfType($commissioningbodytype))) {
             $drss = null;
             foreach ($commissioningbody->services as $service) {
                 if ($service->type->shortname == 'DRSS') {
                     $cc['text'][] = $service->getLetterAddress(array('include_name' => true, 'include_label' => true, 'delimiter' => ', ', 'include_prefix' => true));
                     $cc['targets'][] = '<input type="hidden" name="CC_Targets[]" value="CommissioningBodyService' . $service->id . '" />';
                     break;
                 }
             }
         }
     }
     $data['textappend_ElementLetter_cc'] = implode("\n", $cc['text']);
     $data['elementappend_cc_targets'] = implode("\n", $cc['targets']);
     echo json_encode($data);
 }
示例#3
0
 public function getLetter_macros()
 {
     $macros = array();
     $macro_names = array();
     $firm = Firm::model()->with('serviceSubspecialtyAssignment')->findByPk(Yii::app()->session['selected_firm_id']);
     $criteria = new CDbCriteria();
     $criteria->compare('firm_id', $firm->id);
     $criteria->order = 'display_order asc';
     foreach (LetterMacro::model()->findAll($criteria) as $macro) {
         if (!in_array($macro->name, $macro_names)) {
             $macros[$macro->id] = $macro_names[] = $macro->name;
         }
     }
     if ($firm->service_subspecialty_assignment_id) {
         $criteria = new CDbCriteria();
         $criteria->compare('subspecialty_id', $firm->serviceSubspecialtyAssignment->subspecialty_id);
         $criteria->order = 'display_order asc';
         foreach (LetterMacro::model()->findAll($criteria) as $macro) {
             if (!in_array($macro->name, $macro_names)) {
                 $macros[$macro->id] = $macro_names[] = $macro->name;
             }
         }
     }
     $criteria = new CDbCriteria();
     $criteria->compare('site_id', Yii::app()->session['selected_site_id']);
     $criteria->order = 'display_order asc';
     foreach (LetterMacro::model()->findAll($criteria) as $macro) {
         if (!in_array($macro->name, $macro_names)) {
             $macros[$macro->id] = $macro_names[] = $macro->name;
         }
     }
     return $macros;
 }