public static function create($unitId) { $unit = StructuredUnit::getUnit($unitId); $records = StructuredFieldValueLabel::getSorted($unitId); $rank = 1; if ($records) { $rank = $records[sizeOf($records) - 1][sizeOf(StructuredFieldValueLabel::getStructure()) + 2] + 1; } $query = "INSERT INTO structured_field_value_label (unit_id, label, type, rank) VALUES ({$unitId}, '" . $unit[3] . "', 'text', {$rank});"; $result = mysql_query($query) or die(sqlError(__FILE__, __LINE__, $query)); }
$type = $_POST["type"]; $name = $_POST["name"]; $id = $_POST["id"]; $random = $_POST["random"]; if ($type) { switch ($type) { case 'createUnit': StructuredUnit::createUnit($name); $result = "structured unit with name={$name} created"; break; case 'getUnitId': $id = StructuredUnit::getUnitId($name); $result = "The id for the unit {$name} is {$id}"; break; case 'getUnit': $unit = StructuredUnit::getUnit($name); $result = "unit: " . implode(', ', $unit); break; case 'getUnitRandom': $random = StructuredUnit::getUnitRandom($name); $result = "The random for the unit {$name} is {$random}"; break; case 'updateUnit': StructuredUnit::updateUnit($id, $name, $random); $result = "structured unit with name={$name}, id={$id}, random={$random} updated"; break; case 'deleteUnit': StructuredUnit::deleteUnit($name); $result = "structured unit with name={$name} deleted"; break; }