/**
  * Get the associated ChildGroup object
  *
  * @param  ConnectionInterface $con Optional Connection object.
  * @return ChildGroup The associated ChildGroup object.
  * @throws PropelException
  */
 public function getGroup(ConnectionInterface $con = null)
 {
     if ($this->aGroup === null && $this->groupid !== null) {
         $this->aGroup = ChildGroupQuery::create()->findPk($this->groupid, $con);
         /* The following can be used additionally to
               guarantee the related object contains a reference
               to this object.  This level of coupling may, however, be
               undesirable since it could result in an only partially populated collection
               in the referenced object.
               $this->aGroup->addGroupAccesses($this);
            */
     }
     return $this->aGroup;
 }
 /**
  * Builds a Criteria object containing the primary key for this object.
  *
  * Unlike buildCriteria() this method includes the primary key values regardless
  * of whether or not they have been modified.
  *
  * @throws LogicException if no primary key is defined
  *
  * @return Criteria The Criteria object containing value(s) for primary key(s).
  */
 public function buildPkeyCriteria()
 {
     $criteria = ChildGroupQuery::create();
     $criteria->add(GroupTableMap::COL_ID, $this->id);
     return $criteria;
 }
 /**
  * Performs an INSERT on the database, given a Group or Criteria object.
  *
  * @param mixed               $criteria Criteria or Group object containing data that is used to create the INSERT statement.
  * @param ConnectionInterface $con the ConnectionInterface connection to use
  * @return mixed           The new primary key.
  * @throws PropelException Any exceptions caught during processing will be
  *                         rethrown wrapped into a PropelException.
  */
 public static function doInsert($criteria, ConnectionInterface $con = null)
 {
     if (null === $con) {
         $con = Propel::getServiceContainer()->getWriteConnection(GroupTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from Group object
     }
     if ($criteria->containsKey(GroupTableMap::COL_ID) && $criteria->keyContainsValue(GroupTableMap::COL_ID)) {
         throw new PropelException('Cannot insert a value for auto-increment primary key (' . GroupTableMap::COL_ID . ')');
     }
     // Set the correct dbName
     $query = GroupQuery::create()->mergeWith($criteria);
     // use transaction because $criteria could contain info
     // for more than one table (I guess, conceivably)
     return $con->transaction(function () use($con, $query) {
         return $query->doInsert($con);
     });
 }
 private function verifyGroupsAreAccessable($groupIds)
 {
     $groupEntityService = $this->relatedEntityServices['Group'];
     $accessableGroupIds = $groupEntityService->getAccessableEntityIds();
     $notAccessable = array();
     foreach ($groupIds as $groupId) {
         if (!in_array($groupId, $accessableGroupIds)) {
             $notAccessable[] = $groupId;
         }
     }
     if (count($notAccessable) == 0) {
         return;
     }
     $groups = $groupEntityService->getAutocompleteModels(ECP\GroupQuery::create()->filterById($notAccessable)->find());
     throw new AccessViolationException('You have to be at least a member of all the groups you are sharing this entity with. This is to prevent random spam.', array('Group' => $groups));
 }
 /**
  * Returns a new ChildGroupQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param     Criteria $criteria Optional Criteria to build the query from
  *
  * @return ChildGroupQuery
  */
 public static function create($modelAlias = null, Criteria $criteria = null)
 {
     if ($criteria instanceof ChildGroupQuery) {
         return $criteria;
     }
     $query = new ChildGroupQuery();
     if (null !== $modelAlias) {
         $query->setModelAlias($modelAlias);
     }
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }
 public function processGroups()
 {
     while (true) {
         $groups = ECP\GroupQuery::create()->where('Group.lastComputed < ?', time() - 24 * 60 * 60)->find();
         $groups->populateRelation('GroupEvePerson');
         $groups->populateRelation('GroupPerson');
         $evePersonNames = array();
         foreach ($groups as $group) {
             foreach ($group->getGroupEvepeople() as $groupEvePerson) {
                 $evePersonNames[] = $groupEvePerson->getName();
             }
         }
         if (count($evePersonNames) != 0) {
             $eveCharacters = ECP\EveCharacterQuery::create()->filterByCharName($evePersonNames)->_or()->filterByCorpName($evePersonNames)->_or()->filterByAllyName($evePersonNames)->find();
             $eveCharacters->populateRelation('EveApi');
             $eveNameDict = array();
             foreach ($eveCharacters as $eveCharacter) {
                 $eveApi = $eveCharacter->getEveApi();
                 $userId = $eveApi->getUserId();
                 $eveNameDict[$eveCharacter->getCharName()] = array($userId);
                 if ($eveCharacter->getCorpId() != 0) {
                     $this->pushEveName($eveNameDict, $eveCharacter->getCorpName(), $userId);
                 }
                 if ($eveCharacter->getAllyId() != 0) {
                     $this->pushEveName($eveNameDict, $eveCharacter->getAllyName(), $userId);
                 }
             }
             foreach ($eveNameDict as $key => $userIds) {
                 $eveNameDict[$key] = array_unique($userIds);
             }
             foreach ($groups as $group) {
                 $personDict = array();
                 foreach ($group->getGrouppeople() as $groupPerson) {
                     $personKey = $groupPerson->getGroupPersonTypeId() . '-' . $groupPerson->getGroupEvePersonId();
                     if (!array_key_exists($personKey, $personDict)) {
                         $personDict[$personKey] = array($groupPerson);
                     } else {
                         $personDict[$personKey][] = $groupPerson;
                     }
                 }
                 $group->setLastComputed(time());
                 $connection = $this->getPropelConnection();
                 try {
                     $connection->beginTransaction();
                     foreach ($group->getGroupEvepeople() as $groupEvePerson) {
                         $name = $groupEvePerson->getName();
                         $userIds = array_key_exists($name, $eveNameDict) ? $eveNameDict[$name] : array();
                         $personKey = $groupEvePerson->getGroupPersonTypeId() . '-' . $groupEvePerson->getId();
                         $persons = array_key_exists($personKey, $personDict) ? $personDict[$personKey] : array();
                         $personByUserId = array();
                         foreach ($persons as $person) {
                             $personById[$person->getUserId()];
                         }
                         foreach ($userIds as $userId) {
                             if (!array_key_exists($userId, $personByUserId)) {
                                 $groupPersonEntity = new ECP\GroupPerson();
                                 $groupPersonEntity->setGroup($group);
                                 $groupPersonEntity->setGroupPersonTypeId($groupEvePerson->getGroupPersonTypeId());
                                 $groupPersonEntity->setGroupEvePersonId($groupEvePerson->getId());
                                 $groupPersonEntity->setUserId($userId);
                                 $this->prepareSubentitySave2($connection, $group, 'GroupPerson', $groupPersonEntity, true);
                             }
                         }
                         foreach ($persons as $groupPersonEntity) {
                             if (!in_array($groupPersonEntity->getUserId(), $userIds)) {
                                 $group->removeGroupPerson($groupPersonEntity);
                             }
                         }
                     }
                     $group->save($connection);
                     $connection->commit();
                 } catch (Exception $e) {
                     $connection->rollBack();
                     throw $e;
                 }
             }
         }
         sleep(30);
     }
 }