Exemplo n.º 1
0
		public static function add($name, $isVeg, $isAll, $side)
		{
			global $db;
			$ing = Ingredient::getByName($name);
			if( $ing )
			{
				return $ing;
			}
			else
			{
				$ing = new Ingredient(null, $name, $isVeg, $isAll, $side);
				return $ing->save();
			}
		}
Exemplo n.º 2
0
	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;
	}
Exemplo n.º 3
0
	require_once('Session.php');
	setSession(0, '/');
	
	$name = isset($_POST['name']) ? $_POST['name'] : null;
	$veg = isset($_POST['veg']) ? true : false;
	$all = isset($_POST['all']) ? true : false;
	$side = isset($_POST['side']) ? true : false;
	
	if( !isset($_SESSION['userid']) || $_SESSION['userid'] == null || $_SESSION['userid'] < 1 )
	{
		throw new RedirectBrowserException("../login.php?code=10");
	}
	
	if( $name != null )
	{
		if( Ingredient::getByName($name) )
		{
			print jsonify(false, "This ingredient already exists", $name);
		}
		else
		{
			if( Ingredient::add($name, $veg, $all, $side) )
			{
				print jsonify(true, "The ingredient was added successfully", $name);
			}
			else
			{
				print jsonify(false, "The ingredient could not be added", $name);
			}
		}
	}