model() public static method

Returns the static model of the specified AR class.
public static model ( $className = __CLASS__ ) : AuditType
return AuditType the static model class
示例#1
0
echo CHtml::dropDownList('firm_id', @$_POST['firm_id'], Firm::model()->getList(), array('empty' => 'All firms'));
?>
									</td>
									<td>
										<?php 
$this->widget('zii.widgets.jui.CJuiAutoComplete', array('id' => 'user', 'name' => 'user', 'value' => '', 'sourceUrl' => array('audit/users'), 'options' => array('minLength' => '3'), 'htmlOptions' => array('placeholder' => 'Type to search for users...')));
?>
									</td>
									<td>
										<?php 
echo CHtml::dropDownList('action', @$_POST['action'], CHtml::listData(AuditAction::model()->findAll(array('order' => 'name')), 'id', 'name'), array('empty' => 'All actions'));
?>
									</td>
									<td>
										<?php 
echo CHtml::dropDownList('target_type', @$_POST['target_type'], CHtml::listData(AuditType::model()->findAll(array('order' => 'name')), 'id', 'name'), array('empty' => 'All targets'));
?>
									</td>
									<td>
										<?php 
echo CHtml::dropDownList('event_type_id', @$_POST['event_type_id'], EventType::model()->getEventTypeInUseList(), array('empty' => 'All event types'));
?>
									</td>
								</tr>
							</tbody>
						</table>
					</div>
				</div>

				<div class="row">
					<div class="large-10 column">
示例#2
0
 public static function add($target, $action, $data = null, $log_message = null, $properties = array())
 {
     if (!($_target = AuditType::model()->find('name=?', array($target)))) {
         $_target = new AuditType();
         $_target->name = $target;
         if (!$_target->save()) {
             throw new Exception("Unable to save audit target: " . print_r($_target->getErrors(), true));
         }
     }
     if (!($_action = AuditAction::model()->find('name=?', array($action)))) {
         $_action = new AuditAction();
         $_action->name = $action;
         if (!$_action->save()) {
             throw new Exception("Unable to save audit action: " . print_r($_action->getErrors(), true));
         }
     }
     $audit = new Audit();
     $audit->type_id = $_target->id;
     $audit->action_id = $_action->id;
     $audit->data = $data;
     if (!isset($properties['user_id'])) {
         if (Yii::app()->session['user']) {
             $properties['user_id'] = Yii::app()->session['user']->id;
         }
     }
     if (isset($properties['module'])) {
         if ($et = EventType::model()->find('class_name=?', array($properties['module']))) {
             $properties['event_type_id'] = $et->id;
         } else {
             if (!($module = AuditModule::model()->find('name=?', array($properties['module'])))) {
                 $module = new AuditModule();
                 $module->name = $properties['module'];
                 if (!$module->save()) {
                     throw new Exception("Unable to create audit_module: " . print_r($module->getErrors(), true));
                 }
             }
             $properties['module_id'] = $module->id;
         }
         unset($properties['module']);
     }
     if (isset($properties['model'])) {
         if (!($model = AuditModel::model()->find('name=?', array($properties['model'])))) {
             $model = new AuditModel();
             $model->name = $properties['model'];
             if (!$model->save()) {
                 throw new Exception("Unable to save audit_model: " . print_r($model->getErrors(), true));
             }
         }
         $properties['model_id'] = $model->id;
         unset($properties['model']);
     }
     foreach ($properties as $key => $value) {
         $audit->{$key} = $value;
     }
     if (!$audit->save()) {
         throw new Exception("Failed to save audit entry: " . print_r($audit->getErrors(), true));
     }
     if (isset($properties['user_id'])) {
         $username = User::model()->findByPk($properties['user_id'])->username;
     }
     $log_message && OELog::log($log_message, @$username);
     return $audit;
 }