當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Unit類代碼示例

本文整理匯總了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;
 }
開發者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


注:本文中的Unit類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。