public function getObjectQuery($id)
 {
     return CategoryQuery::create()->findPk($id);
 }
Ejemplo n.º 2
0
 /**
  * Returns the number of related Category objects.
  *
  * @param      Criteria $criteria
  * @param      boolean $distinct
  * @param      PropelPDO $con
  * @return     int Count of related Category objects.
  * @throws     PropelException
  */
 public function countCategorys(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
 {
     if (null === $this->collCategorys || null !== $criteria) {
         if ($this->isNew() && null === $this->collCategorys) {
             return 0;
         } else {
             $query = CategoryQuery::create(null, $criteria);
             if ($distinct) {
                 $query->distinct();
             }
             return $query->filterByUser($this)->count($con);
         }
     } else {
         return count($this->collCategorys);
     }
 }
Ejemplo n.º 3
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();
Ejemplo n.º 4
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);
}
Ejemplo n.º 5
0
 /**
  * Get the associated Category object
  *
  * @param      PropelPDO Optional Connection object.
  * @return     Category The associated Category object.
  * @throws     PropelException
  */
 public function getCategory(PropelPDO $con = null)
 {
     if ($this->aCategory === null && $this->category_id !== null) {
         $this->aCategory = CategoryQuery::create()->findPk($this->category_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->aCategory->addPosts($this);
         		 */
     }
     return $this->aCategory;
 }
 /**
  * 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(CategoryPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = CategoryQuery::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;
     }
 }
 /**
  * Returns a new CategoryQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param     Criteria $criteria Optional Criteria to build the query from
  *
  * @return    CategoryQuery
  */
 public static function create($modelAlias = null, $criteria = null)
 {
     if ($criteria instanceof CategoryQuery) {
         return $criteria;
     }
     $query = new CategoryQuery();
     if (null !== $modelAlias) {
         $query->setModelAlias($modelAlias);
     }
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }