EventTypeModuleCode::getEventShortName PHP Method

getEventShortName() public static method

assumes table names of the form et_[specialty_code][group_code][short_name]_[element_short_name] event needs to have had an element defined.
public static getEventShortName ( $event_type )
    public static function getEventShortName($event_type)
    {
        if (isset($event_type->moduleShortSuffix)) {
            return $event_type->moduleShortSuffix;
        } else {
            // try to derive the short suffix from the table name of an element in the class
            if (!($el = ElementType::model()->findall('event_type_id=:eventTypeId', array(':eventTypeId' => $event_type->id)))) {
                throw new Exception("Unable to find element_type for event_type_id = {$event_type->id}");
            }
            if (count($el)) {
                $code = strtolower(substr($event_type->class_name, 0, 5));
                $class = $el[0]->class_name;
                $model = $class::model();
                if (!preg_match('/^et_' . $code . '([a-z0-9]+)_/', $model->tableName(), $m)) {
                    die('ERROR: cannot determine short name for event type ' . $event_type->class_name);
                }
                return $m[1];
            }
            return '';
        }
    }

Usage Example

コード例 #1
0
    public static function eventTypeProperties($event_type_id)
    {
        $event_type = EventType::model()->findByPk($event_type_id);
        $event_type_short_name = EventTypeModuleCode::getEventShortName($event_type);
        if (empty($_POST)) {
            if (!preg_match('/^([A-Z][a-z]+)([A-Z][a-z]+)([A-Z][a-zA-Z]+)$/', $event_type->class_name, $m)) {
                die("ERROR: {$event_type->class_name}");
            }
            $specialty_id = Specialty::model()->find('abbreviation=?', array(strtoupper($m[1])))->id;
            $event_group_id = EventGroup::model()->find('code=?', array($m[2]))->id;
            $event_type_name = $event_type->name;
        } else {
            $specialty_id = @$_REQUEST['Specialty']['id'];
            $event_group_id = @$_REQUEST['EventGroup']['id'];
            $event_type_name = @$_REQUEST['EventTypeModuleCode']['moduleSuffix'];
        }
        ?>
		<label>Specialty: </label>
		<?php 
        echo CHtml::dropDownList('Specialty[id]', $specialty_id, CHtml::listData(Specialty::model()->findAll(array('order' => 'name')), 'id', 'name'));
        ?>
<br/>
		<label>Event group: </label><?php 
        echo CHtml::dropDownList('EventGroup[id]', $event_group_id, CHtml::listData(EventGroup::model()->findAll(array('order' => 'name')), 'id', 'name'));
        ?>
<br />
		<label>Name of event type: </label> <?php 
        echo CHtml::textField('EventTypeModuleCode[moduleSuffix]', $event_type_name, array('size' => 65, 'id' => 'moduleSuffix'));
        ?>
<br />
		<label>Event type short name: </label> <?php 
        echo CHtml::textField('EventTypeModuleCode[moduleShortSuffix]', $event_type_short_name, array('size' => 65, 'id' => 'moduleShortSuffix'));
        ?>
<br />
		<?php 
    }