/** * 获取状态变更按钮 * 如果是最后一个状态,则不扭转 * @param \Lite\DB\Model $model 数据模型 * @param null $field 状态字段名 * @param array $state_options 状态扭转选项(缺省读取options) * @return string * @throws \Lite\Exception\Exception */ public static function getNextStateBtn(Model $model, $field = null, $state_options = array()) { if (!$field && $model instanceof ModelInterface) { $field = $model->getStateKey(); } if (!$field) { throw new Exception('next state field not found'); } $options = $state_options ?: $model->getPropertiesDefine($field)['options']; $val = $model->{$field}; $pk = $model->getPrimaryKey(); $matched = false; foreach ($options as $k => $opt_name) { if ($val == $k) { $matched = true; } else { if ($matched) { return '<a href="' . self::getUrl(self::getController() . '/state', array($field => $k, $pk => $model->{$pk})) . '" rel="async" class="state-changer btn">' . $opt_name . '</a>'; } } } return ''; }