当前位置: 首页>>代码示例>>PHP>>正文


PHP Parameter::create方法代码示例

本文整理汇总了PHP中Parameter::create方法的典型用法代码示例。如果您正苦于以下问题:PHP Parameter::create方法的具体用法?PHP Parameter::create怎么用?PHP Parameter::create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Parameter的用法示例。


在下文中一共展示了Parameter::create方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: create

 /**
  * @see ParameterTemplateParameterInterface::create()
  * @param integer $folder_id
  * @param integer $owner_id
  * @param integer $template_id
  * @param integer $limit_id
  * @param array $parameter_array
  * @return integer
  * @throws ParameterCreateTemplateLinkFailedException
  * @throws ParameterCreateIDMissingException
  */
 public function create($folder_id, $owner_id, $template_id, $limit_id, $parameter_array)
 {
     global $transaction;
     if (is_numeric($folder_id) and is_numeric($owner_id) and is_numeric($template_id) and is_numeric($limit_id) and $parameter_array) {
         if (is_array($parameter_array)) {
             $transaction_id = $transaction->begin();
             try {
                 $parameter_id = parent::create($folder_id, $limit_id, $parameter_array, $owner_id);
                 $parameter_has_template = new ParameterHasTemplate_Access(null, null);
                 if ($parameter_has_template->create($parameter_id, $template_id) == null) {
                     throw new ParameterCreateTemplateLinkFailedException();
                 }
             } catch (BaseException $e) {
                 if ($transaction_id != null) {
                     $transaction->rollback($transaction_id);
                 }
                 throw $e;
             }
             if ($transaction_id != null) {
                 $transaction->commit($transaction_id);
             }
             return $parameter_id;
         } else {
             throw new ParameterCreateIDMissingException();
         }
     } else {
         throw new ParameterCreateIDMissingException();
     }
 }
开发者ID:suxinde2009,项目名称:www,代码行数:40,代码来源:parameter_template_parameter.class.php

示例2: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Eloquent::unguard();
     $algorithmsXmls = File::allFiles(public_path() . '/algorithms');
     foreach ($algorithmsXmls as $algorithmsXml) {
         $dom = new DomDocument();
         $dom->load($algorithmsXml);
         $root = $dom->documentElement;
         $modality = Modality::whereName($root->getAttribute('modality'))->first();
         if (empty($modality)) {
             throw new Exception("Could not find modality! ({$algorithmsXml})");
         }
         $protocolName = $root->getAttribute('protocol');
         $protocol = Protocol::whereName($protocolName)->whereModalityId($modality->Id)->first();
         if (empty($protocol)) {
             \Log::warning("Could not find protocol! ({$algorithmsXml})");
             continue;
         }
         $arguments = [];
         $parameters = [];
         $description = "";
         foreach ($root->childNodes as $node) {
             if (get_class($node) == 'DOMText') {
                 continue;
             }
             switch ($node->nodeName) {
                 case 'arguments':
                     foreach ($node->childNodes as $argument) {
                         if (get_class($argument) == 'DOMText') {
                             continue;
                         }
                         $arguments[] = ['Name' => $argument->getAttribute('name')];
                     }
                     break;
                 case 'parameters':
                     foreach ($node->childNodes as $parameter) {
                         if (get_class($parameter) == 'DOMText') {
                             continue;
                         }
                         $parameters[] = ['Name' => $parameter->getAttribute('name'), 'Type' => $parameter->getAttribute('type'), 'Value' => $parameter->hasAttribute('value') ? $parameter->getAttribute('value') : null];
                     }
                     break;
                 case 'description':
                     $description = $node->textContent;
                     break;
                 default:
                     throw new Exception("Unrecognized entry in algorithm XML - {$node->nodeName}! ({$algorithmsXml})");
             }
         }
         $algorithm = new Algorithm();
         $algorithm->content = $description;
         $resultName = $root->getAttribute('result');
         $resultType = $root->getAttribute('type');
         $result = Parameter::whereName($resultName)->first();
         if (empty($result)) {
             $result = Parameter::create(['Name' => $resultName, 'Type' => $resultType]);
         }
         $algorithm->result()->associate($result);
         $algorithm->protocol()->associate($protocol);
         $algorithm->save();
         foreach ($arguments as $argument) {
             $algorithm->arguments()->attach(Argument::create($argument));
         }
         foreach ($parameters as $parameter) {
             $algorithm->attribute($parameter);
         }
     }
 }
