Example #1
0
 public static function updateCounts()
 {
     $cats = new self();
     foreach ($cats->simpleSelect() as $cat) {
         $nb = Collection::Query(PostsModel::TABLE)->whereEq(PostsModel::CATEGORY_ID, $cat->getId())->getCount();
         $cat->set(self::POST_COUNT, $nb);
         $cat->save();
     }
 }
Example #2
0
 public static function fromPost($id)
 {
     $col = Collection::Query(self::TABLE)->Select(self::USERNAME, self::CONTENT, self::CREATED, self::MAIL)->WhereEq(self::POST_ID, $id)->orderByDesc(self::CREATED);
     $list = array();
     foreach ($col->getValues(isset($_GET["p"]) ? intval($_GET["p"]) : 0) as $row) {
         $row["gid"] = md5($row["mail"]);
         unset($row["mail"]);
         $list[] = $row;
     }
     return $list;
 }
Example #3
0
 protected function get_user_list($r)
 {
     Input::ensureRequest($r, array("id"));
     $id = $r["id"];
     $cats = new UsersModel();
     $cat = $cats->getBy(UsersModel::USERNAME, $id);
     $col = Collection::Query($this->model->getTableName())->SelectAs($this->model->getField($this->model->getPrimaryField())->getFullName(), self::ID)->leftJoin(CategoriesModel::TABLE, CategoriesModel::TABLE . "." . CategoriesModel::ID . "=" . PostsModel::TABLE . "." . PostsModel::CATEGORY_ID)->SelectAs(CategoriesModel::TABLE . "." . CategoriesModel::NAME, "catname")->SelectAs(CategoriesModel::TABLE . "." . CategoriesModel::SLUG, "catslug")->leftJoin(UsersModel::TABLE, UsersModel::TABLE . "." . UsersModel::ID . "=" . PostsModel::TABLE . "." . PostsModel::USER_ID)->orderByDesc(PostsModel::CREATED)->SelectAs(UsersModel::TABLE . "." . UsersModel::USERNAME, "username")->whereEq(PostsModel::USER_ID, $cat->get("id"))->limit($this->options["limit"]);
     $this->filterList($col);
     if (isset($_GET["q"]) && strlen($_GET["q"]) > 0) {
         $col->filter($_GET["q"]);
     }
     $list = array();
     foreach ($col->getValues(isset($_GET["p"]) ? intval($_GET["p"]) : 0) as $row) {
         $list[] = $this->list_values($row);
     }
     Output::success(array("list" => $list));
 }