本文整理汇总了PHP中Unit类的典型用法代码示例。如果您正苦于以下问题:PHP Unit类的具体用法?PHP Unit怎么用?PHP Unit使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Unit类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: visit
function visit(Unit $node)
{
$txt = "";
$pad = 4 * $node->getDepth();
$txt .= sprintf("%{$pad}s", "");
$txt .= get_class($node) . ": ";
$txt .= "bombard: " . $node->bombardStrength() . "\n";
$this->text .= $txt;
}
示例2: testAbbreviation
public function testAbbreviation()
{
$unit = new Unit('Kilogram', 'kg');
$this->assertEquals('kg', $unit->getAbbr());
$unit = new Unit('Kilogram', '..kilo gram ');
$this->assertEquals('kilogram', $unit->getAbbr());
$unit = new Unit('Kilogram', '1kg');
$this->assertEquals('kg', $unit->getAbbr());
}
示例3: toRoman
protected function toRoman($number)
{
$u = new Unit();
if ($number % $this->numberUnit == 0) {
return $this->hundred[$number / $this->numberUnit - 1];
} else {
return $this->hundred[$number / $this->numberUnit - 1] . $u->convert($number % $this->numberUnit);
}
}
示例4: counterAttack
public function counterAttack(Unit $enemy)
{
try {
$this->ensureIsAlive();
$enemy->takeDamage($this->damage / 2);
} catch (Exception $a) {
echo "my target is dead" . PHP_EOL;
}
}
示例5: addUnit
function addUnit(Unit $unit)
{
foreach ($this->units as $thisunit) {
if ($unit === $thisunit) {
return;
}
}
$unit->setDepth($this->depth + 1);
$this->units[] = $unit;
}
示例6: get_unit_name
function get_unit_name()
{
if (!isset($this->details->unit_id) || $this->details->unit_id == '') {
return __('General', 'cp');
} else {
$unit_obj = new Unit($this->details->unit_id);
$unit = $unit_obj->get_unit();
return $unit->post_title;
}
}
示例7: joinExisting
/**
* @param Unit $newUnit
* @param Unit $occupyingUnit
* @return Unit
*/
public static function joinExisting(Unit $newUnit, Unit $occupyingUnit)
{
$comp = null;
if (!is_null($comp = $occupyingUnit->getComposite())) {
$comp->addUnit($newUnit);
} else {
$comp = new Army();
$comp->addUnit($occupyingUnit)->addUnit($newUnit);
}
return $comp;
}
示例8: toRoman
/**
* @todo Finalize implementation of this method.
*/
protected function toRoman($number)
{
$u = new Unit();
if ($number % $this->numberUnit == 0 && $number < 10000) {
return $this->thousand[$number / $this->numberUnit - 1];
} else {
if ($number < 10000) {
return $this->thousand[$number / $this->numberUnit - 1] . $u->convert($number % $this->numberUnit);
} else {
return 'Fail';
}
}
}
示例9: convertTo
/**
* Convert the quantity to another unit quantity
* @param Unit $to
* @throws \ErrorException
* @return float
*/
public function convertTo(Unit $to)
{
if ($this->getType() != $to->getType()) {
throw new \ErrorException("Cannot convert {$this->getType()} to {$to->getType()}");
}
// Do we have the fast conversion rate set?
if (array_key_exists($to::NAME, $this->fastRates)) {
$result = $this->getQuantity() * $this->fastRates[$to::NAME];
} else {
// Convert through the universal standard
$result = $this->getQuantity() / $to::RATE * $this::RATE;
}
return round($result, $this->getPrecision());
}
示例10: actionIndex
/**
* Lists all models.
*/
public function actionIndex()
{
$unit_model = Unit::model();
$dataProvider = array();
foreach ($unit_model->findAll() as $value) {
$dataProvider[$value->id] = new CActiveDataProvider('Accounts', array('criteria' => array('condition' => "sid={$value->id}"), 'pagination' => array('pageSize' => 100)));
}
if (isset($_POST['yt0'])) {
if (isset($_POST['group'])) {
$_SESSION['data'] = $_POST['group'];
}
$_SESSION['title'] = $_POST['team_title'];
$table_model = Accounts::model();
$table_model->create_table();
// foreach ( $_REQUEST['group'] as $key => $g )
// {
// $criteria = new CDbCriteria;
// $criteria->addInCondition( 'id' , $g );
// $data[$key] = new CActiveDataProvider( 'Accounts' , array(
// 'criteria' => $criteria ,
// 'pagination' => false ,
// ) );
// }
// $this->layout = '//layouts/';
// $this->render( 'create_table' , array(
// 'title' => $_REQUEST['team_title'] ,
// 'data' => $data ,
// 'model' => $table_model ,
// ) );
Yii::app()->end();
}
$this->render('index', array('dataProvider' => $dataProvider, 'unit' => $unit_model));
}
示例11: redirectAction
public function redirectAction()
{
if (!($unit = Unit::find(intval($_GET['id'])))) {
return $this->redirect('/');
}
$this->view->unit = $unit;
}
示例12: insertUnit
public function insertUnit(Unit $unit)
{
$con = self::openConnection();
mysqli_begin_transaction($con);
$code = $unit->getCode();
$sql = "INSERT INTO currency (code) VALUE ('{$code}')";
var_dump($sql);
mysqli_query($con, $sql);
$affected = mysqli_affected_rows($con);
var_dump($affected);
if ($affected == 1) {
mysqli_commit($con);
} else {
mysqli_rollback($con);
}
return $affected;
}
示例13: create
/**
* Muestra el formulario para crear un nuevo objetivo
*
* @return Response
*/
public function create($admin, $unitName)
{
$units = Unit::whereName($unitName)->get();
foreach ($units as $unit) {
$unit = $unit->id;
return View::make('subjects.create', compact('unit', 'admin'));
}
}
示例14: createFromTimePeriod
/**
* Create weight object from timePeriod widget value
* @param mixed
* @return Weight|null
*/
public static function createFromTimePeriod($arrData)
{
$arrData = deserialize($arrData);
if (empty($arrData) || !is_array($arrData) || $arrData['value'] === '' || $arrData['unit'] === '' || !in_array($arrData['unit'], Unit::getAll())) {
return null;
}
return new static($arrData['value'], $arrData['unit']);
}
示例15: get_unit_availability_status
public static function get_unit_availability_status($unit_id)
{
$unit_details = false;
$unit = new Unit((int) $unit_id);
$unit_details = $unit->get_unit();
$unit_available_date = get_post_meta($unit_id, 'unit_availability', true);
/* Not filtering date format as it could cause conflicts. Only filter date on display. */
$current_date = date('Y-m-d', current_time('timestamp', 0));
/* Check if previous has conditions */
$previous_unit_id = self::get_previous_unit_from_the_same_course($unit->course_id, $unit_id);
$force_current_unit_completion = !empty($previous_unit_id) ? get_post_meta($previous_unit_id, 'force_current_unit_completion', true) : '';
$force_current_unit_successful_completion = !empty($previous_unit_id) ? get_post_meta($previous_unit_id, 'force_current_unit_successful_completion', true) : '';
$available = true;
$student_id = get_current_user_id();
$mandatory_done = Student_Completion::is_mandatory_complete($student_id, $unit->course_id, $previous_unit_id);
$unit_completed = Student_Completion::is_unit_complete($student_id, $unit->course_id, $previous_unit_id);
$unit->status['mandatory_required']['enabled'] = !empty($force_current_unit_completion) && 'on' == $force_current_unit_completion;
$unit->status['mandatory_required']['result'] = $mandatory_done;
$unit->status['completion_required']['enabled'] = !empty($force_current_unit_successful_completion) && 'on' == $force_current_unit_successful_completion;
$unit->status['completion_required']['result'] = $unit_completed;
$available = $unit->status['mandatory_required']['enabled'] ? $unit->status['mandatory_required']['result'] : $available;
$available = $unit->status['completion_required']['enabled'] ? $unit->status['completion_required']['result'] : $available;
$unit->status['date_restriction']['result'] = $current_date >= $unit_available_date;
if (!$unit->status['date_restriction']['result'] || !$available) {
$available = false;
} else {
$available = true;
}
/**
* Perform action if unit is available.
*
* @since 1.2.2
* */
do_action('coursepress_unit_availble', $available, $unit_id);
/**
* Return filtered value.
*
* Can be used by other plugins to filter unit availability.
*
* @since 1.2.2
* */
$available = apply_filters('coursepress_filter_unit_availability', $available, $unit_id);
$status = $unit->status;
$status['available'] = $available;
return $status;
}