/** * Crea il blocco HTML standard coni dati di creazione/modifica e il pulsante di eliminazione: * * <p class="created">Creat... il ... da <strong>...</strong></p><br /> * <p><br /> * <form id="...-delete-form" action="..." method="post"><br /> * <input type="hidden" name="_csrf" value="..."><br /> * <input type="hidden" name="Delete...[...]" value="..."><br /> * <a class="btn btn-danger" href="/"><i class="fa fa-trash-o"></i> ...</a><br /> * </form><br /> * </p> * * La form ha id "{nome classe minuscolo}-delete-form", il campo nascosto ha nome "{nome classe}[{nome campo pk}]" * e valore della chiave primaria del modello. * * @param string $pkField Nome del campo pk del modello * @param string $buttonLabel Testo del pulsante di eliminazione * @param boolean $isFemale True per indicare che l'oggetto è al femminile * @return string Blocco HTML */ public function getCreatedUpdatedBlock($pkField, $buttonLabel, $isFemale = false) { if ($this->isNewRecord) { return; } return $this->getCreatedUpdatedParagraph($isFemale) . \PHP_EOL . Html::beginTag('p') . \PHP_EOL . Html::beginForm('', 'post', ['id' => strtolower($this->formName()) . '-delete-form']) . \PHP_EOL . Html::hiddenInput("Delete{$this->formName()}[{$pkField}]", $this->{$pkField}) . \PHP_EOL . Html::faa('trash-o', $buttonLabel, ['/'], ['class' => 'btn btn-danger']) . \PHP_EOL . Html::endForm() . \PHP_EOL . Html::endTag('p'); }
public function run() { echo Html::beginTag('div', ['class' => 'workinprogress']); echo Html::img("/{$this->folder}/{$this->image}", ['alt' => 'work-in-progress.png']); if ($this->message) { echo Html::tag('p', $this->message, ['class' => 'workinprogress-message']); } echo Html::endTag('div'); }
/** * Partendo dall'oggetto che la Api Twitter restituisce per ogni tweet, verifica in base alla proprietà <code>id_str</code> * se il tweet è già presente nel database. In caso affermativo restituisce true, altrimenti inserisce in nuovo record * nel database e lo restituisce. * @param mixed $data Oggetto del tweet restituito dalla Api Twitter * @return mixed True se il tweet è già presente nel database, altrimenti nuovo record creato */ public static function CreateFromObj($data) { $tweet = self::find()->where('id_str=:idstr', [':idstr' => $data->id_str])->one(); if (!$tweet) { # Nuovo tweet: lo inserisco nel database $tweet = new TwitterTweet(); $tweet->id_str = $data->id_str; $tweet->created = date('Y-m-d H:i:s', strtotime($data->created_at)); $text = trim(str_replace('#' . Yii::$app->twitter->hashtag, '<span class="hashtag">#' . Yii::$app->twitter->hashtag . '</span>', $data->text)); $urls = $data->entities->urls; if (is_array($urls)) { foreach ($urls as $url) { $text = str_replace($url->url, Html::a($url->display_url, $url->expanded_url, array('target' => 'blank')), $text); } } $tweet->text = $text; $tweet->save(); $tweet->refresh(); return $tweet; } return true; }