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;
 }
Example #2
0
        $category = \Arlo\Categories::get(array('parent_id' => 0), 1, $active);
    }
    if (!$category) {
        return;
    }
    return $category->c_header;
});
// category footer
$shortcodes->add('category_footer', function ($content = '', $atts, $shortcode_name) {
    global $arlo_plugin;
    $active = $arlo_plugin->get_import_id();
    $arlo_category = isset($_GET['arlo-category']) && !empty($_GET['arlo-category']) ? $_GET['arlo-category'] : get_query_var('arlo-category', '');
    if (!empty($arlo_category)) {
        $category = \Arlo\Categories::get(array('id' => current(explode('-', $arlo_category))), 1, $active);
    } else {
        $category = \Arlo\Categories::get(array('parent_id' => 0), 1, $active);
    }
    if (!$category) {
        return;
    }
    return $category->c_footer;
});
//online activity list item shortcode
$shortcodes->add('oa_list_item', function ($content = '', $atts, $shortcode_name) {
    global $post, $wpdb, $arlo_plugin;
    $settings = get_option('arlo_settings');
    $regions = get_option('arlo_regions');
    $active = $arlo_plugin->get_import_id();
    $arlo_region = get_query_var('arlo-region', '');
    $arlo_region = !empty($arlo_region) && array_ikey_exists($arlo_region, $regions) ? $arlo_region : '';
    $t1 = "{$wpdb->prefix}arlo_eventtemplates";