public function executeNavigation() { $this->person = $this->getUser()->getPerson(); $activityId = $this->getUser()->getAttribute('activityId'); if ($this->getUser()->hasActivity($activityId)) { $this->activity = ActivityPeer::retrieveByPk($activityId); } else { $this->activity = null; } $this->usergroup = UsergroupPeer::retrieveByPk($this->getUser()->getAttribute('usergroupId')); $this->user = UserPeer::retrieveByPk($this->getUser()->getAttribute('userId')); }
protected function getUserAttributes() { if ($this->getUser()->hasAttribute('userId')) { $this->forward404Unless($this->usergroup = UsergroupPeer::retrieveByPk($this->getUser()->getAttribute('usergroupId')), sprintf('Object usergroup does not exist (%s).', $this->getUser()->getAttribute('usergroupId'))); $this->forward404Unless($this->user = UserPeer::retrieveByPk($this->getUser()->getAttribute('userId')), sprintf('Object user does not exist (%s).', $this->getUser()->getAttribute('userId'))); $this->forward404Unless($this->user->isMember($this->usergroup), 'The user is not member of the specified usergroup.'); $this->forward404Unless($this->getUser()->getTemposUser()->isLeader($this->usergroup), 'The logged user is not leader of the specified usergroup.'); $this->person = $this->user; return true; } else { $this->forward404Unless($this->person = $this->getUser()->getPerson(), 'No user or card logged-in.'); return false; } }
public function executeUsergroupCreate(sfWebRequest $request) { $this->forward404Unless($request->isMethod('post')); if ($request->hasParameter('usergroupId')) { $this->forward404Unless($this->usergroup = UsergroupPeer::retrieveByPk($request->getParameter('usergroupId')), sprintf('Object usergroup does not exist (%s).', $request->getParameter('usergroupId'))); $this->form = new UsergroupSubscriptionForm(); $this->form->setDefaultUsergroup($this->usergroup); $this->form->bind($request->getParameter($this->form->getName()), $request->getFiles($this->form->getName())); if ($this->form->isValid()) { $this->form->save(); $this->redirect('usergroup/index'); } } else { $this->forward404('No usergroup specified.'); } $this->setTemplate('usergroupNew'); }
/** * Retrieve multiple objects by pkey. * * @param array $pks List of primary keys * @param PropelPDO $con the connection to use * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function retrieveByPKs($pks, PropelPDO $con = null) { if ($con === null) { $con = Propel::getConnection(UsergroupPeer::DATABASE_NAME, Propel::CONNECTION_READ); } $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(UsergroupPeer::DATABASE_NAME); $criteria->add(UsergroupPeer::ID, $pks, Criteria::IN); $objs = UsergroupPeer::doSelect($criteria, $con); } return $objs; }
/** * Selects a collection of UsergroupHasUser objects pre-filled with all related objects except User. * * @param Criteria $c * @param PropelPDO $con * @param String $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN * @return array Array of UsergroupHasUser objects. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doSelectJoinAllExceptUser(Criteria $c, $con = null, $join_behavior = Criteria::LEFT_JOIN) { $c = clone $c; // Set the correct dbName if it has not been overridden // $c->getDbName() will return the same object if not set to another value // so == check is okay and faster if ($c->getDbName() == Propel::getDefaultDB()) { $c->setDbName(self::DATABASE_NAME); } UsergroupHasUserPeer::addSelectColumns($c); $startcol2 = UsergroupHasUserPeer::NUM_COLUMNS - UsergroupHasUserPeer::NUM_LAZY_LOAD_COLUMNS; UsergroupPeer::addSelectColumns($c); $startcol3 = $startcol2 + (UsergroupPeer::NUM_COLUMNS - UsergroupPeer::NUM_LAZY_LOAD_COLUMNS); $c->addJoin(array(UsergroupHasUserPeer::USERGROUP_ID), array(UsergroupPeer::ID), $join_behavior); $stmt = BasePeer::doSelect($c, $con); $results = array(); while ($row = $stmt->fetch(PDO::FETCH_NUM)) { $key1 = UsergroupHasUserPeer::getPrimaryKeyHashFromRow($row, 0); if (null !== ($obj1 = UsergroupHasUserPeer::getInstanceFromPool($key1))) { // We no longer rehydrate the object, since this can cause data loss. // See http://propel.phpdb.org/trac/ticket/509 // $obj1->hydrate($row, 0, true); // rehydrate } else { $omClass = UsergroupHasUserPeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj1 = new $cls(); $obj1->hydrate($row); UsergroupHasUserPeer::addInstanceToPool($obj1, $key1); } // if obj1 already loaded // Add objects for joined Usergroup rows $key2 = UsergroupPeer::getPrimaryKeyHashFromRow($row, $startcol2); if ($key2 !== null) { $obj2 = UsergroupPeer::getInstanceFromPool($key2); if (!$obj2) { $omClass = UsergroupPeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj2 = new $cls(); $obj2->hydrate($row, $startcol2); UsergroupPeer::addInstanceToPool($obj2, $key2); } // if $obj2 already loaded // Add the $obj1 (UsergroupHasUser) to the collection in $obj2 (Usergroup) $obj2->addUsergroupHasUser($obj1); } // if joined row is not null $results[] = $obj1; } $stmt->closeCursor(); return $results; }
/** * Selects a collection of Subscription objects pre-filled with all related objects except User. * * @param Criteria $c * @param PropelPDO $con * @param String $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN * @return array Array of Subscription objects. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doSelectJoinAllExceptUser(Criteria $c, $con = null, $join_behavior = Criteria::LEFT_JOIN) { $c = clone $c; // Set the correct dbName if it has not been overridden // $c->getDbName() will return the same object if not set to another value // so == check is okay and faster if ($c->getDbName() == Propel::getDefaultDB()) { $c->setDbName(self::DATABASE_NAME); } SubscriptionPeer::addSelectColumns($c); $startcol2 = SubscriptionPeer::NUM_COLUMNS - SubscriptionPeer::NUM_LAZY_LOAD_COLUMNS; ActivityPeer::addSelectColumns($c); $startcol3 = $startcol2 + (ActivityPeer::NUM_COLUMNS - ActivityPeer::NUM_LAZY_LOAD_COLUMNS); ZonePeer::addSelectColumns($c); $startcol4 = $startcol3 + (ZonePeer::NUM_COLUMNS - ZonePeer::NUM_LAZY_LOAD_COLUMNS); CardPeer::addSelectColumns($c); $startcol5 = $startcol4 + (CardPeer::NUM_COLUMNS - CardPeer::NUM_LAZY_LOAD_COLUMNS); UsergroupPeer::addSelectColumns($c); $startcol6 = $startcol5 + (UsergroupPeer::NUM_COLUMNS - UsergroupPeer::NUM_LAZY_LOAD_COLUMNS); $c->addJoin(array(SubscriptionPeer::ACTIVITY_ID), array(ActivityPeer::ID), $join_behavior); $c->addJoin(array(SubscriptionPeer::ZONE_ID), array(ZonePeer::ID), $join_behavior); $c->addJoin(array(SubscriptionPeer::CARD_ID), array(CardPeer::ID), $join_behavior); $c->addJoin(array(SubscriptionPeer::USERGROUP_ID), array(UsergroupPeer::ID), $join_behavior); $stmt = BasePeer::doSelect($c, $con); $results = array(); while ($row = $stmt->fetch(PDO::FETCH_NUM)) { $key1 = SubscriptionPeer::getPrimaryKeyHashFromRow($row, 0); if (null !== ($obj1 = SubscriptionPeer::getInstanceFromPool($key1))) { // We no longer rehydrate the object, since this can cause data loss. // See http://propel.phpdb.org/trac/ticket/509 // $obj1->hydrate($row, 0, true); // rehydrate } else { $omClass = SubscriptionPeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj1 = new $cls(); $obj1->hydrate($row); SubscriptionPeer::addInstanceToPool($obj1, $key1); } // if obj1 already loaded // Add objects for joined Activity rows $key2 = ActivityPeer::getPrimaryKeyHashFromRow($row, $startcol2); if ($key2 !== null) { $obj2 = ActivityPeer::getInstanceFromPool($key2); if (!$obj2) { $omClass = ActivityPeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj2 = new $cls(); $obj2->hydrate($row, $startcol2); ActivityPeer::addInstanceToPool($obj2, $key2); } // if $obj2 already loaded // Add the $obj1 (Subscription) to the collection in $obj2 (Activity) $obj2->addSubscription($obj1); } // if joined row is not null // Add objects for joined Zone rows $key3 = ZonePeer::getPrimaryKeyHashFromRow($row, $startcol3); if ($key3 !== null) { $obj3 = ZonePeer::getInstanceFromPool($key3); if (!$obj3) { $omClass = ZonePeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj3 = new $cls(); $obj3->hydrate($row, $startcol3); ZonePeer::addInstanceToPool($obj3, $key3); } // if $obj3 already loaded // Add the $obj1 (Subscription) to the collection in $obj3 (Zone) $obj3->addSubscription($obj1); } // if joined row is not null // Add objects for joined Card rows $key4 = CardPeer::getPrimaryKeyHashFromRow($row, $startcol4); if ($key4 !== null) { $obj4 = CardPeer::getInstanceFromPool($key4); if (!$obj4) { $omClass = CardPeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj4 = new $cls(); $obj4->hydrate($row, $startcol4); CardPeer::addInstanceToPool($obj4, $key4); } // if $obj4 already loaded // Add the $obj1 (Subscription) to the collection in $obj4 (Card) $obj4->addSubscription($obj1); } // if joined row is not null // Add objects for joined Usergroup rows $key5 = UsergroupPeer::getPrimaryKeyHashFromRow($row, $startcol5); if ($key5 !== null) { $obj5 = UsergroupPeer::getInstanceFromPool($key5); if (!$obj5) { $omClass = UsergroupPeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj5 = new $cls(); $obj5->hydrate($row, $startcol5); UsergroupPeer::addInstanceToPool($obj5, $key5); } // if $obj5 already loaded // Add the $obj1 (Subscription) to the collection in $obj5 (Usergroup) $obj5->addSubscription($obj1); } // if joined row is not null $results[] = $obj1; } $stmt->closeCursor(); return $results; }
public function executeDelete(sfWebRequest $request) { $request->checkCSRFProtection(); $this->forward404Unless($usergroup = UsergroupPeer::retrieveByPk($request->getParameter('id')), sprintf('Object usergroup does not exist (%s).', $request->getParameter('id'))); $usergroup->delete(); $this->redirect('usergroup/index'); }
/** * Get the associated Usergroup object * * @param PropelPDO Optional Connection object. * @return Usergroup The associated Usergroup object. * @throws PropelException */ public function getUsergroup(PropelPDO $con = null) { if ($this->aUsergroup === null && $this->usergroup_id !== null) { $c = new Criteria(UsergroupPeer::DATABASE_NAME); $c->add(UsergroupPeer::ID, $this->usergroup_id); $this->aUsergroup = UsergroupPeer::doSelectOne($c, $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->aUsergroup->addUsergroupHasActivitys($this); */ } return $this->aUsergroup; }
/** * Populates the object using an array. * * This is particularly useful when populating an object from one of the * request arrays (e.g. $_POST). This method goes through the column * names, checking to see whether a matching key exists in populated * array. If so the setByName() method is called for that column. * * You can specify the key type of the array by additionally passing one * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. * The default key type is the column's phpname (e.g. 'AuthorId') * * @param array $arr An array to populate the object from. * @param string $keyType The type of keys the array uses. * @return void */ public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME) { $keys = UsergroupPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setName($arr[$keys[1]]); } }
protected function handleZoneParameters(sfWebRequest $request) { if ($request->hasParameter('self')) { $this->getUser()->getAttributeHolder()->remove('userId'); $this->getUser()->getAttributeHolder()->remove('usergroupId'); } $this->forward404Unless($this->activity = ActivityPeer::retrieveByPk($request->getParameter('activityId')), sprintf('Object activity does not exist (%s).', $request->getParameter('activityId'))); if ($this->getUser()->hasAttribute('userId')) { $this->forward404Unless($this->usergroup = UsergroupPeer::retrieveByPk($this->getUser()->getAttribute('usergroupId')), sprintf('Object usergroup does not exist (%s).', $this->getUser()->getAttribute('usergroupId'))); $this->forward404Unless($this->usergroup->hasActivity($this->activity->getId()), sprintf('User group does not have this entry (\'%s\')', $this->activity->getName())); $this->forward404Unless($this->user = UserPeer::retrieveByPk($this->getUser()->getAttribute('userId')), sprintf('Object user does not exist (%s).', $this->getUser()->getAttribute('userId'))); $this->forward404Unless($this->user->isMember($this->usergroup), 'The user is not member of the specified usergroup.'); $this->forward404Unless($this->getUser()->getTemposUser()->isLeader($this->usergroup), 'The logged user is not leader of the specified usergroup.'); $this->person = $this->user; } else { $this->forward404Unless($this->person = $this->getUser()->getPerson(), 'No user or card logged-in.'); } $this->forward404Unless($this->person->hasActivity($this->activity->getId()), sprintf('Cannot access entry ("%s").', $this->activity)); $this->getUser()->setAttribute('activityId', $this->activity->getId()); }
public function getGroups() { $c = new Criteria(); $c->addJoin(UsergroupPeer::ID, UsergroupHasUserPeer::USERGROUP_ID); $c->addJoin(UsergroupPeer::ID, UsergroupHasChiefPeer::USERGROUP_ID); $cGroupsAsMember = $c->getNewCriterion(UsergroupHasUserPeer::USER_ID, $this->getId(), Criteria::EQUAL); $cGroupsAsLeader = $c->getNewCriterion(UsergroupHasChiefPeer::USER_ID, $this->getId(), Criteria::EQUAL); $cGroupsAsMember->addOr($cGroupsAsLeader); $c->addGroupByColumn(UsergroupPeer::ID); $c->add($cGroupsAsMember); return UsergroupPeer::doSelect($c); }