コード例 #1
0
 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
0
ファイル: UnitTest.php プロジェクト: rmasters/units
 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
0
 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
0
ファイル: unit.php プロジェクト: Nisaiy/DeveloperClub
 public function counterAttack(Unit $enemy)
 {
     try {
         $this->ensureIsAlive();
         $enemy->takeDamage($this->damage / 2);
     } catch (Exception $a) {
         echo "my target is dead" . PHP_EOL;
     }
 }
コード例 #5
0
 function addUnit(Unit $unit)
 {
     foreach ($this->units as $thisunit) {
         if ($unit === $thisunit) {
             return;
         }
     }
     $unit->setDepth($this->depth + 1);
     $this->units[] = $unit;
 }
コード例 #6
0
 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
0
ファイル: UnitScript.php プロジェクト: Codealist/patterns
 /**
  * @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
0
 /**
  * @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
0
ファイル: Unit.php プロジェクト: xobb/mconv
 /**
  * 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
0
 /**
  * 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
0
ファイル: Unit.php プロジェクト: noriotakei/suraimu
 /**
  * getInstanceメソッド
  *
  * このクラスのオブジェクトを生成する。
  * 既に生成されていたら、前回と同じものを返す。
  *
  * @return object $instance
  */
 public static function getInstance()
 {
     if (!self::$_instance) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
コード例 #12
0
ファイル: IndexController.php プロジェクト: yslbc/twcompany
 public function redirectAction()
 {
     if (!($unit = Unit::find(intval($_GET['id'])))) {
         return $this->redirect('/');
     }
     $this->view->unit = $unit;
 }
コード例 #13
0
ファイル: CurrencyDAO.php プロジェクト: Voww/PHP_test_tasks
 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;
 }
コード例 #14
0
ファイル: listing11.09.php プロジェクト: jabouzi/projet
 function textDump($num = 0)
 {
     $ret = parent::textDump($num);
     foreach ($this->units as $unit) {
         $ret .= $unit->textDump($num + 1);
     }
     return $ret;
 }
コード例 #15
0
 /**
  * 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'));
     }
 }
コード例 #16
0
ファイル: Weight.php プロジェクト: codefog/contao-haste
 /**
  * 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']);
 }
コード例 #17
0
 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;
 }
コード例 #18
0
ファイル: UnitTest.php プロジェクト: y2khjh/test1
 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);
 }
コード例 #19
0
ファイル: dump.php プロジェクト: yslbc/twcompany
 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];
 }
コード例 #20
0
ファイル: Request.php プロジェクト: igaponov/jsonrpc
 /**
  * @inheritdoc
  */
 protected function getSerializableAttributes()
 {
     $attributes = parent::getSerializableAttributes();
     $attributes['method'] = $this->method;
     if ($this->params !== null) {
         $attributes['params'] = $this->params;
     }
     return $attributes;
 }
コード例 #21
0
ファイル: UnitsTableSeeder.php プロジェクト: syafdia/PAS
 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)]);
     }
 }
コード例 #22
0
ファイル: Response.php プロジェクト: igaponov/jsonrpc
 /**
  * @inheritdoc
  */
 protected function getSerializableAttributes()
 {
     $attributes = parent::getSerializableAttributes();
     if ($this->error !== null) {
         $attributes['error'] = $this->error;
     } else {
         $attributes['result'] = $this->result;
     }
     return $attributes;
 }
コード例 #23
0
 /**
  * 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));
 }
コード例 #24
0
ファイル: Ingredient.php プロジェクト: y2khjh/test1
 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");
     }
 }
コード例 #25
0
ファイル: UnitHandlerTest.php プロジェクト: microffice/units
 /**
  * Test edit should return filled $data
  *
  * @test
  */
 public function testEditShouldReturnFilledData()
 {
     $this->migrate('testbench_mysql');
     $response = \Unit::edit(1);
     $property = $this->getPrivateProperty('Illuminate\\View\\View', 'data');
     $array = $property->getValue($response);
     $this->assertObjectHasAttribute('data', $response);
     $this->assertArrayHasKey('id', $array);
     $this->assertArrayHasKey('unit', $array);
     //var_dump($array);
 }
コード例 #26
0
ファイル: ApiController.php プロジェクト: yslbc/twcompany
 public function showAction()
 {
     list(, , , $id) = explode('/', $this->getURI());
     $ret = new StdClass();
     if (!($unit = Unit::find(intval($id)))) {
         $ret->error = true;
         $ret->message = "Company not found";
         return $this->jsonp($ret, strval($_GET['callback']));
     }
     $ret->data = $unit->getData();
     return $this->jsonp($ret, strval($_GET['callback']));
 }
コード例 #27
0
 public function getUsercount()
 {
     $unit_model = Unit::model();
     $acc_model = Accounts::model();
     $data = array();
     foreach ($unit_model->findAll() as $value) {
         $temp = $acc_model->findAll("sid=:sid", array(":sid" => $value->id));
         $unit_tmp = $unit_model->find("id=:id", array(":id" => $value->id));
         $data[] = array($unit_tmp->name, count($temp));
     }
     return $data;
 }
コード例 #28
0
ファイル: Component.php プロジェクト: armourjami/armourtake
 public static function addComponent($dishId, $recipeId, $quantity, $unitName)
 {
     if (Unit::exists($newUnit) && Recipe::exists($recipeId)) {
         $db = self::getInstance();
         if ($db->insert('DishRecipes', ['Dishes_id' => $dishId, 'Recipes_id' => $recipeId, 'quantity' => $quantity, 'unit' => $unitName])) {
             return true;
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
コード例 #29
0
ファイル: Scale.php プロジェクト: codefog/contao-haste
 /**
  * Standardize and calculate the total of multiple weights
  *
  * It's probably faster in theory to convert only the total to the final unit, and not each product weight.
  * However, we might loose precision, not sure about that.
  * Based on formulas found at http://jumk.de/calc/gewicht.shtml
  * @param array
  * @param string
  * @return mixed
  */
 public function amountIn($strUnit)
 {
     if (empty($this->arrWeights)) {
         return 0;
     }
     $fltWeight = 0;
     foreach ($this->arrWeights as $objWeight) {
         if ($objWeight->getWeightValue() > 0) {
             $fltWeight += Unit::convert(floatval($objWeight->getWeightValue()), $objWeight->getWeightUnit(), Unit::KILOGRAM);
         }
     }
     return Unit::convert($fltWeight, Unit::KILOGRAM, $strUnit);
 }
コード例 #30
0
 public function run()
 {
     Unit::create(['name' => 'Kg']);
     Unit::create(['name' => 'Gram']);
     Unit::create(['name' => 'Lít']);
     Unit::create(['name' => 'Mililit']);
     Unit::create(['name' => 'Chai']);
     Unit::create(['name' => 'Gói']);
     Unit::create(['name' => 'Bao']);
     Unit::create(['name' => 'Thùng']);
     Unit::create(['name' => 'Hộp']);
     Unit::create(['name' => 'Lon']);
 }