开发者ID:philtweir,项目名称:glossia-scratch-test-site,代码行数:73,代码来源:AlgorithmSeeder.php

示例3: attribute

 public function attribute($data, $context = null, $overwrite = true, $overwrite_parameter = false)
 {
     $name = $data['Name'];
     if (!$this->Id) {
         throw new InvalidArgumentException("Cowardly refusing to create an empty (universal) attribute");
     }
     /* Convention over configuration */
     $id_name = train_case(get_class($this)) . '_Id';
     if ($id_name == 'Context_Id') {
         $id_name = Context::$idField;
     }
     $parameterClause = ParameterAttribution::where($id_name, '=', $this->Id);
     $activeFields = [snake_case(get_class($this))];
     if ($context !== null) {
         $activeFields[] = 'context';
         $parameterClause = $parameterClause->where(Context::$idContext, '=', $context->Id);
     }
     $parameterAttributions = $parameterClause->whereHas('parameter', function ($q) use($name) {
         $q->where('Name', '=', $name);
     })->get()->filter(function ($pa) use($activeFields) {
         return empty(array_diff(array_values($pa->activeFields()), array_values($activeFields)));
     });
     $parameterAttribution = $parameterAttributions->first();
     $parameterAttributions->each(function ($pa) {
         $pa->delete();
     });
     if (array_key_exists('Value', $data)) {
         $value = $data['Value'];
         unset($data['Value']);
     } else {
         $value = null;
     }
     if (array_key_exists('Widget', $data)) {
         $widget = $data['Widget'];
         unset($data['Widget']);
     } else {
         $widget = null;
     }
     if (array_key_exists('Units', $data)) {
         $units = $data['Units'];
         unset($data['Units']);
     } else {
         $units = null;
     }
     if (array_key_exists('Editable', $data)) {
         $editable = $data['Editable'];
         unset($data['Editable']);
     } else {
         $editable = 2;
     }
     if ($parameterAttribution) {
         $parameter = $parameterAttribution->parameter;
         if ($overwrite) {
             $parameterAttribution->Value = $value;
             $parameterAttribution->Editable = $editable;
             $parameterAttribution->Widget = $widget;
             $parameterAttribution->Units = $units;
             $parameterAttribution->save();
         } else {
             $value = $parameterAttribution->Value;
             $editable = $parameterAttribution->Editable;
             $widget = $parameterAttribution->Widget;
             $units = $parameterAttribution->Units;
         }
     } else {
         $parameter = Parameter::whereName($data['Name'])->first();
         if (empty($parameter)) {
             $parameter = Parameter::create($data);
         } else {
             $parameter->update(array_filter($data));
         }
         /* Convention over configuration */
         $id_name = train_case(get_class($this)) . '_Id';
         if ($id_name == 'Context_Id') {
             $id_name = Context::$idField;
         }
         $type = array_key_exists('Type', $data) ? $data['Type'] : $parameter->Type;
         $widget = isset($widget) ? $widget : $parameter->Widget;
         $units = isset($units) ? $units : $parameter->Units;
         $attribution = [$id_name => $this->Id, 'Parameter_Id' => $parameter->Id, 'Value' => $value, 'Format' => $type, 'Editable' => $editable, 'Widget' => $widget, 'Units' => $units];
         if ($context !== null) {
             $attribution[Context::$idContext] = $context->Id;
         }
         $parameterAttribution = ParameterAttribution::create($attribution);
     }
     if ($parameter->Widget === null && $parameter->Units === null || $overwrite_parameter) {
         $parameter->Widget = $widget;
         $parameter->Units = $units;
     }
     $parameter->Value = $value;
     $parameter->Editable = $editable;
     $parameter->Widget = $widget;
     $parameter->Units = $units;
     $parameterAttribution->save();
     return $parameter;
 }
