public static function add($characteristic) { $char = Characteristic::getByCharacteristic($characteristic); if( !$char ) { $char = new Characteristic(null, $characteristic); return $char->save(); } else { return $char; } }
function replaceName($str, $type) { $itms = array(); foreach( $str as $splt ) { if( $splt != null && $splt != '' ) { array_push($itms, trim($splt)); } } $ints = array(); foreach( $itms as $name ) { switch( $type ) { case 0: $cat = Category::getByName($name); if( $cat instanceof Category ) { array_push($ints, $cat->categoryid); } break; case 1: $ing = Ingredient::getByName($name); if( $ing instanceof Ingredient ) { array_push($ints, $ing->ingredientid); } break; case 2: $char = Characteristic::getByCharacteristic($name); if( $char instanceof Characteristic ) { array_push($ints, $char->characteristicid); } break; default: break; } } return $ints; }
require_once('RedirectBrowserException.php'); require_once('Characteristic.php'); require_once('Session.php'); setSession(0, '/'); $name = isset($_POST['name']) ? $_POST['name'] : null; if( !isset($_SESSION['userid']) || $_SESSION['userid'] == null || $_SESSION['userid'] < 1 ) { throw new RedirectBrowserException("../login.php?code=10"); } if( $name != null ) { if( Characteristic::getByCharacteristic($name) ) { print jsonify(false, "This characteristic already exists", $name); } else { if( Characteristic::add($name) ) { print jsonify(true, "The characteristic was added successfully", $name); } else { print jsonify(false, "The characteristic could not be added", $name); } } }