/**
  * Returns a new UserQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param     Criteria $criteria Optional Criteria to build the query from
  *
  * @return    UserQuery
  */
 public static function create($modelAlias = null, $criteria = null)
 {
     if ($criteria instanceof UserQuery) {
         return $criteria;
     }
     $query = new UserQuery();
     if (null !== $modelAlias) {
         $query->setModelAlias($modelAlias);
     }
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }
Exemplo n.º 2
0
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      PropelPDO $con
  * @return     void
  * @throws     PropelException
  * @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(UserPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = UserQuery::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;
     }
 }
 public function getObjectQuery($id)
 {
     return UserQuery::create()->findPk($id);
 }
Exemplo n.º 4
0
$app['activity_streams.data_resolver_chain']->addDataResolver(new PostResolver());
$app['activity_streams.data_resolver_chain']->addDataResolver(new UserResolver());
$app['activity_streams.action_manager'] = $app->share(function () use($app) {
    return new ActionManager($app['activity_streams.data_resolver_chain']);
});
$app->get('/', function () use($app) {
    $actions = $app['activity_streams.action_manager']->findAll();
    return $app['twig']->render('index.twig', array('actions' => $actions));
});
$app->get('/activities.json', function () use($app) {
    $actions = $app['activity_streams.action_manager']->findAll();
    $renderer = new JsonRenderer();
    $res = array();
    foreach ($actions as $action) {
        $res['items'][] = json_decode($renderer->render($action));
    }
    return json_encode($res);
});
$app->get('/user/{id}', function ($id) use($app) {
    $user = UserQuery::create()->findPk($id);
    return $app['twig']->render('user_show.twig', array('user' => $user));
});
$app->get('/category/{id}', function ($id) use($app) {
    $category = CategoryQuery::create()->findPk($id);
    return $app['twig']->render('category_show.twig', array('category' => $category));
});
$app->get('/post/{id}', function ($id) use($app) {
    $post = PostQuery::create()->findPk($id);
    return $app['twig']->render('post_show.twig', array('post' => $post));
});
$app->run();
Exemplo n.º 5
0
    $user = new User();
    $user->setUsername($username);
    // save user
    $user->save();
    writeln($user);
}
foreach (array('Web', 'Life', 'Open Source', 'PHP') as $value) {
    $category = new Category();
    $category->setName($value);
    $user = UserQuery::create()->findPk(rand(1, 3));
    $category->setUser($user);
    // save category
    $category->save();
    // create action
    $actionManager->createAction($category->getUser(), Category::CREATE_CATEGORY, $category);
    writeln($category);
}
for ($i = 0; $i <= 20; $i++) {
    $post = new Post();
    $post->setTitle('Post title ' . $i);
    $post->setBody('Post body ' . $i);
    $user = UserQuery::create()->findPk(rand(1, 3));
    $post->setUser($user);
    $category = $user = CategoryQuery::create()->findPk(rand(1, 9));
    $post->setCategory($category);
    // create post
    $post->save();
    // create action
    $actionManager->createAction($post->getUser(), Post::CREATE_POST, $post, $post->getCategory());
    writeln($post);
}
Exemplo n.º 6
0
 /**
  * Get the associated User object
  *
  * @param      PropelPDO Optional Connection object.
  * @return     User The associated User object.
  * @throws     PropelException
  */
 public function getUser(PropelPDO $con = null)
 {
     if ($this->aUser === null && $this->user_id !== null) {
         $this->aUser = UserQuery::create()->findPk($this->user_id, $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->aUser->addPosts($this);
         		 */
     }
     return $this->aUser;
 }