private function import_categories($timestamp) { global $wpdb; $client = $this->get_api_client(); $table_name = "{$wpdb->prefix}arlo_categories"; self::add_log('API Call started: Categories', $timestamp); $items = $client->Categories()->getAllCategories(array('CategoryID', 'ParentCategoryID', 'Name', 'SequenceIndex', 'Description', 'Footer')); self::add_log('API Call finished: Categories', $timestamp); self::add_log('Data process start: ' . __FUNCTION__, $timestamp); if (!empty($items)) { foreach ($items as $item) { $slug = sanitize_title($item->CategoryID . ' ' . $item->Name); $query = $wpdb->query($wpdb->prepare("INSERT INTO {$table_name} \n\t\t\t\t\t(c_arlo_id, c_name, c_slug, c_header, c_footer, c_order, c_parent_id, active) \n\t\t\t\t\tVALUES ( %d, %s, %s, %s, %s, %d, %d, %s ) \n\t\t\t\t\t", $item->CategoryID, $item->Name, $slug, @$item->Description->Text, @$item->Footer->Text, @$item->SequenceIndex, @$item->ParentCategoryID, $timestamp)); if ($query === false) { self::add_log('SQL error: ' . $wpdb->last_error . ' ' . $wpdb->last_query, $timestamp); throw new Exception('Database insert failed: ' . $table_name); } } } $this->import_eventtemplatescategoriesitems($timestamp); //count the templates in the categories $sql = "\n\t\tSELECT\n\t\t\tCOUNT(1) AS num, \n\t\t\tc_arlo_id\n\t\tFROM\n\t\t\t{$wpdb->prefix}arlo_eventtemplates_categories\n\t\tWHERE\n\t\t\tactive = {$timestamp}\n\t\tGROUP BY\n\t\t\tc_arlo_id\n\t\t"; $items = $wpdb->get_results($sql, ARRAY_A); if (!is_null($items)) { foreach ($items as $counts) { $sql = "\n\t\t\t\tUPDATE\n\t\t\t\t\t{$wpdb->prefix}arlo_categories\n\t\t\t\tSET\n\t\t\t\t\tc_template_num = %d\n\t\t\t\tWHERE\n\t\t\t\t\tc_arlo_id = %d\n\t\t\t\tAND\n\t\t\t\t\tactive = {$timestamp}\n\t\t\t\t"; $query = $wpdb->query($wpdb->prepare($sql, $counts['num'], $counts['c_arlo_id'])); if ($query === false) { self::add_log('SQL error: ' . $wpdb->last_error . ' ' . $wpdb->last_query, $timestamp); throw new Exception('Database insert failed: ' . $table_name); } } } $cats = \Arlo\Categories::getTree(0, 1000, 0, $timestamp); $this->set_category_depth_level($cats, $timestamp); $sql = "SELECT MAX(c_depth_level) FROM {$wpdb->prefix}arlo_categories WHERE active = {$timestamp}"; $max_depth = $wpdb->get_var($sql); $this->set_category_depth_order($cats, $max_depth, 0, $timestamp); for ($i = $max_depth + 1; $i--; $i < 0) { $sql = "\n\t\t\tSELECT \n\t\t\t\tSUM(c_template_num) as num,\n\t\t\t\tc_parent_id\n\t\t\tFROM\n\t\t\t\t{$wpdb->prefix}arlo_categories\n\t\t\tWHERE\n\t\t\t\tc_depth_level = {$i}\n\t\t\tAND\n\t\t\t\tactive = {$timestamp}\n\t\t\tGROUP BY\n\t\t\t\tc_parent_id\n\t\t\t"; $cats = $wpdb->get_results($sql, ARRAY_A); if (!is_null($cats)) { foreach ($cats as $cat) { $sql = "\n\t\t\t\t\tUPDATE\n\t\t\t\t\t\t{$wpdb->prefix}arlo_categories\n\t\t\t\t\tSET\n\t\t\t\t\t\tc_template_num = c_template_num + %d\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tc_arlo_id = %d\n\t\t\t\t\tAND\n\t\t\t\t\t\tactive = {$timestamp}\n\t\t\t\t\t"; $query = $wpdb->query($wpdb->prepare($sql, $cat['num'], $cat['c_parent_id'])); } } } self::add_log('Data process finished: ' . __FUNCTION__, $timestamp); return $items; }
if ($title) { $conditions = array('id' => $start_at); if ($start_at == 0) { $conditions = array('parent_id' => 0); } $current = \Arlo\Categories::get($conditions, 1, $active); $return .= sprintf($title, $current->c_name); } if ($depth > 0) { if ($start_at == 0) { $root = \Arlo\Categories::getTree($start_at, 1, 0, $active); if (!empty($root)) { $start_at = $root[0]->c_arlo_id; } } $tree = \Arlo\Categories::getTree($start_at, $depth, 0, $active); $GLOBALS['categories_count'] = count($tree); if (!empty($tree)) { $return .= category_ul($tree, $counts); } } return $return; }); // event template duration $shortcodes->add('event_duration', function ($content = '', $atts, $shortcode_name) { global $arlo_plugin; $active = $arlo_plugin->get_import_id(); if (!isset($GLOBALS['arlo_event_list_item']) || empty($GLOBALS['arlo_event_list_item']['et_arlo_id'])) { return; } $conditions = array('template_id' => $GLOBALS['arlo_event_list_item']['et_arlo_id'], 'parent_id' => 0);