[ PHPXref.com ] [ Generated: Sun Jul 20 21:17:54 2008 ] [ Zoph 0.5.1 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/php/ -> category.inc.php (source)

   1  <?php
   2  
   3  /*
   4   * A category class corresponding to the category table.
   5   *
   6   * This file is part of Zoph.
   7   *
   8   * Zoph is free software; you can redistribute it and/or modify
   9   * it under the terms of the GNU General Public License as published by
  10   * the Free Software Foundation; either version 2 of the License, or
  11   * (at your option) any later version.
  12   * 
  13   * Zoph is distributed in the hope that it will be useful,
  14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16   * GNU General Public License for more details.
  17   * You should have received a copy of the GNU General Public License
  18   * along with Zoph; if not, write to the Free Software
  19   * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  20   */
  21  
  22  class category extends zoph_tree_table {
  23  
  24      var $photo_count;
  25  
  26      function category($id = 0) {
  27          parent::zoph_table("categories", array("category_id"), array("category"));
  28          $this->set("category_id", $id);
  29      }
  30  
  31      function delete() {
  32          parent::delete(array("photo_categories"));
  33      }
  34  
  35      function get_children() {
  36          return parent::get_children(null, "category");
  37      }
  38  
  39      function get_branch_ids($user = null) {
  40          return parent::get_branch_ids("category", $user);
  41      }
  42  
  43      function get_photo_count($user) {
  44  
  45          if ($this->photo_count) { return $photo_count; }
  46  
  47          $id = $this->get("category_id");
  48  
  49          if ($user && !$user->is_admin()) {
  50              $sql =
  51                  "select count(distinct pc.photo_id) from " .
  52                  DB_PREFIX . "photo_categories as pc, " .
  53                  DB_PREFIX . "photo_albums as pa, " .
  54                  DB_PREFIX . "photos as p, " .
  55                  DB_PREFIX . "album_permissions as ap " .
  56                  "where pc.category_id = '" .  escape_string($id) . "'" .
  57                  " and ap.user_id = '" . escape_string($user->get("user_id")) . "'" .
  58                  " and pc.photo_id = pa.photo_id" .
  59                  " and pa.album_id = ap.album_id" .
  60                  " and pa.photo_id = p.photo_id" .
  61                  " and ap.access_level >= p.level";
  62          }
  63          else {
  64              $sql =
  65                  "select count(photo_id) from " .
  66                  DB_PREFIX . "photo_categories " .
  67                  "where category_id = '" .  escape_string($id) . "'";
  68          }
  69  
  70          return get_count_from_query($sql);
  71      }
  72  
  73      function get_total_photo_count($user = null) {
  74          if ($this->get("parent_category_id")) {
  75              $id_list = $this->get_branch_ids($user);
  76              $id_constraint = "pc.category_id in ($id_list)";
  77          }
  78          else {
  79              $id_constraint = "";
  80          }
  81  
  82  
  83          if ($user && !$user->is_admin()) {
  84              $sql =
  85                  "select count(distinct pc.photo_id) from " .
  86                  DB_PREFIX . "photo_categories as pc, " .
  87                  DB_PREFIX . "photo_albums as pa, " .
  88                  DB_PREFIX . "photos as p, " .
  89                  DB_PREFIX . "album_permissions as ap " .
  90                  "where ap.user_id = '" . escape_string($user->get("user_id")) . "'" .
  91                  " and pc.photo_id = pa.photo_id" .
  92                  " and pa.album_id = ap.album_id" .
  93                  " and pa.photo_id = p.photo_id" .
  94                  " and ap.access_level >= p.level";
  95  
  96              if ($id_constraint) {
  97                  $sql .= " and $id_constraint";
  98              }
  99          }
 100          else {
 101              $sql =
 102                  "select count(distinct pc.photo_id) from " .
 103                  DB_PREFIX . "photo_categories as pc";
 104  
 105              if ($id_constraint) {
 106                  $sql .= " where $id_constraint";
 107              }
 108          }
 109  
 110          return get_count_from_query($sql);
 111      }
 112  
 113      function get_edit_array() {
 114          return array(
 115              translate("category name") =>
 116                  create_text_input("category", $this->get("category")),
 117              translate("parent category") =>
 118                  create_pulldown("parent_category_id",
 119                      $this->get("parent_category_id"),
 120                      get_categories_select_array()),
 121              translate("category description") =>
 122                  create_text_input("category_description",
 123                      $this->get("category_description"), 40, 128));
 124      }
 125  
 126      function get_link() {
 127          if ($this->get("parent_category_id")) {
 128              $name = $this->get("category");
 129          }
 130          else {
 131              $name = translate("Categories");
 132          }
 133          return "<a href=\"categories.php?parent_category_id=" . $this->get("category_id") . "\">$name</a>";
 134      }
 135  
 136  }
 137  
 138  function get_root_category() {
 139      return new category(1);
 140  }
 141  
 142  function get_categories_select_array($user = null, $search = 0) {
 143      return create_tree_select_array("category", $user, null, "", null, $search);
 144  }
 145  
 146  function get_categories_search_array($user = null) {
 147      return get_categories_select_array($user, 1);
 148  }
 149  
 150  function get_popular_categories($user) {
 151  
 152      global $TOP_N;
 153  
 154      if ($user && !$user->is_admin()) {
 155          $sql =
 156              "select cat.*, count(distinct ph.photo_id) as count from " .
 157              DB_PREFIX . "categories as cat, " .
 158              DB_PREFIX . "photo_categories as pc, " .
 159              DB_PREFIX . "photos as ph, " .
 160              DB_PREFIX . "photo_albums as pa, " .
 161              DB_PREFIX . "album_permissions as ap " .
 162              "where ap.user_id = '" . escape_string($user->get("user_id")) . "'" .
 163              " and ap.album_id = pa.album_id" .
 164              " and pa.photo_id = pc.photo_id" .
 165              " and pc.category_id = cat.category_id" .
 166              " and pc.photo_id = ph.photo_id" .
 167              " and ap.access_level >= ph.level " .
 168              "group by cat.category_id " .
 169              "order by count desc, cat.category " .
 170              "limit 0, $TOP_N";
 171      }
 172      else {
 173          $sql =
 174              "select cat.*, count(*) as count from " .
 175              DB_PREFIX . "categories as cat, " .
 176              DB_PREFIX . "photo_categories as pc " .
 177              "where pc.category_id = cat.category_id " .
 178              "group by cat.category_id " .
 179              "order by count desc, cat.category " .
 180              "limit 0, $TOP_N";
 181      }
 182  
 183      return get_popular_results("category", $sql);
 184  
 185  }
 186  
 187  ?>


[ Powered by PHPXref - Served by Debian GNU/Linux ]