本文整理汇总了PHP中Unit类的典型用法代码示例。如果您正苦于以下问题:PHP Unit类的具体用法?PHP Unit怎么用?PHP Unit使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Unit类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:sydorenkovd,项目名称:Design-pattern,代码行数:9,代码来源:Visitor.php
示例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());
}
开发者ID:rmasters,项目名称:units,代码行数:9,代码来源:UnitTest.php
示例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);
}
}
开发者ID:YurePereira,项目名称:fypa-design-patterns,代码行数:9,代码来源:Hundred.class.php
示例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;
}
}
开发者ID:Nisaiy,项目名称:DeveloperClub,代码行数:9,代码来源:unit.php
示例5: addUnit
function addUnit(Unit $unit)
{
foreach ($this->units as $thisunit) {
if ($unit === $thisunit) {
return;
}
}
$unit->setDepth($this->depth + 1);
$this->units[] = $unit;
}
开发者ID:sydorenkovd,项目名称:Design-pattern,代码行数:10,代码来源:CompositeUnit.php
示例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;
}
}
开发者ID:akshayxhtmljunkies,项目名称:brownglock,代码行数:10,代码来源:class.discussion.php
示例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;
}
开发者ID:Codealist,项目名称:patterns,代码行数:16,代码来源:UnitScript.php
示例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';
}
}
}
开发者ID:YurePereira,项目名称:fypa-design-patterns,代码行数:16,代码来源:Thousand.class.php
示例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());
}
开发者ID:xobb,项目名称:mconv,代码行数:20,代码来源:Unit.php
示例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));
}
开发者ID:renlong567,项目名称:YiiYurenGithub,代码行数:36,代码来源:TableController.php
示例11: redirectAction
public function redirectAction()
{
if (!($unit = Unit::find(intval($_GET['id'])))) {
return $this->redirect('/');
}
$this->view->unit = $unit;
}
开发者ID:yslbc,项目名称:twcompany,代码行数:7,代码来源:IndexController.php
示例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;
}
开发者ID:Voww,项目名称:PHP_test_tasks,代码行数:17,代码来源:CurrencyDAO.php
示例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'));
}
}
开发者ID:betancourtfran,项目名称:tep,代码行数:13,代码来源:SubjectsController.php
示例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']);
}
开发者ID:codefog,项目名称:contao-haste,代码行数:13,代码来源:Weight.php
示例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;
}
开发者ID:akshayxhtmljunkies,项目名称:brownglock,代码行数:46,代码来源:class.course.unit.php
示例16: testValidateFunction
public function testValidateFunction()
{
$this->assertEquals(Unit::validate('of'), true);
$this->assertEquals(Unit::validate('grams'), true);
$this->assertEquals(Unit::validate('ml'), true);
$this->assertEquals(Unit::validate('slices'), true);
$this->assertEquals(Unit::validate('tones'), false);
}
开发者ID:y2khjh,项目名称:test1,代码行数:8,代码来源:UnitTest.php
示例17: getType
public function getType($id)
{
if (!array_key_exists($id, $this->unit_types)) {
$start = floor($id / 10000) * 10000;
$end = $start + 10000;
$this->unit_types = Unit::search("`id` >= {$start} AND `id` < {$end}")->toArray('type');
}
return $this->unit_types[$id];
}
开发者ID:yslbc,项目名称:twcompany,代码行数:9,代码来源:dump.php
示例18: run
public function run()
{
$faker = Faker::create();
foreach (range(1, 10) as $index) {
$size = rand(100, 300);
$user_id = rand(1, 10);
Unit::create(['block' => $faker->word(), 'unit_type_id' => rand(1, 9), 'additional_land_area' => $size, 'additional_facility' => rand(0, 1), 'created_by' => $user_id, 'changed_by' => $user_id, 'change_reason' => $faker->realText(100)]);
}
}
开发者ID:syafdia,项目名称:PAS,代码行数:9,代码来源:UnitsTableSeeder.php
示例19: actionIndex
/**
* Lists all models.
*/
public function actionIndex()
{
$unit_model = Unit::model();
$dataProvider[0] = new CActiveDataProvider('Accounts', array('pagination' => array('pageSize' => 30)));
foreach ($unit_model->findAll() as $value) {
$dataProvider[$value->id] = new CActiveDataProvider('Accounts', array('criteria' => array('condition' => "sid={$value->id}"), 'pagination' => array('pageSize' => 10)));
}
// print_r($dataProvider[0]->getData());exit;
$this->render('index', array('dataProvider' => $dataProvider));
}
开发者ID:renlong567,项目名称:YiiYurenGithub,代码行数:13,代码来源:AccountsController.php
示例20: __construct
public function __construct($item, $amount, $unit, DateTime $usedBy)
{
$this->item = strval($item);
$this->amount = intval($amount);
$this->usedBy = $usedBy;
if (Unit::validate($unit)) {
$this->unit = strtolower($unit);
} else {
throw new InvalidArgumentException("Invalid unit");
}
}
开发者ID:y2khjh,项目名称:test1,代码行数:11,代码来源:Ingredient.php
注:本文中的Unit类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论