Returns the static model of the specified AR class.
public static model ( $className = __CLASS__ ) : ContactLocation | ||
return | ContactLocation | the static model class |
public function actionEditContact() { if (!($patient = Patient::model()->findByPk(@$_POST['patient_id']))) { throw new Exception("Patient not found: " . @$_POST['patient_id']); } if (!($contact = Contact::model()->findByPk(@$_POST['contact_id']))) { throw new Exception("Contact not found: " . @$_POST['contact_id']); } if (@$_POST['site_id']) { if (!($site = Site::model()->findByPk(@$_POST['site_id']))) { throw new Exception("Site not found: " . @$_POST['site_id']); } if (!($cl = ContactLocation::model()->find('contact_id=? and site_id=?', array($contact->id, $site->id)))) { $cl = new ContactLocation(); $cl->contact_id = $contact->id; $cl->site_id = $site->id; if (!$cl->save()) { throw new Exception("Unable to save contact location: " . print_r($cl->getErrors(), true)); } } } else { if (!($institution = Institution::model()->findByPk(@$_POST['institution_id']))) { throw new Exception("Institution not found: " . @$_POST['institution_id']); } if (!($cl = ContactLocation::model()->find('contact_id=? and institution_id=?', array($contact->id, $institution->id)))) { $cl = new ContactLocation(); $cl->contact_id = $contact->id; $cl->institution_id = $institution->id; if (!$cl->save()) { throw new Exception("Unable to save contact location: " . print_r($cl->getErrors(), true)); } } } if (!($pca = PatientContactAssignment::model()->findByPk(@$_POST['pca_id']))) { throw new Exception("PCA not found: " . @$_POST['pca_id']); } $pca->location_id = $cl->id; if (!$pca->save()) { throw new Exception("Unable to save patient contact assignment: " . print_r($pca->getErrors(), true)); } $this->redirect(array('/patient/view/' . $patient->id)); }
/** * @covers ContactLocation::model */ public function testModel() { $this->assertEquals('ContactLocation', get_class(ContactLocation::model()), 'Class name should match model.'); }
public function actionRemoveLocation() { if (!($cl = ContactLocation::model()->findByPk(@$_POST['location_id']))) { throw new Exception("ContactLocation not found: " . @$_POST['location_id']); } if (count($cl->patients) > 0) { echo "0"; return; } if (!$cl->delete()) { echo "-1"; return; } Audit::add('admin-ContactLocation', 'delete', @$_POST['location_id']); return "1"; }