开发者ID:philtweir,项目名称:glossia-scratch-test-site,代码行数:96,代码来源:Paramable.php

示例4: run

 public function run()
 {
     Parameter::create(['Name' => 'NEEDLE_TIP_LOCATION', 'Type' => 'array(float)', 'Widget' => 'textbox', 'Description' => 'location of the needle tip']);
     Parameter::create(['Name' => 'NEEDLE_ENTRY_LOCATION', 'Type' => 'array(float)', 'Widget' => 'textbox', 'Description' => 'location of the needle tip']);
 }
开发者ID:philtweir,项目名称:glossia-scratch-test-site,代码行数:5,代码来源:ParameterSeeder.php

示例5: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Eloquent::unguard();
     $parameterFields = ['name', 'type', 'widget', 'description', 'units', 'priority', 'restriction'];
     $attributionFields = ['Name', 'Type', 'Widget', 'Units'];
     $constantsXmls = File::allFiles(public_path() . '/constants');
     foreach ($constantsXmls as $constantsXml) {
         $dom = new DomDocument();
         $dom->load($constantsXml);
         $root = $dom->documentElement;
         $class = $root->getAttribute('class');
         $name = $root->getAttribute('name');
         //FIXME: Not very safe!
         if (Config::get('gosmart.context_as_enum') && $class == 'Context') {
             if ($root->hasAttribute('family')) {
                 $family = $root->getAttribute('family');
             } else {
                 $family = 'organ';
             }
             $target = Context::byNameFamily($name, $family);
         } else {
             $object = new $class();
             $objectQuery = $object->whereName($name);
             if ($root->hasAttribute('family')) {
                 $objectQuery = $objectQuery->whereFamily($root->getAttribute('family'));
             }
             $target = $objectQuery->first();
         }
         if (empty($target)) {
             throw new Exception("Did not find object {$name} ({$class}) for {$constantsXml}");
         }
         foreach ($root->childNodes as $constant) {
             if (get_class($constant) == 'DOMText') {
                 continue;
             }
             if (!$constant->hasAttribute('name')) {
                 throw new Exception("Constant missing name! ({$constantsXml})");
             }
             $present = array_filter($parameterFields, [$constant, 'hasAttribute']);
             $parameterData = [];
             array_map(function ($a) use(&$parameterData, $constant) {
                 $parameterData[train_case($a)] = $constant->getAttribute($a);
             }, $present);
             if (!$constant->hasAttribute('description')) {
                 $parameterData['Description'] = $parameterData['Name'];
             }
             $parameterData['Name'] = preg_replace('/[ -]/', '_', $parameterData['Name']);
             $parameterData['Name'] = strtoupper($constant->nodeName) . '_' . strtoupper(preg_replace('/[[:^word:]]/', '', $parameterData['Name']));
             if (!$constant->hasAttribute('type')) {
                 $parameterData['Type'] = 'float';
             }
             $parameter = Parameter::whereName($parameterData['Name'])->first();
             if (empty($parameter)) {
                 $parameter = Parameter::create($parameterData);
             } else {
                 $parameter->fill($parameterData)->save();
             }
             $id_name = train_case($class) . '_Id';
             if ($id_name == "Context_Id") {
                 $id_name = Context::$idField;
             }
             $attributionData = array_intersect_key($parameterData, array_flip($attributionFields));
             if ($constant->hasAttribute('context')) {
                 //$attributionData[Context::$idField] = Context::byNameFamily($constant->getAttribute('context'), $constant->getAttribute('contextFamily') ?: 'organ')->first()->id;
                 $context = Context::byNameFamily($constant->getAttribute('context'), $constant->getAttribute('contextFamily') ?: 'organ')->first();
             } else {
                 $context = null;
             }
             if ($constant->hasAttribute('value')) {
                 $attributionData['Value'] = $constant->getAttribute('value');
             } else {
                 $attributionData['Value'] = null;
             }
             $attribution = $target->attribute($attributionData, $context);
         }
     }
 }
开发者ID:philtweir,项目名称:glossia-scratch-test-site,代码行数:82,代码来源:ValueSeeder.php


注:本文中的Parameter::create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。