/** * Returns a new UserOrganizationQuery object. * * @param string $modelAlias The alias of a model in the query * @param UserOrganizationQuery|Criteria $criteria Optional Criteria to build the query from * * @return UserOrganizationQuery */ public static function create($modelAlias = null, $criteria = null) { if ($criteria instanceof UserOrganizationQuery) { return $criteria; } $query = new UserOrganizationQuery(); if (null !== $modelAlias) { $query->setModelAlias($modelAlias); } if ($criteria instanceof Criteria) { $query->mergeWith($criteria); } return $query; }
public function setRole($user, $role) { $uo = UserOrganizationQuery::create()->filterByOrganization($this)->filterByUser($user)->findOne(); if ($uo) { $uo->setOrganizationRole($role)->save(); } }
}); /* * add user to organization */ $app->post('/organizations/:id/users', function ($org_id) use($app) { if_is_admin(function () use($app, $org_id) { $org = OrganizationQuery::create()->findPk($org_id); if ($org) { $data = json_decode($app->request()->getBody(), true); $alreadyInOrg = array(); $added = 0; foreach ($data as $u_id) { $u = UserQuery::create()->findPk($u_id); if ($u) { // number of organization users $c = UserOrganizationQuery::create()->filterByOrganization($org)->filterByInviteToken('', Criteria::NOT_EQUAL)->count(); if ($c > 0 && $org->hasUser($u)) { $alreadyInOrg[] = $u->guessName(); } else { $org->addUser($u); $added++; // make first user the admin // if ($c == 0) { // $org->save(); // $org->setRole($u, 'admin'); // } DatawrapperHooks::execute(DatawrapperHooks::USER_ORGANIZATION_ADD, $org, $u); } } } $org->save();
}); /* * add user to organization */ $app->post('/organizations/:id/users', function ($org_id) use($app) { if_is_admin(function () use($app, $org_id) { $org = OrganizationQuery::create()->findPk($org_id); if ($org) { $data = json_decode($app->request()->getBody(), true); $alreadyInOrg = array(); $added = 0; foreach ($data as $u_id) { $u = UserQuery::create()->findPk($u_id); if ($u) { // number of organization users $c = UserOrganizationQuery::create()->filterByOrganization($org)->count(); if ($c > 0 && $org->hasUser($u)) { $alreadyInOrg[] = $u->guessName(); } else { $org->addUser($u); $added++; // make first user the admin // if ($c == 0) { // $org->save(); // $org->setRole($u, 'admin'); // } DatawrapperHooks::execute(DatawrapperHooks::USER_ORGANIZATION_ADD, $org, $u); } } } $org->save();
/** * Removes this object from datastore and sets delete attribute. * * @param PropelPDO $con * @return void * @throws PropelException * @throws Exception * @see BaseObject::setDeleted() * @see BaseObject::isDeleted() */ public function delete(PropelPDO $con = null) { if ($this->isDeleted()) { throw new PropelException("This object has already been deleted."); } if ($con === null) { $con = Propel::getConnection(UserOrganizationPeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } $con->beginTransaction(); try { $deleteQuery = UserOrganizationQuery::create()->filterByPrimaryKey($this->getPrimaryKey()); $ret = $this->preDelete($con); if ($ret) { $deleteQuery->delete($con); $this->postDelete($con); $con->commit(); $this->setDeleted(true); } else { $con->commit(); } } catch (Exception $e) { $con->rollBack(); throw $e; } }
/** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this User is new, it will return * an empty collection; or if this User has previously * been saved, it will retrieve related UserOrganizations from storage. * * This method is protected by default in order to keep the public * api reasonable. You can provide public methods for those you * actually need in User. * * @param Criteria $criteria optional Criteria object to narrow the query * @param PropelPDO $con optional connection object * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN) * @return PropelObjectCollection|UserOrganization[] List of UserOrganization objects */ public function getUserOrganizationsJoinOrganization($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN) { $query = UserOrganizationQuery::create(null, $criteria); $query->joinWith('Organization', $join_behavior); return $this->getUserOrganizations($query, $con); }