Skip to content

Commit

Permalink
db tables vars in object
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-mw committed Feb 3, 2014
1 parent 89c8e2b commit a64676d
Show file tree
Hide file tree
Showing 17 changed files with 5,555 additions and 5,479 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ notifications:

branches:
only:
- master
- master
- dev
3 changes: 1 addition & 2 deletions src/Microweber/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,7 @@ public function __set($property, $value)

public function get($provider, $args = null)
{
// A.k.a call
return $this->call($provider, $args);
return $this->call($provider, $args);
}

public function call($provider, $args = null)
Expand Down
75 changes: 43 additions & 32 deletions src/Microweber/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,11 @@
class Category
{
public $app;
public $tables = array();
public $table_prefix = false;

function __construct($app = null)
{
if (!defined("MW_DB_TABLE_TAXONOMY")) {
define('MW_DB_TABLE_TAXONOMY', MW_TABLE_PREFIX . 'categories');
}

if (!defined("MW_DB_TABLE_TAXONOMY_ITEMS")) {
define('MW_DB_TABLE_TAXONOMY_ITEMS', MW_TABLE_PREFIX . 'categories_items');
}


if (!is_object($this->app)) {
Expand All @@ -34,7 +29,21 @@ function __construct($app = null)

}

$prefix = $this->app->config('table_prefix');
$this->tables = $this->app->content->tables;
if (!isset($this->tables['categories'])) {
$this->tables['categories'] = $prefix . 'categories';
}
if (!isset($this->tables['categories_items'])) {
$this->tables['categories_items'] = $prefix . 'categories_items';
}
if (!defined("MW_DB_TABLE_TAXONOMY")) {
define('MW_DB_TABLE_TAXONOMY', $this->tables['categories']);
}

if (!defined("MW_DB_TABLE_TAXONOMY_ITEMS")) {
define('MW_DB_TABLE_TAXONOMY_ITEMS', $this->tables['categories_items']);
}
}

/**
Expand Down Expand Up @@ -200,7 +209,7 @@ public function tree($params = false)
$orderby = false;
}

$table = MW_DB_TABLE_TAXONOMY;
$table = $this->tables['categories'];
if (isset($params['content_id'])) {
$params['for_page'] = $params['content_id'];

Expand Down Expand Up @@ -319,9 +328,9 @@ public function tree($params = false)
public function html_tree($parent, $link = false, $active_ids = false, $active_code = false, $remove_ids = false, $removed_ids_code = false, $ul_class_name = false, $include_first = false, $content_type = false, $li_class_name = false, $add_ids = false, $orderby = false, $only_with_content = false, $visible_on_frontend = false, $depth_level_counter = 0, $max_level = false, $list_tag = false, $list_item_tag = false, $active_code_tag = false)
{

$db_t_content = MW_TABLE_PREFIX . 'content';
$db_t_content = $this->tables['content'];

$table = $db_categories = MW_DB_TABLE_TAXONOMY;
$table = $db_categories = $this->tables['categories'];

if ($parent == false) {

Expand Down Expand Up @@ -700,7 +709,7 @@ public function link($id)

return $cache_content;
} else {
$table = MW_DB_TABLE_TAXONOMY;
$table = $this->tables['categories'];
$c_infp = $this->get_by_id($id);
if (!isset($c_infp['rel'])) {
return;
Expand Down Expand Up @@ -765,8 +774,8 @@ public function link($id)
}
//$this->load->model ( 'Content_model', 'content_model' );

$table = MW_DB_TABLE_TAXONOMY;
$db_t_content = MW_TABLE_PREFIX . 'content';
$table = $this->tables['categories'];
$db_t_content = $this->tables['content'];

$content = array();

Expand Down Expand Up @@ -902,7 +911,7 @@ public function get_parents($id = 0, $without_main_parrent = false, $data_type =
return FALSE;
}

$table = MW_DB_TABLE_TAXONOMY;
$table = $this->tables['categories'];

$ids = array();

Expand Down Expand Up @@ -966,9 +975,9 @@ public function get_children($parent_id = 0, $type = false, $visible_on_frontend
$categories_id = intval($parent_id);
$cache_group = 'categories/' . $categories_id;

$table = MW_DB_TABLE_TAXONOMY;
$table = $this->tables['categories'];

$db_t_content = MW_TABLE_PREFIX . 'content';
$db_t_content = $this->tables['content'];

if (isset($orderby) == false) {
$orderby = array();
Expand Down Expand Up @@ -1077,8 +1086,8 @@ public function get_for_content($content_id, $data_type = 'categories')
return $cache_content;
}

$table = MW_DB_TABLE_TAXONOMY;
$table_items = MW_DB_TABLE_TAXONOMY_ITEMS;
$table = $this->tables['categories'];
$table_items = $this->tables['categories_items'];

$data = array();

Expand Down Expand Up @@ -1123,7 +1132,7 @@ public function get_items($params, $data_type = 'categories')
$params = parse_str($params, $params2);
$params = $options = $params2;
}
$table_items = MW_DB_TABLE_TAXONOMY_ITEMS;
$table_items = $this->tables['categories_items'];
$data = $params;
if ($data_type == 'categories') {
$data['data_type'] = 'category_item';
Expand All @@ -1149,8 +1158,8 @@ public function get($params, $data_type = 'categories')
$rel_id = $params['rel_id'];
}

$table = MW_DB_TABLE_TAXONOMY;
$table_items = MW_DB_TABLE_TAXONOMY_ITEMS;
$table = $this->tables['categories'];
$table_items = $this->tables['categories_items'];

$data = $params;
$data_type_q = false;
Expand All @@ -1173,11 +1182,13 @@ public function save($data, $preserve_cache = false)

$adm = $this->app->user->is_admin();
if ($adm == false) {
mw_error('Ony admin can save category');
if (defined('MW_API_CALL')) {
return array('error' => 'Only admin can save category');
}
}

$table = MW_TABLE_PREFIX . 'categories';
$table_items = MW_TABLE_PREFIX . 'categories_items';
$table = $this->tables['categories'];
$table_items = $this->tables['categories_items'];

$content_ids = false;

Expand Down Expand Up @@ -1213,7 +1224,7 @@ public function save($data, $preserve_cache = false)
$cs = array();
$cs['id'] = intval($data['rel_id']);
$cs['subtype'] = 'dynamic';
$table_c = MW_TABLE_PREFIX . 'content';
$table_c = $this->tables['content'];
$save = $this->app->db->save($table_c, $cs);
}

Expand Down Expand Up @@ -1246,7 +1257,7 @@ public function save($data, $preserve_cache = false)
return false;
}

$custom_field_table = MW_TABLE_PREFIX . 'custom_fields';
$custom_field_table = $this->tables['custom_fields'];

$sid = session_id();

Expand All @@ -1265,7 +1276,7 @@ public function save($data, $preserve_cache = false)
$this->app->db->q($clean);
$this->app->cache->clear('custom_fields');

$media_table = MW_TABLE_PREFIX . 'media';
$media_table = $this->tables['media'];

$clean = " UPDATE $media_table SET
Expand Down Expand Up @@ -1364,7 +1375,7 @@ public function get_by_id($id = 0)
return $cache_content;
}

$table = MW_DB_TABLE_TAXONOMY;
$table = $this->tables['categories'];

$id = intval($id);

Expand All @@ -1390,19 +1401,19 @@ public function delete($data)

$adm = $this->app->user->is_admin();
if ($adm == false) {
mw_error('Error: not logged in as admin.' . __FILE__ . __LINE__);
return false;
}

if (isset($data['id'])) {
$c_id = intval($data['id']);
$this->app->db->delete_by_id('categories', $c_id);
$del = $this->app->db->delete_by_id('categories', $c_id);
$this->app->db->delete_by_id('categories', $c_id, 'parent_id');
$this->app->db->delete_by_id('categories_items', $c_id, 'parent_id');
if (defined("MODULE_DB_MENUS")) {
$this->app->db->delete_by_id('menus', $c_id, 'categories_id');
}


return $del;
}
}

Expand All @@ -1414,7 +1425,7 @@ public function reorder($data)
return array('error' => "You must be logged in as admin to perform: " . __CLASS__ . '->' . __FUNCTION__);
}

$table = MW_TABLE_PREFIX . 'categories';
$table = $this->tables['categories'];
foreach ($data as $value) {
if (is_array($value)) {
$indx = array();
Expand Down
Loading

0 comments on commit a64676d

Please sign in to comment.