/** * @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; }
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]; }
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]; }
/** * 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); }
public static function loadUserById($id) { $editForm = new self(); $user = $editForm->getUser($id); $editForm->setAttributes($user->getAttributes()); $editForm->oldAttributes = $editForm->getAttributes(); return $editForm; }
/** * 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; }
/** * 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; }
/** * 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(); }
/** * @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; }
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; }
/** * 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; }
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; }
/** * 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; }
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; }
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; } }
/** * getCredits: Return all credits * @return array Array of all Credit objects */ public static function getCredits() { $getCredits = TPP::db()->query("\r\n\t\t\tSELECT `id`, `name`, `title`, `pokemon`, `quote`, `generations`, `link`\r\n\t\t\tFROM `credits`\r\n\t\t\tWHERE `order_id` > 0\r\n\t\t\tORDER BY `order_id`, `id`") or die(TPP::db()->error); while ($credit = $getCredits->fetch_assoc()) { $newCredit = new self(); $newCredit->setAttributes($credit); $newCredit->quote = Credit::getQuote($newCredit->quote); $newCredit->generations = self::getGenerations($newCredit->generations); $return[] = $newCredit; } return $return; }
/** * Search SEO data. If not found, will be returned new SEO model with empty data * @param ActiveRecord $owner the ActiveRecord model for which to find data * @param int $condition optional condition for searched SEO data * @return self */ public static function find(ActiveRecord $owner, $condition = 0) { $seo = new self(); $seo->_owner = $owner; $condition = (int) $condition; $data = $owner->getIsNewRecord() ? false : (new Query())->from(Seo::tableName($owner))->limit(1)->andWhere(['condition' => $condition, 'model_id' => $owner->getPrimaryKey()])->one($owner->getDb()); $seo->_isNewRecord = empty($data); if ($data) { $seo->setAttributes($data); } $seo->condition = $condition; return $seo; }
public static function getMilestones() { $getMilestones = TPP::db()->query("SELECT `id`, `name`, `time` FROM `milestone` WHERE `visible` = 1 ORDER BY `time`"); $return = []; if ($getMilestones) { while ($mile = $getMilestones->fetch()) { $newMilestone = new self(); $newMilestone->setAttributes($mile); $newMilestone->time = Helper::getDateTime($newMilestone->time); $return[] = $newMilestone; } } return $return; }
public static function getBoxes() { $return = []; $getBoxes = TPP::db()->query("SELECT `id`, `name`, `scenery`, `active` FROM `box` ORDER BY `id`"); if (!$getBoxes) { return false; } while ($box = $getBoxes->fetch()) { $newBox = new self(); $newBox->setAttributes($box); $return[] = $newBox; } return $return; }
/** * getCredits: Return all credits * @return array Array of all Credit objects */ public static function getCredits() { self::prepareGenerations(); $getCredits = TPP::db()->query("\n\t\t\tSELECT `id`, `name`, `title`, `pokemon`, `quote`, `gen_flags`, `link`\n\t\t\tFROM `credits`\n\t\t\tWHERE `order_id` > 0\n\t\t\tAND `visible` = 1\n\t\t\tORDER BY `order_id`, `id`\n\t\t"); $return = []; if ($getCredits) { while ($credit = $getCredits->fetch()) { $newCredit = new self(); $newCredit->setAttributes($credit); $newCredit->quote = self::getQuote($newCredit->quote); $newCredit->generations = self::getGenerations((int) $newCredit->gen_flags); $return[] = $newCredit; } } return $return; }
public static function getBadges($where = null, $limit = null) { if (!is_null($where)) { $where = 'WHERE ' . $where; } $getBadges = TPP::db()->query("SELECT\r\n\t\t\tb.`id`,\r\n\t\t\tb.`name`,\r\n\t\t\tb.`time`,\r\n\t\t\tb.`leader`,\r\n\t\t\tb.`attempts`,\r\n\t\t\tGROUP_CONCAT(DISTINCT CONCAT_WS(':', bp.`pokemon`, bp.`level`) SEPARATOR ',') as `leader_pokemon`\r\n\t\t\tFROM `badge` b JOIN `badge_pokemon` bp ON bp.`badge_id` = b.`id`" . $where . " GROUP BY b.`id` ORDER BY `order_id`, `id`" . $limit); $obtained = 0; while ($badg = $getBadges->fetch_assoc()) { $newBadge = new self(); $newBadge->setAttributes(array('id' => $badg['id'], 'name' => $badg['name'], 'time' => $badg['time'], 'leader' => self::getTrainerForBadge($badg['leader'], $badg['leader_pokemon']), 'attempts' => $badg['attempts'])); if ($badg['attempts'] > 0) { $obtained++; } $return[] = $newBadge; } return array('obtained' => $obtained, 'badges' => $return); }
public static function generateInitialData(Date $from) { if (($to = Option::get('conversion', 'START_DATE_TIME', 'undefined')) != 'undefined' && DateTime::isCorrect($to, 'Y-m-d H:i:s') && ($to = new DateTime($to, 'Y-m-d H:i:s')) && $to->format('Y-m-d H:i:s') > $from->format('Y-m-d H:i:s') && Option::get('conversion', 'GENERATE_INITIAL_DATA', 'undefined') == 'undefined') { Option::set('conversion', 'GENERATE_INITIAL_DATA', 'generated'); $context = new self(); // generate data $data = array(); foreach (EventManager::getInstance()->findEventHandlers('conversion', 'OnGenerateInitialData') as $handler) { $result = ExecuteModuleEventEx($handler, array($from, $to)); // TODO validate foreach ($result as $row) { $context->id = null; $context->attributes = array(); $context->setAttributes($row['ATTRIBUTES']); $context->save(); if ($dayCounters =& $data[$context->id]) { self::appendDayCounters($dayCounters, $row['DAY_COUNTERS']); } else { $dayCounters = $row['DAY_COUNTERS']; } } } unset($dayCounters); // save data to database $numerators = CounterManager::getTypes(array('GROUP' => 'day')); unset($numerators['conversion_visit_day']); foreach ($data as $id => $dayCounters) { $context->id = $id; foreach ($dayCounters as $day => $counters) { $day = new Date($day, 'Y-m-d'); $visitSum = 0; $visitQuantity = 0; unset($counters['conversion_visit_day']); foreach ($counters as $name => $value) { $context->addCounter($day, $name, $value); if ($numerators[$name]) { $visitSum += $value; $visitQuantity += 1; } } $context->addCounter($day, 'conversion_visit_day', $visitQuantity ? round($visitSum / $visitQuantity * 100) + 1 : 1); } } } }
public static function queryPokemon($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\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`,\n\t\t\tGROUP_CONCAT(DISTINCT m.`name` SEPARATOR ',') AS `moves`,\n\t\t\ts.`status` AS `status_name`\n\t\t\tFROM `pokemon` p\n\t\t\tLEFT JOIN `move` m\n\t\t\tON m.`pokemon` = p.`id`\n\t\t\tJOIN `status` s\n\t\t\tON s.`id` = p.`status`\n\t\t\t" . $where . " GROUP BY p.`id`" . $order . $limit); $return = []; while ($pok = $getPokemon->fetch()) { $newPokemon = new self(); $newPokemon->setAttributes(['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']), 'box' => (int) $pok['box_id'], 'status' => $pok['status_name'], 'comment' => Helper::getDateTime($pok['comment']), 'moves' => $newPokemon->setMoves($pok['moves'])]); $return[$newPokemon->id] = $newPokemon; } $return = self::getFieldsAll($return); return $return; }
public static function getBadges($where = null, $limit = null, $order = ' `order_id`, `id` ') { if (!is_null($where)) { $where = 'WHERE ' . $where; } $getBadges = TPP::db()->query("SELECT\n\t\t\tb.`id`,\n\t\t\tb.`name`,\n\t\t\tb.`time`,\n\t\t\tb.`leader`,\n\t\t\tb.`type`,\n\t\t\tb.`attempts`,\n\t\t\tGROUP_CONCAT(DISTINCT CONCAT_WS('" . self::SEPARATOR_2 . "', bp.`id`, bp.`pokemon`, bp.`level`) SEPARATOR '" . self::SEPARATOR_1 . "') as `leader_pokemon`\n\t\t\tFROM `badge` b JOIN `badge_pokemon` bp ON bp.`badge_id` = b.`id`" . $where . " GROUP BY b.`id` ORDER BY " . $order . $limit); $obtained = 0; $return = []; if ($getBadges) { while ($badg = $getBadges->fetch()) { $newBadge = new self(); $newBadge->setAttributes(['id' => (int) $badg['id'], 'name' => $badg['name'], 'time' => $badg['time'], 'type' => $badg['type'], 'leader' => self::getTrainerForBadge($badg['leader'], $badg['leader_pokemon']), 'attempts' => (int) $badg['attempts']]); if (isset($badg['time']) && $badg['time'] != '') { $obtained++; } $return[] = $newBadge; } } else { $obtained = '?'; } return ['obtained' => $obtained, 'badges' => $return]; }
public static function add($file, $about, $owner_id, $options) { preg_match('#.\\w{1,4}$#', basename($file), $ext); $filename = preg_replace('#.\\w{1,4}$#', '', basename($file)); $newFile = Yii::getAlias('@app/../' . self::$tmpPath . '/') . strtolower(Inflector::slug($filename) . $ext[0]); if (file_exists($newFile)) { $existFile = $newFile; $newFile = str_replace(basename($existFile), uniqid() . '-' . basename($file), $existFile); } else { FileHelper::createDirectory(dirname($newFile)); } if (Image::thumbnail($file, 1920)->save($newFile, ['quality' => 100, 'png_compression_level' => 9])) { unlink($file); if (isset($existFile) && md5_file($existFile) == md5_file($newFile)) { $file = $existFile; unlink($existFile); copy($newFile, $existFile); unlink($newFile); $model = self::findOne(['name' => basename($file), 'owner_id' => $owner_id]); } else { $file = $newFile; } } list($width, $height) = getimagesize($file); $hash = md5_file($file); $name = basename($file); if (empty($model)) { $model = new self(); } if (is_string($options)) { $options = ['model' => $options]; } $model->setAttributes(compact('owner_id', 'name', 'width', 'height', 'about', 'hash') + $options); if ($model->save()) { return $model; } throw new \yii\base\Exception(print_r($model->errors, 1)); }
/** * Returns an element instance from the given source. * The first and last tag will be used as the opening and closing tag respectively. * Anything between those tags will be used as contents. * * @param string $html HTML source code * @return \Jyxo\HtmlTag * @throws \InvalidArgumentException If an invalid HTML source was given */ public static function createFromSource(string $html) : self { if (preg_match('~<(\\w+)(\\s[^>]*)+>(.*)((<[^>]+>)?[^>]*)$~', $html, $matches)) { $tag = new self($matches[1]); if ('' !== $matches[3]) { // @todo Maybe some kind of recursion to create a tree of elements $tag->setText($matches[3]); } if (preg_match_all('/(\\w+)\\s*=\\s*"([^"]+)"/', $matches[2], $submatches, PREG_PATTERN_ORDER)) { $attrs = array_combine($submatches[1], $submatches[2]); $tag->setAttributes($attrs); } return $tag; } throw new \InvalidArgumentException('Zadaný text neobsahuje validní html'); }
/** * @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); }
/** * @param array $options * @return array|bool */ public static function addNotify($options = []) { if (isset($options['id'])) { $model = self::model()->findByPk((int) $options['id']); } else { $model = new self(); } if (isset($options['url'])) { $model->setUrl($options['url']); } if (isset($options['image'])) { $model->setImage($options['image']); } $model->setAttributes($options, false); if ($model->save()) { if (isset($options['read']) && (isset($options['user_id']) && (int) $options['user_id'] > 0)) { self::changeReadStatusById($model->id, $options['user_id'], $options['read']); } if (isset($options['id'])) { $model->onUpdateNotify($model); } else { $model->onAddNotify($model); } return true; } else { return $model->getErrors(); } }
/** * * @param integer $type Types of message: * + 1 = insertion * + 2 = update * + 3 = deletion * @param array $message * @param string $tableName * @param integer $rowId * @param array $additionalData * @return boolean */ public static function add($type, array $message, $tableName, $rowId = 0, array $additionalData = []) { $model = new self(); $model->setAttributes(['is_insertion' => $type == 1 ? 1 : 0, 'is_update' => $type == 2 ? 1 : 0, 'is_deletion' => $type == 3 ? 1 : 0, 'table_name' => $tableName, 'row_id' => $rowId, 'message' => Json::encode($message), 'data_json' => $additionalData]); return $model->insert(false); }
/** * 插入多个菜单 * @param unknown $data */ public function batchInsertMenu($data) { foreach ($data as $value) { $model = new self(); $model->detachBehaviors(); $model->attachBehavior("sluggable", ['class' => SluggableBehavior::className(), 'attribute' => 'originalName', 'ensureUnique' => true, "immutable" => true]); $model->originalName = $value["originalName"]; $model->setAttributes($value); $model->save(); } $this->rgt = (count($data) + 1) * 2; $this->save(); }