本文整理汇总了PHP中self::setAttributes方法的典型用法代码示例。如果您正苦于以下问题:PHP self::setAttributes方法的具体用法?PHP self::setAttributes怎么用?PHP self::setAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类self
的用法示例。
在下文中一共展示了self::setAttributes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: add
/**
* @param $from
* @param $to
* @return FriendRequest
*/
public static function add($from, $to)
{
$model = new self();
$model->setAttributes(['from' => $from, 'to' => $to]);
$model->save();
return $model;
}
示例2: getEliteFour
public static function getEliteFour($where = null, $limit = null, $order = ' e.`order`, e.`id` ')
{
if (!is_null($where)) {
$where = 'WHERE ' . $where;
}
$getEliteFour = TPP::db()->query("SELECT\n\t\t\te.`id`,\n\t\t\te.`name`,\n\t\t\te.`type`,\n\t\t\te.`attempts`,\n\t\t\te.`wins`,\n\t\t\te.`losses`,\n\t\t\te.`time`,\n\t\t\te.`is_rematch`,\n\t\t\te.`order`,\n\t\t\tGROUP_CONCAT(\n\t\t\t\tDISTINCT CONCAT_WS('" . self::SEPARATOR_2 . "',\n\t\t\t\t\tefp.`id`,\n\t\t\t\t\tefp.`pokemon`,\n\t\t\t\t\tefp.`level`\n\t\t\t\t) SEPARATOR '" . self::SEPARATOR_1 . "'\n\t\t\t) as `pokemon`,\n\t\t\tGROUP_CONCAT(\n\t\t\t\tDISTINCT CONCAT_WS('" . self::SEPARATOR_2 . "',\n\t\t\t\t\tefpm.elite_four_pokemon_id,\n\t\t\t\t\tefpm.name\n\t\t\t\t) SEPARATOR '" . self::SEPARATOR_1 . "'\n\t\t\t) as `moves`\n\t\t\tFROM `elite_four` e\n\t\t\tJOIN `elite_four_pokemon` efp\n\t\t\t\tON efp.`elite_four_id` = e.`id`\n\t\t \tLEFT JOIN `elite_four_pokemon_move` efpm\n\t\t \t\tON efpm.`elite_four_pokemon_id` = efp.`id`\n\t\t\t" . $where . "\n\t\t\tGROUP BY e.`id`\n\t\t\tORDER BY " . $order . $limit);
if (!$getEliteFour) {
return [];
}
$return = [];
$beaten = $count_e4 = 0;
while ($eliteFour = $getEliteFour->fetch()) {
$count_e4++;
if (isset($eliteFour['time']) && $eliteFour['time'] != '') {
$beaten++;
}
$newE4 = new self();
$newE4->setAttributes(['id' => (int) $eliteFour['id'], 'name' => $eliteFour['name'], 'type' => $eliteFour['type'], 'attempts' => (int) $eliteFour['attempts'], 'wins' => (int) $eliteFour['wins'], 'losses' => (int) $eliteFour['losses'], 'time' => $eliteFour['time'], 'order' => (int) $eliteFour['order'], 'is_rematch' => (bool) $eliteFour['is_rematch'], 'pokemon' => parent::getPokemonForTrainer($eliteFour['pokemon'], ['id', 'pokemon', 'level'])]);
$moves = [];
foreach (explode(self::SEPARATOR_1, $eliteFour['moves']) as $move) {
$ex = explode(self::SEPARATOR_2, $move);
$moves[$ex[0]][] = $ex[1];
}
foreach ($newE4->pokemon as $p) {
if (isset($moves[$p->id])) {
$p->moves = $p->setMoves($moves[$p->id]);
}
}
$return[] = $newE4;
}
return ['beaten' => $beaten === $count_e4, 'elitefour' => $return];
}
示例3: getImportantTrainers
public static function getImportantTrainers($where = null, $limit = null, $order = ' i.`order_by`, i.`id` ')
{
if (!is_null($where)) {
$where = 'WHERE ' . $where;
}
$getImportantTrainers = TPP::db()->query("SELECT\n\t\t\ti.`id`,\n\t\t\ti.`name`,\n\t\t\ti.`nickname`,\n\t\t\ti.`type`,\n\t\t\ti.`attempts`,\n\t\t\ti.`wins`,\n\t\t\ti.`losses`,\n\t\t\ti.`time`,\n\t\t\ti.`is_rematch`,\n\t\t\ti.`order_by`,\n\t\t\tGROUP_CONCAT(\n\t\t\t\tDISTINCT CONCAT_WS('" . self::SEPARATOR_2 . "',\n\t\t\t\t\titp.`id`,\n\t\t\t\t\titp.`pokemon`,\n\t\t\t\t\titp.`level`,\n\t\t\t\t\titp.`nickname`,\n\t\t\t\t\tIFNULL(itp.`item`, 1)\n\t\t\t\t) SEPARATOR '" . self::SEPARATOR_1 . "'\n\t\t\t) as `pokemon`,\n\t\t\tGROUP_CONCAT(\n\t\t\t\tDISTINCT CONCAT_WS('" . self::SEPARATOR_2 . "',\n\t\t\t\t\titpm.important_trainer_pokemon_id,\n\t\t\t\t\titpm.name\n\t\t\t\t) SEPARATOR '" . self::SEPARATOR_1 . "'\n\t\t\t) as `moves`\n\t\t\tFROM `important_trainer` i\n\t\t\tJOIN `important_trainer_pokemon` itp\n\t\t\t\tON itp.`important_trainer_id` = i.`id`\n\t\t \tLEFT JOIN `important_trainer_pokemon_move` itpm\n\t\t \t\tON itpm.`important_trainer_pokemon_id` = itp.`id`\n\t\t\t" . $where . "\n\t\t\tGROUP BY i.`id`\n\t\t\tORDER BY " . $order . $limit);
if (!$getImportantTrainers) {
return [];
}
$return = [];
while ($importantTrainer = $getImportantTrainers->fetch()) {
$newIT = new self();
$newIT->setAttributes(['id' => (int) $importantTrainer['id'], 'name' => $importantTrainer['name'], 'nickname' => $importantTrainer['nickname'], 'type' => $importantTrainer['type'], 'attempts' => (int) $importantTrainer['attempts'], 'wins' => (int) $importantTrainer['wins'], 'losses' => (int) $importantTrainer['losses'], 'time' => $importantTrainer['time'], 'order_by' => (int) $importantTrainer['order_by'], 'is_rematch' => (bool) $importantTrainer['is_rematch'], 'pokemon' => parent::getPokemonForTrainer($importantTrainer['pokemon'], ['id', 'pokemon', 'level', 'nickname', 'item'])]);
$moves = [];
foreach (explode(self::SEPARATOR_1, $importantTrainer['moves']) as $move) {
$ex = explode(self::SEPARATOR_2, $move);
$moves[$ex[0]][] = $ex[1];
}
foreach ($newIT->pokemon as $p) {
if (isset($moves[$p->id])) {
$p->moves = $p->setMoves($moves[$p->id]);
}
}
$return[] = $newIT;
}
return ['importanttrainers' => $return];
}
示例4: add
/**
* add new log entry.
*
* @param int $type The type of add
* + 1 = insertion
* + 2 = update
* + 3 = deletion
* @param string $message
*/
public static function add($type, $message, array $additionalData = [])
{
$attrs = ['is_insertion' => $type == 1 ? 1 : 0, 'is_update' => $type == 2 ? 1 : 0, 'is_deletion' => $type == 3 ? 1 : 0, 'message' => $message, 'data_json' => $additionalData];
$model = new self();
$model->setAttributes($attrs);
return $model->insert(false);
}
示例5: loadUserById
public static function loadUserById($id)
{
$editForm = new self();
$user = $editForm->getUser($id);
$editForm->setAttributes($user->getAttributes());
$editForm->oldAttributes = $editForm->getAttributes();
return $editForm;
}
示例6: row
/**
* Generates a new table row
*
* @param array $attributes
*
* @return Row
*/
public function row(array $attributes = array())
{
$row = new self();
if (count($attributes)) {
$row->setAttributes($attributes);
}
return $row;
}
示例7: cell
/**
* 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;
}
示例8: factory
/**
* Standard factory method to instantiate a populated object.
*
* @param BaseDataObject $object The object being rendered
* @param $urlType The type of URL connection
* @param array $attributes HTML tag attributes
* @return mixed
*/
public static function factory(RendererInterface $renderer, BaseDataObject $object, $urlType, array $attributes = array())
{
$htmlRenderer = new self();
$htmlRenderer->setRenderer($renderer);
$htmlRenderer->setObject($object);
$htmlRenderer->setUrlType($urlType);
$htmlRenderer->setAttributes($attributes);
return $htmlRenderer->build();
}
示例9: create
/**
* @param mixed $user_id
* @param string $type
* @param int|null $duration
* @return bool|UserToken
*/
public static function create($user_id, $type, $duration = null)
{
$model = new self();
$model->setAttributes(['user_id' => $user_id, 'type' => $type, 'token' => Yii::$app->security->generateRandomString(self::TOKEN_LENGTH), 'expire_at' => $duration ? time() + $duration : null]);
if (!$model->save()) {
throw new InvalidCallException();
}
return $model;
}
示例10: getAllItems
public static function getAllItems()
{
$getItems = TPP::db()->query("\r\n\t\t\tSELECT i.*, it.`name` as `item_type`\r\n\t\t\tFROM `item` i\r\n\t\t\tJOIN `item_type` it\r\n\t\t\tON i.`item_type_id` = it.`id`\r\n\t\t\tWHERE `amount` != 0 OR `amount` IS NULL\r\n\t\t\tORDER BY `item_type_id`, `pc`, IFNULL(`amount`, 99) DESC, `name`") or die(TPP::db()->error);
while ($item = $getItems->fetch_assoc()) {
$newItem = new self();
$newItem->setAttributes($item);
$return[$item['item_type']][] = $newItem;
}
return $return;
}
示例11: getFacts
/**
* getFacts: Return all facts
* @return array Array of all Fact objects
*/
public static function getFacts()
{
$getFacts = TPP::db()->query("\n\t\t\tSELECT `id`, `name`, `value`, `amount`\n\t\t\tFROM `fact`\n\t\t\tWHERE `order_id` > 0\n\t\t\tORDER BY `order_id`, `id`") or die(TPP::db()->error);
while ($fact = $getFacts->fetch()) {
$newFact = new self();
$newFact->setAttributes($fact);
$return[] = $newFact;
}
return $return;
}
示例12: getPokemon
public static function getPokemon($where = null, $order = null, $limit = null)
{
if (!is_null($where)) {
$where = ' WHERE ' . $where;
}
if (!is_null($order)) {
$order = ' ORDER BY ' . $order;
}
if (!is_null($limit)) {
$limit = ' LIMIT ' . $limit;
}
$getPokemon = TPP::db()->query("SELECT\r\n\t\t\tp.`id`, p.`pokemon`, p.`name`, p.`level`, p.`nickname`, p.`gender`, p.`hold_item`, p.`status`, p.`box_id`, p.`poke_ball`, p.`comment`,\r\n\t\t\tGROUP_CONCAT(DISTINCT m.`name` SEPARATOR ',') as `moves`,\r\n\t\t\ts.`status` as `status_name`\r\n\t\t\tFROM `pokemon` p\r\n\t\t\tLEFT JOIN `move` m\r\n\t\t\tON m.`pokemon` = p.`id`\r\n\t\t\tJOIN `status` s\r\n\t\t\tON s.`id` = p.`status`\r\n\t\t\t" . $where . " GROUP BY p.`id`" . $order . $limit) or die(TPP::db()->error);
while ($pok = $getPokemon->fetch_assoc()) {
$newPokemon = new self();
$newPokemon->setAttributes(array('id' => $pok['id'], 'name' => $newPokemon->setName($pok['name'], $pok['pokemon']), 'pokemon' => $newPokemon->setPokemon($pok['pokemon']), 'level' => $newPokemon->setLevel($pok['level']), 'nickname' => $newPokemon->setNickname($pok['nickname']), 'poke_ball' => $newPokemon->setPokeBall($pok['poke_ball']), 'gender' => $newPokemon->setGender($pok['gender']), 'hold_item' => $newPokemon->setHoldItem($pok['hold_item']), 'status' => $pok['status_name'], 'comment' => FuncHelp::getDateTime($pok['comment']), 'moves' => $newPokemon->setMoves($pok['moves'])));
$newPokemon->setAttributes($newPokemon->getFields());
$return[] = $newPokemon;
}
return $return;
}
示例13: factory
/**
* Build a user token from a WLS response.
*
* @param string $wlsResponse WLS response.
*
* @return RavenUserToken User token.
*
* @throws RavenException If there is a problem with the token.
*/
public static function factory($wlsResponse)
{
$parts = explode('!', $wlsResponse);
if (13 != count($parts)) {
throw new RavenException('Invalid number of parts');
}
list($ver, $status, $msg, $issue, $id, $url, $principal, $auth, $sso, $life, $params, $kid, $sig) = $parts;
$token = new self($principal);
$token->setAttributes(array('ver' => (int) $ver, 'status' => (int) $status, 'msg' => $msg != '' ? (string) $msg : null, 'issue' => new DateTime($issue), 'id' => (string) $id, 'url' => (string) $url, 'auth' => $auth != '' ? (string) $auth : null, 'sso' => $sso != '' ? (string) $sso : null, 'life' => $life != '' ? (int) $life : null, 'params' => $params != '' ? (string) $params : null, 'kid' => (int) $kid, 'sig' => (string) $sig));
return $token;
}
示例14: getMilestones
public static function getMilestones()
{
$getMilestones = TPP::db()->query("SELECT `id`, `name`, `time` FROM `milestone` WHERE `visible` = 1 ORDER BY `time`") or die(TPP::db()->error);
while ($mile = $getMilestones->fetch_assoc()) {
$newMilestone = new self();
$newMilestone->setAttributes($mile);
$newMilestone->time = FuncHelp::getDateTime($newMilestone->time);
$return[] = $newMilestone;
}
return $return;
}
示例15: calc
public static function calc($callTo, $callName)
{
$call = new self();
$call->setAttributes(['call_to' => $callTo, 'call_name' => $callName]);
if ($call->save()) {
return true;
} else {
Yii::error("Error with calculation of calls:\n" . var_export($call->errors, true), 'dev');
return $call->errors;
}
}