Changeset 4833 for trunk


Ignore:
Timestamp:
Feb 3, 2010, 10:26:32 AM (15 years ago)
Author:
nikrou
Message:

Feature 511 : fix problems with calendar functions
add pwg_db_concat() function

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/include/functions.php

    r4731 r4833  
    949949    $query = '
    950950UPDATE '.IMAGES_TABLE.'
    951   SET path = CONCAT(\''.$fulldirs[$cat_id].'\',\'/\',file)
     951  SET path = '.pwg_db_concat(array($fulldirs[$cat_id],'\'/\'','file')).'
    952952  WHERE storage_category_id = '.$cat_id.'
    953953;';
  • trunk/admin/include/functions_permalinks.php

    r4325 r4833  
    193193UPDATE '.CATEGORIES_TABLE.'
    194194  SET permalink="'.$permalink.'"
    195   WHERE id='.$cat_id.'
    196   LIMIT 1';
     195  WHERE id='.$cat_id;
     196  //  LIMIT 1';
    197197  pwg_query($query);
    198198
  • trunk/admin/permalinks.php

    r4325 r4833  
    110110SELECT
    111111  id,
    112   CONCAT(id, " - ", name, IF(permalink IS NULL, "", " √") ) AS name,
     112  '.pwg_db_concat(array('id', '\' - \'', 'name', 'IF(permalink IS NULL, \'\', \' √\')')).' AS name,
    113113  uppercats, global_rank
    114114FROM '.CATEGORIES_TABLE;
  • trunk/include/calendar_base.class.php

    r4781 r4833  
    221221
    222222    $level_items = simple_hash_from_query($query, 'period', 'nb_images');
     223    $level_items = array_to_int($level_items);
    223224
    224225    if ( count($level_items)==1 and
     
    292293    $current = implode('-', $page['chronology_date'] );
    293294    $upper_items = array_from_query( $query, 'period');
    294 
    295     usort($upper_items, 'date_compare');
     295    $upper_items = array_to_int($upper_items);
     296
     297    usort($upper_items, 'version_compare');
    296298    $upper_items_rank = array_flip($upper_items);
    297299    if ( !isset($upper_items_rank[$current]) )
    298300    {
    299301      array_push($upper_items, $current);// just in case (external link)
    300       usort($upper_items, 'date_compare');
     302      usort($upper_items, 'version_compare');
    301303      $upper_items_rank = array_flip($upper_items);
    302304    }
  • trunk/include/dblayer/functions_mysql.inc.php

    r4781 r4833  
    459459}
    460460
     461function pwg_db_concat($array)
     462{
     463  $string = implode($array, ',');
     464  return 'CONCAT('. $string.')';
     465}
     466
    461467function pwg_db_concat_ws($array, $separator)
    462468{
  • trunk/include/dblayer/functions_pgsql.inc.php

    r4781 r4833  
    393393}
    394394
     395function pwg_db_concat($array)
     396{
     397  $string = implode($array, ',');
     398  return 'ARRAY_TO_STRING(ARRAY['.$string.'])';
     399}
     400
    395401function pwg_db_concat_ws($array, $separator)
    396402{
  • trunk/include/dblayer/functions_sqlite.inc.php

    r4791 r4833  
    5555
    5656  $link->createFunction('now', 'pwg_now', 0);
     57  $link->createFunction('unix_timestamp', 'pwg_unix_timestamp', 0);
    5758  $link->createFunction('md5', 'md5', 1);
     59  $link->createFunction('if', 'pwg_if', 3);
    5860
    5961  $link->createAggregate('std', 'pwg_std_step', 'pwg_std_finalize');
     
    402404}
    403405
     406function pwg_db_concat($array)
     407{
     408  return implode($array, ' || ');
     409}
     410
    404411function pwg_db_concat_ws($array, $separator)
    405412{
     
    469476  }
    470477
    471   return 'date('.$date.',\''.$period.' DAY\')';
     478  return 'date('.$date.',\''.-$period.' DAY\')';
    472479}
    473480
     
    512519function pwg_db_get_dayofweek($date)
    513520{
    514   return 'strftime(\'%w\','.$date.')+1';
     521  return 'strftime(\'%w\','.$date.')';
    515522}
    516523
    517524function pwg_db_get_weekday($date)
    518525{
    519   return 'strftime(\'%w\','.$date.')';
     526  return 'strftime(\'%w\',date('.$date.',\'-1 DAY\'))';
    520527}
    521528
     
    548555  return date('Y-m-d H:i:s');
    549556}
     557
     558function pwg_unix_timestamp()
     559{
     560  return time();
     561}
     562
     563function pwg_if($expression, $value1, $value2)
     564{
     565  if ($expression)
     566  {
     567    return $value1;
     568  }
     569  else
     570  {
     571    return $value2;
     572  }
     573}
    550574
    551575function pwg_regexp($pattern, $string)
  • trunk/include/functions_calendar.inc.php

    r4781 r4833  
    291291}
    292292
    293 /*
    294  * callback to sort array with date comparaison
    295  *
    296  **/
    297 function date_compare(&$a, &$b)
     293function array_to_int($array)
    298294{
    299   $parts = explode('-', $a);
    300   foreach ($parts as &$p) {
    301     $p = (int)$p;
    302   }
    303   $a = implode('-', $parts);
    304   $parts = explode('-', $b);
    305   foreach ($parts as &$p) {
    306     $p = (int)$p;
    307   }
    308   $b = implode('-', $parts);
    309 
    310   return strcmp($a, $b);
     295  foreach ($array as $k => $v)
     296  {
     297    if ((int)$k==$k)
     298    {
     299      $key = (int) $k;
     300    }
     301    else
     302    {
     303      $key = $k;
     304    }
     305    if (is_array($v))
     306    {
     307      $result[$key] = array_to_int($v);
     308    }
     309    else
     310    {
     311      if (is_int($v))
     312      {
     313        $value = (int) $v;
     314      }
     315      else
     316      {
     317        $value = $v;
     318      }
     319      $result[$key] = $value;
     320    }
     321  }
     322  return $result;
    311323}
    312324?>
Note: See TracChangeset for help on using the changeset viewer.