public function matchProcedure($name, $organizationId, $create = true)
    {
        $cacheId = __CLASS__ . '_' . __FUNCTION__;
        $matches = $this->cache->load($cacheId);

        if (! $matches) {
            $matches = array();
            $select  = $this->db->select();
            $select->from('gems__agenda_procedures', array(
                'gapr_id_procedure', 'gapr_match_to', 'gapr_id_organization', 'gapr_filter',
                ));

            $result = $this->db->fetchAll($select);
            foreach ($result as $row) {
                if (null === $row['gapr_id_organization']) {
                    $key = 'null';
                } else {
                    $key = $row['gapr_id_organization'];
                }
                foreach (explode('|', $row['gapr_match_to']) as $match) {
                    $matches[$match][$key] = $row['gapr_filter'] ? false : $row['gapr_id_procedure'];
                }
            }
            $this->cache->save($matches, $cacheId, array('procedures'));
        }

        if (isset($matches[$name])) {
            if (isset($matches[$name][$organizationId])) {
                return $matches[$name][$organizationId];
            }
            if (isset($matches[$name]['null'])) {
                return $matches[$name]['null'];
            }
        }

        if (! $create) {
            return null;
        }

        $result = $this->addProcedure($name, $organizationId);

        return $result['gapr_filter'] ? false : $result['gapr_id_procedure'];
    }
public function matchProcedure($name, $organizationId, $create = true)
    {
        $cacheId = __CLASS__ . '_' . __FUNCTION__;
        $matches = $this->cache->load($cacheId);

        if (! $matches) {
            $matches = array();
            $select  = $this->db->select();
            $select->from('gems__agenda_procedures', array(
                'gapr_id_procedure', 'gapr_match_to', 'gapr_id_organization', 'gapr_filter',
                ));

            $result = $this->db->fetchAll($select);
            foreach ($result as $row) {
                if (null === $row['gapr_id_organization']) {
                    $key = 'null';
                } else {
                    $key = $row['gapr_id_organization'];
                }
                foreach (explode('|', $row['gapr_match_to']) as $match) {
                    $matches[$match][$key] = $row['gapr_filter'] ? false : $row['gapr_id_procedure'];
                }
            }
            $this->cache->save($matches, $cacheId, array('procedures'));
        }

        if (isset($matches[$name])) {
            if (isset($matches[$name][$organizationId])) {
                return $matches[$name][$organizationId];
            }
            if (isset($matches[$name]['null'])) {
                return $matches[$name]['null'];
            }
        }

        if (! $create) {
            return null;
        }

        $result = $this->addProcedure($name, $organizationId);

        return $result['gapr_filter'] ? false : $result['gapr_id_procedure'];
    }
public function matchProcedure ( $ name , $ organizationId , $ create = true ) { $ cacheId = __CLASS__ . '_' . __FUNCTION__ ; $ matches = $ this -> cache -> load ( $ cacheId ) ; if ( ! $ matches ) { $ matches = array ( ) ; $ select = $ this -> db -> select ( ) ; $ select -> from ( 'gems__agenda_procedures' , array ( 'gapr_id_procedure' , 'gapr_match_to' , 'gapr_id_organization' , 'gapr_filter' , ) ) ; $ result = $ this -> db -> fetchAll ( $ select ) ; foreach ( $ result as $ row ) { if ( null === $ row [ 'gapr_id_organization' ] ) { $ key = 'null' ; } else { $ key = $ row [ 'gapr_id_organization' ] ; } foreach ( explode ( '|' , $ row [ 'gapr_match_to' ] ) as $ match ) { $ matches [ $ match ] [ $ key ] = $ row [ 'gapr_filter' ] ? false : $ row [ 'gapr_id_procedure' ] ; } } $ this -> cache -> save ( $ matches , $ cacheId , array ( 'procedures' ) ) ; } if ( isset ( $ matches [ $ name ] ) ) { if ( isset ( $ matches [ $ name ] [ $ organizationId ] ) ) { return $ matches [ $ name ] [ $ organizationId ] ; } if ( isset ( $ matches [ $ name ] [ 'null' ] ) ) { return $ matches [ $ name ] [ 'null' ] ; } } if ( ! $ create ) { return null ; } $ result = $ this -> addProcedure ( $ name , $ organizationId ) ; return $ result [ 'gapr_filter' ] ? false : $ result [ 'gapr_id_procedure' ] ; }
Find a procedure code for the name and organization.

@param string $name The name to match against
@param int $organizationId Organization id
@param boolean $create Create a match when it does not exist
@return int or null
Find a procedure code for the name and organization .