OphTrOperationbooking_Admission_Letter_Warning_Rule::getRule PHP Method

getRule() public static method

public static getRule ( $rule_type_name, $site_id, $is_child, $theatre_id, $subspecialty_id, $firm_id )
    public static function getRule($rule_type_name, $site_id, $is_child, $theatre_id, $subspecialty_id, $firm_id)
    {
        if (!($rule_type = OphTrOperationbooking_Admission_Letter_Warning_Rule_Type::model()->find('name=?', array($rule_type_name)))) {
            throw new Exception("We were asked for a rule type that doesn't exist: {$rule_type_name}");
        }
        $criteria = new CDbCriteria();
        $criteria->addCondition("parent_rule_id is null and rule_type_id = {$rule_type->id}");
        $criteria->addCondition("rule_type_id = {$rule_type->id}");
        $criteria->order = 'rule_order asc';
        foreach (self::model()->findAll($criteria) as $rule) {
            if ($rule->applies($site_id, $is_child, $theatre_id, $subspecialty_id, $firm_id)) {
                return $rule->parse($site_id, $is_child, $theatre_id, $subspecialty_id, $firm_id);
            }
        }
    }

Usage Example

 public function getWarningHTML($type)
 {
     $return = '';
     $subspecialty_id = $this->session->firm ? $this->session->firm->serviceSubspecialtyAssignment->subspecialty_id : null;
     if ($rule = OphTrOperationbooking_Admission_Letter_Warning_Rule::getRule($type, $this->session->theatre->site_id, $this->operation->event->episode->patient->isChild($this->session->date), $this->session->theatre_id, $subspecialty_id, $this->session->firm_id)) {
         if ($rule->strong) {
             $return .= '<strong>';
         }
         if ($rule->emphasis) {
             $return .= '<em>';
         }
         $return .= $rule->warning_text;
         if ($rule->emphasis) {
             $return .= '</em>';
         }
         if ($rule->strong) {
             $return .= '</strong>';
         }
     }
     return $return;
 }