Ignore:
Timestamp:
Feb 4, 2014, 4:13:30 PM (10 years ago)
Author:
JanisV
Message:

Set thumbnails for new virtual albums
Make physical albums private
Processing folder structure

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/physical2virtual/main.inc.php

    r27147 r27164  
    3030}
    3131
     32function find_or_create_virtual_category($category_name, $parent_id=null, $options=array())
     33{
     34  if (!is_null($parent_id))
     35  {
     36    $sub_ids = get_subcat_ids(array($parent_id));
     37    foreach ($sub_ids as $id)
     38    {
     39      $cat_info = get_cat_info($id);
     40      if ($cat_info['name'] == $category_name and !$cat_info['dir'])
     41        return $cat_info;
     42    }
     43  }
     44
     45  return create_virtual_category($category_name, $parent_id, $options);
     46}
     47
    3248function physical2virtual_convert()
    3349{
     
    3551
    3652  $query = '
    37     SELECT name
    38     FROM '.CATEGORIES_TABLE.'
    39     WHERE dir IS NULL
    40   ;';  // get virtual
    41   $virt_cats = array_from_query($query, 'name');
    42  
    43   $query = '
    44     SELECT id, name
     53    SELECT id, name, id_uppercat
    4554    FROM '.CATEGORIES_TABLE.'
    4655    WHERE dir IS NOT NULL
     
    5059  {
    5160    $virt_name = $row['name'];
    52     $created = false;
    53     if (!in_array($virt_name, $virt_cats))
     61
     62    $parent = isset($conf['physical2virtual']['parent_cat']) ? $conf['physical2virtual']['parent_cat'] : null;
     63       
     64    if ($conf['physical2virtual']['store_structure'])
    5465    {
    55       $parent = isset($conf['physical2virtual']['parent_cat']) ? $conf['physical2virtual']['parent_cat'] : null;
    56       $virt_id = create_virtual_category($virt_name, $parent)['id'];
    57       $created = true;
    58 
    59       if (isset($conf['physical2virtual']['lock_physical']) and $conf['physical2virtual']['lock_physical'])
     66      // get array of physical parents
     67      $cat_info = get_cat_info($row['id']);
     68      $uppers = $cat_info['upper_names'];
     69      array_pop($uppers); // remove themself
     70     
     71      foreach ($uppers as $upper)
    6072      {
    61         $cat_info = get_cat_info($row['id']);
    62         if ($cat_info['visible'] == true)
    63         {
    64           set_cat_visible(array($row['id']), false);
    65         }
    66       }
    67       if (isset($conf['physical2virtual']['private_physical']) and $conf['physical2virtual']['private_physical'])
    68       {
    69         set_cat_status(array($row['id']), 'private');
     73        $parent = find_or_create_virtual_category($upper['name'], $parent)['id'];
    7074      }
    7175    }
    72     else
     76
     77    $virt_cat = find_or_create_virtual_category($virt_name, $parent);
     78//    $virt_cat = create_virtual_category($virt_name, $parent)['id']; // use this for duplicate folders name
     79
     80    if (isset($conf['physical2virtual']['lock_physical']) and $conf['physical2virtual']['lock_physical'])
    7381    {
    74       // Get existen virt category ID
    75       $query = '
    76         SELECT id FROM '.CATEGORIES_TABLE.' WHERE dir IS NULL AND name = \''.pwg_db_real_escape_string($virt_name).'\'
    77       ;';
    78       list($virt_id) = pwg_db_fetch_row(pwg_query($query));
     82      $cat_info = get_cat_info($row['id']);
     83      if ($cat_info['visible'] == true)
     84      {
     85        set_cat_visible(array($row['id']), false);
     86      }
     87    }
     88    if (isset($conf['physical2virtual']['private_physical']) and $conf['physical2virtual']['private_physical'])
     89    {
     90      set_cat_status(array($row['id']), 'private');
    7991    }
    8092
    8193    $query = '
    8294      INSERT IGNORE INTO '.IMAGE_CATEGORY_TABLE.' (category_id, image_id)
    83         SELECT '.$virt_id.', image_id FROM '.IMAGE_CATEGORY_TABLE.' WHERE category_id = '.$row['id'].'
     95        SELECT '.$virt_cat['id'].', image_id FROM '.IMAGE_CATEGORY_TABLE.' WHERE category_id = '.$row['id'].'
    8496    ;';
    8597    pwg_query($query);
    8698
    87     if ($created)
     99    if (!(isset($virt_cat['representative_picture_id']) and $virt_cat['representative_picture_id']))
    88100    {
    89       set_random_representant(array($virt_id));
     101      set_random_representant(array($virt_cat['id']));
    90102    }
    91103  }
Note: See TracChangeset for help on using the changeset viewer.