예제 #1
0
 private function addOwnersRelations($org_id)
 {
     $owners = array_unique($this->owners);
     foreach ($owners as $owner) {
         $relation = new UsersOrganizations();
         $relation->isNewRecord = true;
         $relation->user_id = $owner;
         $relation->organization_id = $org_id;
         $relation->save();
     }
 }
예제 #2
0
파일: Users.php 프로젝트: aversilov/prexr
 public static function isOrgOwner($user_id, $org_id)
 {
     return self::find()->from(self::tableName() . ' u')->innerJoin(UsersOrganizations::tableName() . ' uo', 'u.id = uo.user_id')->innerJoin(Organizations::tableName() . ' o', 'o.id = uo.organization_id')->where(['o.id' => $org_id, 'u.id' => $user_id])->exists();
 }
예제 #3
0
파일: Users.php 프로젝트: aversilov/prexr
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getUsersOrganizations()
 {
     return $this->hasMany(UsersOrganizations::className(), ['user_id' => 'id']);
 }
예제 #4
0
파일: Users.php 프로젝트: aversilov/prexr
 public static function getByOrg($org_id)
 {
     $sql = 'SELECT u.username ' . ' FROM ' . self::tableName() . ' u ' . ' JOIN ' . UsersOrganizations::tableName() . ' uo ' . ' ON u.id = uo.user_id ' . ' JOIN ' . Organizations::tableName() . ' o ' . ' ON o.id = uo.organization_id ' . ' WHERE o.id = :org_id';
     return self::findBySql($sql, [':org_id' => $org_id])->asArray()->all();
     self::find()->select('u.username')->from(self::tableName() . ' u')->innerJoin(UsersOrganizations::tableName() . ' uo', 'u.id = uo.user_id')->innerJoin(Organizations::tableName() . ' o', 'o.id = uo.organization_id')->where(['o.id' => $org_id])->asArray()->all();
 }
예제 #5
0
 public static function getByUserId($user_id)
 {
     $sql = 'SELECT o.id, o.nice_name ' . ' FROM ' . self::tableName() . ' o ' . ' JOIN ' . UsersOrganizations::tableName() . ' uo ' . ' ON o.id = uo.organization_id ' . ' JOIN ' . Users::tableName() . ' u ' . ' ON u.id = uo.user_id ' . ' WHERE u.id = :user_id' . ' ORDER BY o.nice_name ';
     return self::findBySql($sql, [':user_id' => $user_id])->asArray()->all();
 }