/** * Turns a quantity for the item into appropriately-pluralized text. * * 20 apples in total, using 1 => the apple * 20 apples in total, using 2 => 20 apples * 20 apples in total, using 20 => all 20 apples * 2 apple in total, using 1 => your apple * * @param mixed $quantity * @return string **/ public function makeActionText($quantity) { $word = ''; if ($quantity == $this->getQuantity()) { // Figure it out here so you have the methods available. if ($quantity > 1) { $word = "all <strong>{$quantity} {$this->getInflectedItemName()}</strong>"; } else { $word = "your <strong>{$this->getItemName()}</strong>"; } } else { if ($quantity > 1) { $plural = English_Inflector::pluralize($this->getItemName()); $word = "<strong>{$quantity} {$plural}</strong>"; } else { $word = "the <strong>{$this->getItemName()}</strong>"; } } // end not all return $word; }
$ERRORS[] = 'Invalid user specified.'; } elseif ($User->getUserName() == $other_user->getUserName()) { $ERRORS[] = 'You cannot give an item to yourself.'; } if ($item != null && $other_user != null) { if ($item->getUniqueItem() == 'Y') { if ($other_user->hasItem($item->getItemTypeId()) == true) { $ERRORS[] = 'That user already has this unique item!'; } elseif ($quantity > 1) { // This case should never come up... $ERRORS[] = 'This is a unique item; you cannot give the user two!'; } } } // end item and user exist if (sizeof($ERRORS) > 0) { draw_errors($ERRORS); } else { $word = $item->getItemName(); $item->giveItem($other_user, $quantity); if ($quantity > 1) { $word = English_Inflector::pluralize($word); } $_SESSION['item_notice'] = "You have given <strong>{$quantity} {$word}</strong> to {$other_user->getUserName()}."; redirect('items'); } // end DO IT break; // end give_process } // end switch
/** * Return $word in singular form. * * @param string $word Word in plural * @return string Word in singular **/ public static function singularize($word) { $_this =& English_Inflector::getInstance(); if (!isset($_this->singularRules) || empty($_this->singularRules)) { $_this->__initSingularRules(); } if (isset($_this->singularized[$word])) { return $_this->singularized[$word]; } extract($_this->singularRules); if (!isset($regexUninflected) || !isset($regexIrregular)) { $regexUninflected = English_Inflector::enclose(join('|', $uninflected)); $regexIrregular = English_Inflector::enclose(join('|', array_keys($irregular))); $_this->singularRules['regexUninflected'] = $regexUninflected; $_this->singularRules['regexIrregular'] = $regexIrregular; } if (preg_match('/(.*)\\b(' . $regexIrregular . ')$/i', $word, $regs)) { $_this->singularized[$word] = $regs[1] . substr($word, 0, 1) . substr($irregular[strtolower($regs[2])], 1); return $_this->singularized[$word]; } if (preg_match('/^(' . $regexUninflected . ')$/i', $word, $regs)) { $_this->singularized[$word] = $word; return $word; } foreach ($singularRules as $rule => $replacement) { if (preg_match($rule, $word)) { $_this->singularized[$word] = preg_replace($rule, $replacement, $word); return $_this->singularized[$word]; } } // end loop $_this->singularized[$word] = $word; return $word; }