Example #1
0
 /**
  * Add new category
  *
  *    $data = array(
  *        'name'   => 'category name',
  *        'desc'   => 'category description',
  *        'parent' => 'category parent id'
  *        );
  *
  * @param array
  * @return mixed ID of the category or PEAR error object
  */
 static function add($data)
 {
     global $dbh;
     if (empty($data['name'])) {
         throw new InvalidArgumentException('no name given');
     }
     $name = $data['name'];
     $desc = empty($data['desc']) ? 'none' : $data['desc'];
     $parent = empty($data['parent']) ? null : $data['parent'];
     $sql = 'INSERT INTO categories (id, name, description, parent) VALUES (?, ?, ?, ?)';
     $id = $dbh->nextId('categories');
     $err = $dbh->query($sql, array($id, $name, $desc, $parent));
     if (DB::isError($err)) {
         return $err;
     }
     $err = renumber_visitations($id, $parent);
     if (PEAR::isError($err)) {
         return $err;
     }
     include_once 'pear-rest.php';
     $pear_rest = new pearweb_Channel_REST_Generator(PEAR_REST_PATH, $dbh);
     $pear_rest->saveCategoryREST($name);
     $pear_rest->saveAllCategoriesREST();
     $pear_rest->savePackagesCategoryREST($name);
     return $id;
 }
Example #2
0
 /**
  * Add new category
  *
  *    $data = array(
  *        'name'   => 'category name',
  *        'desc'   => 'category description',
  *        'parent' => 'category parent id'
  *        );
  *
  * @param array
  * @return mixed ID of the category or PEAR error object
  */
 function add($data)
 {
     global $dbh;
     $name = $data['name'];
     if (empty($name)) {
         return PEAR::raiseError('no name given');
     }
     $desc = empty($data['desc']) ? 'none' : $data['desc'];
     $parent = empty($data['parent']) ? null : $data['parent'];
     $sql = 'INSERT INTO categories (id, name, description, parent)' . 'VALUES (?, ?, ?, ?)';
     $id = $dbh->nextId('categories');
     $err = $dbh->query($sql, array($id, $name, $desc, $parent));
     if (DB::isError($err)) {
         return $err;
     }
     $err = renumber_visitations($id, $parent);
     if (PEAR::isError($err)) {
         return $err;
     }
     $GLOBALS['pear_rest']->saveCategoryREST($name);
     $GLOBALS['pear_rest']->saveAllCategoriesREST();
     return $id;
 }
Example #3
0
<?php

/*
   +----------------------------------------------------------------------+
   | PEAR Web site version 1.0                                            |
   +----------------------------------------------------------------------+
   | Copyright (c) 2001-2003 The PHP Group                                |
   +----------------------------------------------------------------------+
   | This source file is subject to version 2.02 of the PHP license,      |
   | that is bundled with this package in the file LICENSE, and is        |
   | available at through the world-wide-web at                           |
   | http://www.php.net/license/2_02.txt.                                 |
   | If you did not receive a copy of the PHP license and are unable to   |
   | obtain it through the world-wide-web, please send a note to          |
   | license@php.net so we can mail you a copy immediately.               |
   +----------------------------------------------------------------------+
   | Authors:                                                             |
   +----------------------------------------------------------------------+
   $Id$
*/
require_once "pear-config.php";
require_once "pear-debug.php";
require_once "pear-database.php";
$dbh = DB::connect(PEAR_DATABASE_DSN, array('persistent' => true));
renumber_visitations(true);