コード例 #1
0
ファイル: Soldier.php プロジェクト: Sywooch/armin
 public function getUnitLink()
 {
     if ($this->unit) {
         $p = Unit::findOne($this->unit);
         if ($p) {
             return Html::a(Html::encode($p->name), ['/unit/view', 'id' => $p->id]);
         }
     }
 }
コード例 #2
0
ファイル: Item.php プロジェクト: Sywooch/armin
 public function getAttachedToLink()
 {
     if (Attachment::isStorehouse($this->attached_to)) {
         return 'На складі';
     }
     if (Attachment::isRepaired($this->attached_to)) {
         return 'В ремонті';
     }
     if (Attachment::isSoldier($this->attached_to)) {
         $soldier = Soldier::findOne($this->attached_to_soldier);
         return Html::a(Html::encode("Службовець: {$soldier->nickname} ({$soldier->name})"), ['/soldier/view', 'id' => $soldier->id]);
     }
     if (Attachment::isUnit($this->attached_to)) {
         $unit = Unit::findOne($this->attached_to_unit);
         $soldier = Soldier::findOne($unit->soldier);
         return Html::a(Html::encode("Підрозділ: {$unit->name} ({$soldier->nickname}({$soldier->name}))"), ['/unit/view', 'id' => $unit->id]);
     }
     return 'undefined';
 }
コード例 #3
0
ファイル: UnitAccessible.php プロジェクト: tqsq2005/Yii2adv
 /**
  * (void) validateAttribute : 校验当前用户是否取得单位编码的完全访问权限
  * @param \yii\base\Model $model
  * @param string $attribute
  */
 public function validateAttribute($model, $attribute)
 {
     /** @var integer $user_id 当前用户ID */
     $user_id = Yii::$app->user->identity->id;
     /** @var string $unitcode 校验单位编码 */
     $unitcode = $model->{$attribute};
     switch ($attribute) {
         case 'unitcode':
             //修改
             if (Unit::findOne(['unitcode' => $unitcode]) && MapUnit::getUserPower($user_id, $unitcode) != MapUnit::USER_POWER_ALLOW) {
                 $this->addError($model, $attribute, '你没有单位(部门)『' . $unitcode . '』的『完全访问』权限.');
             }
             break;
         case 'upunitcode':
             //新增
             if (!Unit::findOne(['upunitcode' => $unitcode]) && MapUnit::getUserPower($user_id, $unitcode) < MapUnit::USER_POWER_VIEW_DEPT) {
                 $this->addError($model, $attribute, '你没有单位(部门)『' . $unitcode . '』的『完全访问』权限.');
             }
             break;
     }
 }
コード例 #4
0
 /**
  * (string) actionCheckUnitAccessible : 客户端ajax校验当前用户是否取得单位编码的完全访问权限
  * 见common\components\validators\UnitAccessible
  * @return string
  */
 public function actionCheckUnitAccessible()
 {
     /** @var string $attribute 字段:unitcode、upunitcode或unit */
     $attribute = Yii::$app->request->post('attribute');
     /** @var string $value 字段对应的值 */
     $value = Yii::$app->request->post('value');
     /** @var integer $user_id 当前用户ID */
     $user_id = Yii::$app->user->identity->id;
     $errMsg = '';
     switch ($attribute) {
         case 'unitcode':
             //修改
             if (Unit::findOne(['unitcode' => $value]) && MapUnit::getUserPower($user_id, $value) != MapUnit::USER_POWER_ALLOW) {
                 $errMsg = '你没有单位(部门)『' . $value . '』的『完全访问』权限.';
             }
             break;
         case 'upunitcode':
             //新增
             if (!Unit::findOne(['upunitcode' => $value]) && MapUnit::getUserPower($user_id, $value) < MapUnit::USER_POWER_VIEW_DEPT) {
                 $errMsg = '你没有单位(部门)『' . $value . '』的『完全访问』权限.';
             }
             break;
     }
     return $errMsg;
 }
コード例 #5
0
ファイル: UnitController.php プロジェクト: tqsq2005/Yii2adv
 /**
  * Finds the Unit model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param $unitcode
  * @return Unit the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($unitcode)
 {
     if (($model = Unit::findOne(['unitcode' => $unitcode])) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('数据获取失败..');
     }
 }
コード例 #6
0
ファイル: UnitController.php プロジェクト: Sywooch/armin
 /**
  * Finds the Unit model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return Unit the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Unit::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }