public static function construct($alarm1, $alarm2, $tamper, $battery, $supervision_reports, $restore_reports, $trouble, $ac) { $status = new self(); $value = 0x0; if ($alarm1) { $value |= self::ALARM_1_BITMASK; } if ($alarm2) { $value |= self::ALARM_2_BITMASK; } if ($tamper) { $value |= self::TAMPER_BITMASK; } if ($battery) { $value |= self::BATTERY_BITMASK; } if ($supervision_reports) { $value |= self::SUPERVISION_REPORTS_BITMASK; } if ($restore_reports) { $value |= self::RESTORE_REPORTS_BITMASK; } if ($trouble) { $value |= self::TROUBLE_BITMASK; } if ($ac) { $value |= self::AC_MAINS_BITMASK; } $status->setValue($value); return $status; }
/** * Factory method to load form fields from config. * * Config must return an array: field_id => waContactField OR array of options to specify on existing field with given field_id. * * @param string|array $file path to config file, or array of config options. * @param array $options */ public static function loadConfig($file, $options = array()) { $config = self::readConfig($file); $form = new self($config['fields'], $options); $form->setValue($config['values']); return $form; }
/** * @param mixed|null $value * * @return Item */ public static function create($value = null) { $item = new self(); if ($value) { $item->setValue($value); } return $item; }
/** * @param $arr * @return Tree */ private static function fromArray($arr) { $ret = new self([]); foreach ($arr as $key => $value) { $ret->setValue($key, $value); } return $ret; }
public static function withAttributes($title, $value, $isShort = true) { $instance = new self(); $instance->setTitle($title); $instance->setValue($value); $instance->setShort($isShort); return $instance; }
public static function construct($attribute_id, $datatype_id, $value) { $element = new self(); $element->setAttributeId($attribute_id); $element->setDatatypeId($datatype_id); $element->setValue($value); return $element; }
/** * Generates a new table cell * * @param string $value * @param array $attributes * * @return FTV_Html_Cell */ public function cell($value, array $attributes = null) { $cell = new self(); $cell->setValue($value); if (null !== $attributes) { $cell->setAttributes($attributes); } return $cell; }
public static function constructSuccess($attribute_id, $datatype_id, $value) { $record = new self(); $record->setAttributeId($attribute_id); $record->setStatus(ZCLStatus::SUCCESS); $record->setDatatypeId($datatype_id); $record->setValue($value); return $record; }
/** * @param Schema $schema * @param Property $property * @param string $operationType * @return Operation */ public static function factory(Schema $schema, Property $property, $operationType) { $operation = new self(); $operation->setType($operationType); $operation->setSchema($schema); $operation->setPath($property->getPath()); $operation->setValue($property->getValue()); return $operation; }
/** * Criar Item com campos obrigatórios preenchidos * * @param string $id - Código do Produto * @param string $name - Nome do Produto * @param float $value - Valor Unitário * @param integer $quantity - Quantidade * * @return Item */ public static function create($id, $name, $value, $quantity) { $instance = new self(); $instance->setId($id); $instance->setName($name); $instance->setValue($value); $instance->setQuantity($quantity); return $instance; }
/** * @param $name * @param $value */ public static function set($name, $value) { $obj = new self($name); $obj->setValue($value); if (self::where(array('name' => $name))->hasSets()) { $obj->update(); } else { $obj->create(); } }
/** * @param SimpleXMLElement $xml * * @return Characteristic */ public static function createFromXML(SimpleXMLElement $xml) { /* <characteristic displayValue="Basic (0-500 EUR)" value="1" name="Insurance range code"/> */ $attributes = $xml->attributes(); $option = new self(); $option->setDisplayValue($attributes['displayValue']); $option->setValue($attributes['value']); $option->setName($attributes['name']); return $option; }
/** * @return ConfigurationEntry */ static function getEntry(ConfigurationKey $ck) { try { $entry = self::dao()->getEntityById($ck); } catch (OrmEntityNotFoundException $e) { $entry = new self(); $entry->setId($ck); $entry->setValue(''); $entry->save(); } return $entry; }
public static function setForScope($scope, array $settings) { /** @var \Octo\System\Store\SettingStore $settingStore */ $settingStore = Store::get('Setting'); foreach ($settings as $key => $value) { $setting = new self(); $setting->setKey($key); $setting->setValue($value); $setting->setScope($scope); $settingStore->saveByReplace($setting); } }
public static function fromArray($data) { if (!array_key_exists('value', $data) || !array_key_exists('reasons', $data)) { throw new \InvalidArgumentException('array does not contain \'value\' or \'reasons\''); } if (!is_array($data['reasons'])) { throw new \InvalidArgumentException('\'reasons\' must be an array'); } $scorePart = new self(); $scorePart->setValue($data['value']); $scorePart->setReasons($data['reasons']); return $scorePart; }
public static function set($_key, $_value, $_lifetime = 60, $_options = null) { if ($_lifetime < 0) { $_lifetime = 0; } $cache = new self(); $cache->setKey($_key); $cache->setValue($_value); $cache->setLifetime($_lifetime); if ($_options != null) { $cache->options = json_encode($_options, JSON_UNESCAPED_UNICODE); } return $cache->save(); }
/** * @param array $option * @param integer $currentXml * @return array */ private function internalParse(array &$option, $currentXml = 0) { if ($currentXml == 0) { if (!isset($option[0])) { return array(); } $currentXmlArray = $option[0]; $this->setName(isset($currentXmlArray['tag']) ? $currentXmlArray['tag'] : 'noname'); $this->setValue(isset($currentXmlArray['value']) ? $currentXmlArray['value'] : ''); $this->setAttributes(isset($currentXmlArray['attributes']) ? $currentXmlArray['attributes'] : array()); $this->setRoot(true); } $xmlArray = array(); $currentXml++; $deep = $currentXml; while ($deep < count($option)) { $currentXmlArray = $option[$deep]; if ($currentXmlArray['type'] == 'close') { return array($xmlArray, $deep); } $xmlObject = new self(''); $xmlObject->setName(isset($currentXmlArray['tag']) ? $currentXmlArray['tag'] : 'noname'); $xmlObject->setValue(isset($currentXmlArray['value']) ? $currentXmlArray['value'] : ''); $xmlObject->setAttributes(isset($currentXmlArray['attributes']) ? $currentXmlArray['attributes'] : array()); if ($currentXmlArray['type'] == 'open') { $result = $this->internalParse($option, $deep++); if (!empty($result)) { list($children, $deep) = $result; $xmlObject->appendChild($children); } } $xmlArray[$xmlObject->getName()][] = $xmlObject; $deep++; } return array($xmlArray, $deep); }
/** * Helper to quickly create a new asset * * @param integer $parentId * @param array $data * @return Asset */ public static function create($parentId, $data = array()) { $asset = new self(); $asset->setParentId($parentId); foreach ($data as $key => $value) { $asset->setValue($key, $value); } $asset->save(); // get concrete type of asset Zend_Registry::set("asset_" . $asset->getId(), null); $asset = self::getById($asset->getId()); Zend_Registry::set("asset_" . $asset->getId(), $asset); return $asset; }
static function create($value, $currency = null, $locale = null) { $c = new self($currency, $locale); $c->setValue($value); return $c; }
public function __clone() { $clone = new self($this->getName(), $this->getMetadata(), $this->getDefaultTypeName(), $this->getMandatory(), $this->getMultilingual(), $this->getMaxOccurs(), $this->getMinOccurs(), $this->getParams()); $clone->types = []; foreach ($this->types as $type) { $clone->addType(clone $type); } $clone->setValue($this->getValue()); return $clone; }
/** * @param ConfigurationEntryDefinition $def * * @return ConfigurationEntry */ public static function createFromDefinition(ConfigurationEntryDefinition $def) { $me = new self($def->getName()); $me->setReadableName($def->getReadableName()); $me->setValue($def->getValue()); $me->setServerHandlerConfig($def->getServerHandlerConfig()); $me->setClientHandlerConfig($def->getClientHandlerConfig()); $me->setExposed($def->isExposed()); $me->setCategory($def->getCategory()); return $me; }
/** * {@inheritdoc} */ public static function fromArray(array $values) { $message = new self(); $values = array_merge(['key' => null, 'value' => null], $values); $message->setKey($values['key']); $message->setValue($values['value']); return $message; }
/** * @param $strValue * * @return Phone */ public static function createFromString($strValue) { $phone = new self(); $phone->setValue($strValue); return $phone; }
/** * Archive les données de history dans historyArch */ public static function archive() { $sql = 'DELETE FROM history WHERE `datetime` <= "2000-01-01 01:00:00" OR `datetime` >= "2020-01-01 01:00:00"'; DB::Prepare($sql, array()); $sql = 'DELETE FROM historyArch WHERE `datetime` <= "2000-01-01 01:00:00" OR `datetime` >= "2020-01-01 01:00:00"'; DB::Prepare($sql, array()); $sql = 'DELETE FROM history WHERE `value` IS NULL'; DB::Prepare($sql, array()); $sql = 'DELETE FROM historyArch WHERE `value` IS NULL'; DB::Prepare($sql, array()); if (config::byKey('historyArchivePackage') >= config::byKey('historyArchiveTime')) { config::save('historyArchivePackage', config::byKey('historyArchiveTime') - 1); } if (config::byKey('historyArchiveTime') < 1) { $archiveDatetime = date('Y-m-d H:i:s', strtotime('- 1 hours')); } else { $archiveDatetime = date('Y-m-d H:i:s', strtotime('- ' . config::byKey('historyArchiveTime', 'core', 1) . ' hours')); } if (config::byKey('historyArchivePackage') < 1) { $archivePackage = '00:' . config::byKey('historyArchivePackage') * 60 . ':00'; } else { $archivePackage = config::byKey('historyArchivePackage') . ':00:00'; if (strlen($archivePackage) < 8) { $archivePackage = '0' . $archivePackage; } } $values = array('archiveDatetime' => $archiveDatetime); $sql = 'SELECT DISTINCT(cmd_id) FROM history WHERE `datetime`<:archiveDatetime'; $list_sensors = DB::Prepare($sql, $values, DB::FETCH_TYPE_ALL); foreach ($list_sensors as $sensors) { $cmd = cmd::byId($sensors['cmd_id']); if (is_object($cmd) && $cmd->getType() == 'info' && $cmd->getIsHistorized() == 1) { if ($cmd->getConfiguration('historyPurge', '') != '') { $purgeTime = date('Y-m-d H:i:s', strtotime($cmd->getConfiguration('historyPurge', ''))); $values = array('cmd_id' => $cmd->getId(), 'datetime' => $purgeTime); $sql = 'DELETE FROM historyArch WHERE cmd_id=:cmd_id AND `datetime` < :datetime'; DB::Prepare($sql, $values, DB::FETCH_TYPE_ROW); } if ($cmd->getSubType() == 'binary' || $cmd->getConfiguration('historizeMode', 'avg') == 'none') { $values = array('cmd_id' => $cmd->getId()); $sql = 'SELECT ' . DB::buildField(__CLASS__) . ' FROM history WHERE cmd_id=:cmd_id ORDER BY `datetime` ASC'; $history = DB::Prepare($sql, $values, DB::FETCH_TYPE_ALL, PDO::FETCH_CLASS, __CLASS__); for ($i = 1; $i < count($history); $i++) { if ($history[$i]->getValue() != $history[$i - 1]->getValue()) { $history[$i]->setTableName('historyArch'); $history[$i]->save(); $history[$i]->setTableName('history'); } $history[$i]->remove(); } $history[0]->setTableName('historyArch'); $history[0]->save(); $history[0]->setTableName('history'); $history[0]->remove(); $values = array('cmd_id' => $cmd->getId()); $sql = 'SELECT ' . DB::buildField(__CLASS__) . ' FROM historyArch WHERE cmd_id=:cmd_id ORDER BY datetime ASC'; $history = DB::Prepare($sql, $values, DB::FETCH_TYPE_ALL, PDO::FETCH_CLASS, __CLASS__); for ($i = 1; $i < count($history); $i++) { if ($history[$i]->getValue() == $history[$i - 1]->getValue()) { $history[$i]->setTableName('historyArch'); $history[$i]->remove(); } } } else { $values = array('cmd_id' => $sensors['cmd_id'], 'archiveDatetime' => $archiveDatetime); $sql = 'SELECT MIN(`datetime`) as oldest FROM history WHERE `datetime`<:archiveDatetime AND cmd_id=:cmd_id'; $oldest = DB::Prepare($sql, $values, DB::FETCH_TYPE_ROW); $mode = $cmd->getConfiguration('historizeMode', 'avg'); while ($oldest['oldest'] != null) { $values = array('cmd_id' => $sensors['cmd_id'], 'oldest' => $oldest['oldest'], 'archivePackage' => $archivePackage); $sql = 'SELECT ' . $mode . '(value) as value, FROM_UNIXTIME(AVG(UNIX_TIMESTAMP(`datetime`))) as datetime FROM history WHERE TIMEDIFF(`datetime`,:oldest)<:archivePackage AND cmd_id=:cmd_id'; $avg = DB::Prepare($sql, $values, DB::FETCH_TYPE_ROW); $history = new self(); $history->setCmd_id($sensors['cmd_id']); $history->setValue($avg['value']); $history->setDatetime($avg['datetime']); $history->setTableName('historyArch'); $history->save(); $values = array('cmd_id' => $sensors['cmd_id'], 'oldest' => $oldest['oldest'], 'archivePackage' => $archivePackage); $sql = 'DELETE FROM history WHERE TIMEDIFF(`datetime`,:oldest)<:archivePackage AND cmd_id=:cmd_id'; DB::Prepare($sql, $values, DB::FETCH_TYPE_ROW); $values = array('cmd_id' => $sensors['cmd_id'], 'archiveDatetime' => $archiveDatetime); $sql = 'SELECT MIN(`datetime`) as oldest FROM history WHERE `datetime`<:archiveDatetime AND cmd_id=:cmd_id'; $oldest = DB::Prepare($sql, $values, DB::FETCH_TYPE_ROW); } } } } }
/** * @param float $val * @return \self */ public static function createFromFloat($val) { $newInstance = new self(); $newInstance->setValue($val); return $newInstance; }
public static function create($value = null, tad_DI52_Container $container) { $instance = new self($container); $instance->setValue($value); return $instance; }
/** * Generate a new Cookie object from a cookie string * (for example the value of the Set-Cookie HTTP header) * * @static * @throws Zend_Http_Header_Exception_InvalidArgumentException * @param $headerLine * @param bool $bypassHeaderFieldName * @return array|SetCookie */ public static function fromString($headerLine, $bypassHeaderFieldName = false) { list($name, $value) = explode(': ', $headerLine, 2); // check to ensure proper header type for this factory if (strtolower($name) !== 'set-cookie') { throw new Zend_Http_Header_Exception_InvalidArgumentException('Invalid header line for Set-Cookie string: "' . $name . '"'); } $multipleHeaders = preg_split('#(?<!Sun|Mon|Tue|Wed|Thu|Fri|Sat),\\s*#', $value); $headers = array(); foreach ($multipleHeaders as $headerLine) { $header = new self(); $keyValuePairs = preg_split('#;\\s*#', $headerLine); foreach ($keyValuePairs as $keyValue) { if (strpos($keyValue, '=')) { list($headerKey, $headerValue) = preg_split('#=\\s*#', $keyValue, 2); } else { $headerKey = $keyValue; $headerValue = null; } // First K=V pair is always the cookie name and value if ($header->getName() === NULL) { $header->setName($headerKey); $header->setValue($headerValue); continue; } // Process the remanining elements switch (str_replace(array('-', '_'), '', strtolower($headerKey))) { case 'expires': $header->setExpires($headerValue); break; case 'domain': $header->setDomain($headerValue); break; case 'path': $header->setPath($headerValue); break; case 'secure': $header->setSecure(true); break; case 'httponly': $header->setHttponly(true); break; case 'version': $header->setVersion((int) $headerValue); break; case 'maxage': $header->setMaxAge((int) $headerValue); break; default: // Intentionally omitted } } $headers[] = $header; } return count($headers) == 1 ? array_pop($headers) : $headers; }
/** Convenience function for inline validating of variables. @param $mValue The value to validate. @param $aArgs The configuration arguments of the validator. @return bool Whether the variable is valid. */ public static function test($mValue, array $aArgs = array()) { $o = new self($aArgs); return !$o->setValue($mValue)->hasError(); }
public static function createFromRawEvent(RawEvent $rawEvent) { $event = new self(); $event->setStatus($rawEvent->getStatus()); $event->setMessage($rawEvent->getMessage()); $event->setUnique($rawEvent->isUnique()); $event->setUrl($rawEvent->getUrl()); $event->setValue($rawEvent->getValue()); $event->setComponentId($rawEvent->getComponentId()); return $event; }
/** * Factory method to load form fields from config. * * Config must return an array: field_id => waContactField OR array of options to specify on existing field with given field_id. * * @param string|array $file path to config file, or array of config options. * @param array $options */ public static function loadConfig($file, $options = array()) { if (is_array($file)) { $fields_config = $file; } else { if (!is_readable($file)) { throw new waException('Config is not readable: ' . $file); } $fields_config = (include $file); if (!$fields_config || !is_array($fields_config)) { waLog::log('Incorrect config ' . $file); $fields_config = array(); } } $fields = array(); $values = array(); // hidden field values known beforehand foreach ($fields_config as $full_field_id => $opts) { if ($opts instanceof waContactField) { $f = clone $opts; } else { if (is_array($opts)) { // Allow to specify something like 'phone.home' as field_id in config file. $fid = explode('.', $full_field_id, 2); $fid = $fid[0]; $f = waContactFields::get($fid); if (!$f) { waLog::log('ContactField ' . $fid . ' not found.'); continue; } else { // Prepare fields parameter for composite field if ($f instanceof waContactCompositeField && !empty($opts['fields'])) { if (!is_array($opts['fields'])) { unset($opts['fields']); } else { $old_subfields = $f->getFields(); $subfields = array(); foreach ($opts['fields'] as $sfid => $sfopts) { if (empty($old_subfields[$sfid])) { waLog::log('Field ' . $fid . ':' . $sfid . ' not found and is ignored in ' . (is_array($file) ? 'config' : $file)); continue; } $subfields[$sfid] = self::getClone($old_subfields[$sfid], $sfopts); if ($subfields[$sfid] instanceof waContactHiddenField) { if (empty($values[$full_field_id]['data'])) { $values[$full_field_id] = array('data' => array()); } $values[$full_field_id]['data'][$sfid] = $subfields[$sfid]->getParameter('value'); } } $opts['fields'] = $subfields; } } $f = self::getClone($f, $opts); if ($f instanceof waContactHiddenField) { $values[$full_field_id] = $f->getParameter('value'); } } } else { waLog::log('Field ' . $full_field_id . ' has incorrect format and is ignored in ' . $file); continue; } } $fields[$full_field_id] = $f; } $form = new self($fields, $options); $form->setValue($values); return $form; }