Exemplo n.º 1
0
 /**
  * add action notes
  *
  * @author                                  youzhao.zxw<*****@*****.**>
  * @param   string  $tableName              target table name
  * @param   string  $action                 edit action
  * @param   array   $newRecordAttributes    new record attributes
  * @param   array   $oldRecordAttributs     old record attributes
  * @return  array                           add action notes result
  */
 public static function addActionNotes($tableName, $action, $newRecordAttributes, $oldRecordAttributs)
 {
     $infoAction = new AdminAction();
     $infoAction->action_type = $action;
     $infoAction->target_table = $tableName;
     $infoAction->target_id = $newRecordAttributes['id'];
     if (!$infoAction->save()) {
         $resultInfo['status'] = CommonService::$ApiResult['FAIL'];
         $resultInfo['detail'] = $infoAction->getErrors();
         return $resultInfo;
     } else {
         if (!empty($oldRecordAttributs)) {
             $diffAttributeArr = self::compareRecord($oldRecordAttributs, $newRecordAttributes);
             foreach ($diffAttributeArr as $diffInfo) {
                 $actionHistory = new AdminHistory();
                 $actionHistory->action_field = $diffInfo[0];
                 $actionHistory->adminaction_id = $infoAction->id;
                 $actionHistory->old_value = $diffInfo[1];
                 $actionHistory->new_value = $diffInfo[2];
                 if (!$actionHistory->save()) {
                     $resultInfo['status'] = CommonService::$ApiResult['FAIL'];
                     $resultInfo['detail'] = $actionHistory->getErrors();
                     return $resultInfo;
                 }
             }
         }
     }
     $resultInfo['status'] = CommonService::$ApiResult['SUCCESS'];
     $resultInfo['detail'] = array('id' => $infoAction->id);
     return $resultInfo;
 }
Exemplo n.º 2
0
 /**
  * 新增一条管理员操作记录
  * @param type $attr
  * @return boolean
  */
 public static function add($attr)
 {
     if (empty($attr)) {
         return false;
     }
     $modelAA = new AdminAction();
     $modelAA->attributes = $attr;
     if ($modelAA->save()) {
         return true;
     }
     return false;
 }
Exemplo n.º 3
0
 public static function record($type, $logid = 0)
 {
     if ($type == '') {
         return false;
     }
     if (Yii::app()->user->isGuest) {
         return false;
     }
     $uid = Yii::app()->user->id;
     $desc = GroupPowers::getDesc('admin', $type);
     if ($desc == '') {
         return false;
     }
     $data = array('uid' => $uid, 'logid' => $logid, 'classify' => $type, 'description' => $desc, 'ip' => ip2long(Yii::app()->request->userHostAddress), 'cTime' => time());
     $model = new AdminAction();
     $model->attributes = $data;
     if ($model->save()) {
         return true;
     } else {
         return false;
     }
 }