/**
  * Creates a new Participant model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate($meeting_id)
 {
     $mtg = new Meeting();
     $title = $mtg->getMeetingTitle($meeting_id);
     $model = new Participant();
     $model->meeting_id = $meeting_id;
     $model->invited_by = Yii::$app->user->getId();
     // load friends for auto complete field
     $friends = Friend::getFriendList(Yii::$app->user->getId());
     if ($model->load(Yii::$app->request->post())) {
         if (!User::find()->where(['email' => $model->email])->exists()) {
             // if email not already registered
             //  create new user with temporary username & password
             $temp_email_arr[] = $model->email;
             $model->username = Inflector::slug(implode('-', $temp_email_arr));
             $model->password = Yii::$app->security->generateRandomString(12);
             $model->participant_id = $model->addUser();
         } else {
             // add participant from user record
             $usr = User::find()->where(['email' => $model->email])->one();
             $model->participant_id = $usr->id;
         }
         // validate the form against model rules
         if ($model->validate()) {
             // all inputs are valid
             $model->save();
             return $this->redirect(['/meeting/view', 'id' => $meeting_id]);
         } else {
             // validation failed
             return $this->render('create', ['model' => $model, 'title' => $title, 'friends' => $friends]);
         }
     } else {
         return $this->render('create', ['model' => $model, 'title' => $title, 'friends' => $friends]);
     }
 }
Example #2
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if (!$this->id) {
         $this->id = Inflector::slug($this->label);
     }
 }
Example #3
0
 public function getDetailUrl($contextNavItemId = null)
 {
     if ($contextNavItemId) {
         return \luya\helpers\Url::toModule($contextNavItemId, 'gallery/album/index', ['albumId' => $this->id, 'title' => \yii\helpers\Inflector::slug($this->title)]);
     }
     return \luya\helpers\Url::to('gallery/album/index', ['albumId' => $this->id, 'title' => \yii\helpers\Inflector::slug($this->title)]);
 }
Example #4
0
 public function getDetailUrl($contextNavItemId = null)
 {
     if ($contextNavItemId) {
         return \cms\helpers\Url::toMenuItem($contextNavItemId, 'news/default/detail', ['id' => $this->id, 'title' => \yii\helpers\Inflector::slug($this->title)]);
     }
     return \luya\helpers\Url::toManager('news/default/detail', ['id' => $this->id, 'title' => \yii\helpers\Inflector::slug($this->title)]);
 }
 public function up()
 {
     $this->addColumn('{{%topic}}', 'slug', Schema::TYPE_STRING . ' NOT NULL');
     $topics = (new Query())->select('id, title')->from('{{%topic}}')->all();
     foreach ($topics as $topic) {
         $this->update('{{%topic}}', array('slug' => Inflector::slug($topic['title'])), 'id = :id', array(':id' => $topic['id']));
     }
 }
Example #6
0
 public function run()
 {
     $alias = Inflector::slug(Yii::$app->request->post('name'));
     // if ($this->checkCommand->bindValues([':alias'=> $alias])->queryScalar() === false) {
     //}
     Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     return ['alias' => $alias, 'code' => 100];
 }
Example #7
0
 public function testSlug()
 {
     $data = ['Привет. Hello, Йии-- Framework !--- Как дела ? How it goes ?' => 'privet-hello-jii-framework-kak-dela-how-it-goes', 'this is a title' => 'this-is-a-title', 'недвижимость' => 'nedvizimost', 'áàâéèêíìîóòôúùûã' => 'aaaeeeiiiooouuua', 'Ναδάλης ṃỹṛèşưḿĕ' => 'nadales-myresume', 'E=mc²' => 'e-mc2', '載å¥' => 'e14a'];
     foreach ($data as $source => $expected) {
         $this->assertEquals($expected, Inflector::slug($source));
     }
     //$this->assertEquals('this-is-my-text-', Inflector::slug('! this is my / text $## '));
 }
Example #8
0
 private function slugify($slug)
 {
     if ($this->translit) {
         return Inflector::slug(TransliteratorHelper::process($slug), '-', true);
     } else {
         return $this->slug($slug, '-', true);
     }
 }
Example #9
0
 /**
  * @inheritDoc
  */
 protected function renderHeadline($block)
 {
     $content = $this->parseInline($block['content']);
     $hash = Inflector::slug(strip_tags($content));
     $hashLink = "<a href=\"#{$hash}\" name=\"{$hash}\" class=\"hashlink\">&para;</a>";
     $tag = 'h' . $block['level'];
     return "<{$tag}>{$content} {$hashLink}</{$tag}>";
 }
Example #10
0
 public function run()
 {
     $text = Yii::$app->request->post('text');
     $translateText = Yii::$app->translate->translate($text, 'en');
     $result[] = Inflector::slug($text);
     $result[] = Inflector::slug($translateText);
     return json_encode($result);
 }
Example #11
0
 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     return [TimestampBehavior::className(), ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'alias'], 'value' => function ($event) {
         return Inflector::slug($event->sender->title);
     }], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_AFTER_FIND => 'body'], 'value' => function ($event) {
         return HtmlPurifier::process(Markdown::process($event->sender->content, 'gfm'));
     }]];
 }
Example #12
0
 static function getFileName($fileInstanse, $namePostfix = true)
 {
     $baseName = str_ireplace('.' . $fileInstanse->extension, '', $fileInstanse->name);
     $fileName = StringHelper::truncate(Inflector::slug($baseName), 32, '');
     if ($namePostfix || !$fileName) {
         $fileName .= ($fileName ? '-' : '') . substr(uniqid(md5(rand()), true), 0, 10);
     }
     $fileName .= '.' . $fileInstanse->extension;
     return $fileName;
 }
Example #13
0
 public function validateName($attribute)
 {
     $name = Inflector::camelize(Inflector::slug($this->{$attribute}));
     $label = $this->getAttributeLabel($attribute);
     if (empty($name)) {
         $this->addError($attribute, "'{$label}' должно состоять только из букв и цифр");
     } else {
         $this->{$attribute} = $name;
     }
 }
Example #14
0
 /**
  * Initializes the module.
  */
 public function init()
 {
     if (is_null($this->cronGroup)) {
         $this->cronGroup = Inflector::slug(Yii::$app->id . '-' . Yii::getAlias('@app'));
     } else {
         $this->cronGroup = Inflector::slug($this->cronGroup);
     }
     $this->setComponents([$this->nameComponent => ['class' => 'gofmanaa\\crontask\\components\\Crontab', 'filename' => $this->fileName, 'directory' => $this->fileDir, 'crontabPath' => $this->crontabPath, 'cronGroup' => $this->cronGroup]]);
     parent::init();
 }
Example #15
0
 public function getFileName()
 {
     if (!$this->_fileName) {
         $fileName = substr(uniqid(md5(rand()), true), 0, 10);
         $fileName .= '-' . Inflector::slug($this->file->baseName);
         $fileName .= '.' . $this->file->extension;
         $this->_fileName = $fileName;
     }
     return $this->_fileName;
 }
Example #16
0
 /**
  * @param string $word
  * @return string
  */
 public static function slug($word)
 {
     if (is_array($word)) {
         $word = array_shift($word);
     }
     if (isset(static::$aliases[$word])) {
         return static::$aliases[$word];
     }
     return Inflector::slug($word);
 }
Example #17
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return [[['id', 'created_at', 'updated_at', 'created_by', 'updated_by', 'lock'], 'integer'], [['title'], 'string', 'max' => 1024], [['alias'], 'filter', 'filter' => 'trim'], [['alias'], 'filter', 'filter' => function ($value) {
         if (empty($value)) {
             return Inflector::slug(TransliteratorHelper::process($this->title));
         } else {
             return Inflector::slug($value);
         }
     }], [['alias'], 'unique'], [['alias'], 'required', 'enableClientValidation' => false], [['alias', 'note'], 'string', 'max' => 255]];
 }
 /**
  * Sets url parts array
  * @param $itemsType string invitations or actualities
  */
 public function setMenuUrlParts($itemsType)
 {
     $sql = "SELECT menu_item.id,menu_item.title AS name FROM category, menu_item_content, menu_item WHERE category.id=:id AND category.id=menu_item_content.category_id AND menu_item_content.menu_item_id=menu_item.id";
     $query = Yii::$app->db->createCommand($sql);
     $query->bindValue(':id', $this->{$itemsType . 'CategoryId'});
     $urlParts = $query->queryOne();
     if (isset($urlParts['name'])) {
         $urlParts['name'] = Inflector::slug(strip_tags($urlParts['name']));
     }
     $this->{'_' . $itemsType . 'MenuUrlParts'};
 }
Example #19
0
 /**
  * Gets menu url parts for given article
  * @param $articleId
  * @return array|bool
  */
 public static function getMenuUrlParts($articleId)
 {
     $sql = "SELECT menu_item.id,menu_item.title AS name FROM content, article_category, category, menu_item_content, menu_item WHERE content.id=:id AND content.id=article_category.article_id AND article_category.category_id=category.id AND category.id=menu_item_content.category_id AND menu_item_content.menu_item_id=menu_item.id";
     $query = \Yii::$app->db->createCommand($sql);
     $query->bindValue(':id', $articleId);
     $urlParts = $query->queryOne();
     if (isset($urlParts['name'])) {
         $urlParts['name'] = Inflector::slug(strip_tags($urlParts['name']));
     }
     return $urlParts;
 }
Example #20
0
 private function getFileName($image)
 {
     $imageFileType = strtolower(pathinfo($image->name, PATHINFO_EXTENSION));
     $fileName = Inflector::slug(str_replace($imageFileType, '', $image->name), '_');
     if ($this->useHash) {
         $fileName = hash('md5', Yii::getAlias($fileName));
         $rand = rand(10000, 99999);
         return $rand . '_' . $fileName . '.' . $imageFileType;
     } else {
         return $fileName . '.' . $imageFileType;
     }
 }
 /**
  * Copies the image to the assets folder and save's it in the database.
  *
  * @param   string  $absolutePath   The path were the image is uploaded   
  * @param   bool    $isMain         A flag to determine if the image is the main image
  * @param   string  $identifier     The index that has to be set for the image in the database
  * @return  bool|Image
  * @throws  \Exception
  */
 public function attachImage($absolutePath, $isMain = false, $identifier = '')
 {
     if (!preg_match('#http#', $absolutePath)) {
         if (!file_exists($absolutePath)) {
             throw new \Exception('File not exist! :' . $absolutePath);
         }
     } else {
         //nothing
     }
     if (!$this->owner->primaryKey) {
         throw new \Exception('Owner must have primaryKey when you attach image!');
     }
     $pictureFileName = basename($absolutePath);
     $pictureSubDir = $this->getModule()->getModelSubDir($this->owner);
     $storePath = $this->getModule()->getStorePath($this->owner);
     $newAbsolutePath = $storePath . DIRECTORY_SEPARATOR . $pictureSubDir . DIRECTORY_SEPARATOR . $pictureFileName;
     BaseFileHelper::createDirectory($storePath . DIRECTORY_SEPARATOR . $pictureSubDir, 0775, true);
     copy($absolutePath, $newAbsolutePath);
     unlink($absolutePath);
     if (!file_exists($newAbsolutePath)) {
         throw new \Exception('Cant copy file! ' . $absolutePath . ' to ' . $newAbsolutePath);
     }
     $image = new Image();
     $image->itemId = $this->owner->primaryKey;
     $image->filePath = $pictureSubDir . '/' . $pictureFileName;
     $image->modelName = $this->getModule()->getShortClass($this->owner);
     $image->urlAlias = $this->getAlias($image);
     $image->identifier = $identifier;
     $image->name = substr(yii\helpers\Inflector::slug($pictureFileName), 0, -3);
     // Get the highest position
     // @todo Create function
     $owner = $this->owner;
     $query = (new yii\db\Query())->select('MAX(`position`)')->from(Image::tableName())->where(['modelName' => yii\helpers\StringHelper::basename($owner::className())]);
     $command = $query->createCommand();
     $image->position = $command->queryOne(\PDO::FETCH_COLUMN) + 1;
     if (!$image->save()) {
         return false;
     }
     // Add the translations
     foreach (Yii::$app->params['languages'] as $language => $data) {
         $imageLang = new ImageLang();
         $imageLang->language = $language;
         $image->link('translations', $imageLang);
     }
     if (count($image->getErrors()) > 0) {
         $ar = array_shift($image->getErrors());
         unlink($newAbsolutePath);
         throw new \Exception(array_shift($ar));
     }
     $img = $this->owner->getImage();
     $this->setMainImage($image);
     return $image;
 }
Example #22
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return [[['title', 'status'], 'required'], [['status', 'created_at', 'updated_at', 'created_by', 'updated_by', 'hits', 'lock'], 'integer'], [['title'], 'string', 'max' => 100], [['group'], 'filter', 'filter' => function ($value) {
         // если во вьюхе используется select2, отфильтровываем значение из массива [0 => 'значение'] -> 'значение'
         return is_array($value) ? reset($value) : $value;
     }], [['alias', 'group', 'metakey'], 'string', 'max' => 255], [['metadesc'], 'string', 'max' => 2048], [['alias'], 'filter', 'filter' => 'trim'], [['alias'], 'filter', 'filter' => function ($value) {
         if (empty($value)) {
             return Inflector::slug(TransliteratorHelper::process($this->title));
         } else {
             return Inflector::slug($value);
         }
     }], [['alias'], 'unique'], [['alias'], 'required', 'enableClientValidation' => false]];
 }
Example #23
0
 public function generateSlug()
 {
     if (empty($this->owner->{$this->slugAttributeName}) && !empty($this->owner->{$this->sourceAttributeName})) {
         $slug = Inflector::slug($this->owner->{$this->sourceAttributeName}, $this->replacement, $this->lowercase);
         $this->owner->{$this->slugAttributeName} = $slug;
         if ($this->unique) {
             $suffix = 1;
             while (!$this->uniqueCheck()) {
                 $this->owner->{$this->slugAttributeName} = $slug . $this->replacement . ++$suffix;
             }
         }
     }
 }
 public function up()
 {
     $this->addColumn('{{%category}}', 'slug', Schema::TYPE_STRING . ' NOT NULL');
     $this->addColumn('{{%section}}', 'slug', Schema::TYPE_STRING . ' NOT NULL');
     $categories = (new Query())->select('id, title')->from('{{%category}}')->all();
     foreach ($categories as $category) {
         $this->update('{{%category}}', array('slug' => Inflector::slug($category['title'])), 'id = :id', array(':id' => $category['id']));
     }
     $sections = (new Query())->select('id, title')->from('{{%section}}')->all();
     foreach ($sections as $section) {
         $this->update('{{%section}}', array('slug' => Inflector::slug($section['title'])), 'id = :id', array(':id' => $section['id']));
     }
 }
Example #25
0
 private function generatePosts()
 {
     $count = mt_rand(300, 500);
     Console::startProgress(0, $count, 'Generating posts: ');
     $sectionIds = (new Query())->select('id')->from('{{%section}}')->where('section_id IS NOT NULL')->column($this->getDb());
     $authorIds = (new Query())->select('id')->from('{{%user}}')->column($this->getDb());
     for ($i = 1; $i <= $count; ++$i) {
         $title = rtrim($this->getFaker()->sentence(mt_rand(3, 10)), '.');
         $this->getDb()->createCommand()->insert('{{%post}}', ['title' => $title, 'slug' => Inflector::slug($title), 'section_id' => $sectionIds[array_rand($sectionIds)], 'author_id' => $authorIds[array_rand($authorIds)], 'text' => implode("\n\n", $this->getFaker()->paragraphs(mt_rand(1, 5))), 'created_at' => time(), 'updated_at' => time()])->execute();
         Console::updateProgress($i, $count);
     }
     Console::endProgress();
 }
Example #26
0
 /**
  * Generate new slug name according to article title or custom name. If
  * provided string existed, it will attach next order automatically.
  * @param string $title article title or custom name.
  * @return string new slug name.
  */
 public static function generateNewSlugName($title)
 {
     $counter = 0;
     $suffix = '';
     do {
         $name = Inflector::slug($title);
         if ($counter) {
             $suffix = '-' . $counter;
         }
         $name .= $suffix;
         $counter++;
     } while (static::checkSlugNameExists($name));
     return $name;
 }
Example #27
0
 protected function normalizeFilename()
 {
     if (!$this->_filename) {
         $extensionName = $this->getExtensionName();
         if (!empty($extensionName)) {
             $name = Inflector::slug(preg_replace('/\\..*?$/', '', strtolower($this->file)));
             $name .= $extensionName;
         } else {
             $name = strtolower($this->file);
         }
         $this->_filename = substr(uniqid(md5(rand()), true), 0, 10) . '.' . $name;
     }
     return $this->_filename;
 }
Example #28
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return [[['title', 'detail_text', 'status'], 'required'], [['preview_text', 'detail_text'], 'string'], [['detail_text'], 'filter', 'filter' => 'yii\\helpers\\HtmlPurifier::process'], [['parent_id', 'created_at', 'updated_at', 'status', 'created_by', 'updated_by', 'lft', 'rgt', 'level', 'ordering', 'hits', 'lock'], 'integer'], [['title'], 'string', 'max' => 1024], [['title'], 'filter', 'filter' => 'strip_tags'], [['alias', 'metakey'], 'string', 'max' => 255], [['metadesc'], 'string', 'max' => 2048], [['alias'], 'filter', 'filter' => 'trim'], [['alias'], 'filter', 'filter' => function ($value) {
         if (empty($value)) {
             return Inflector::slug(TransliteratorHelper::process($this->title));
         } else {
             return Inflector::slug($value);
         }
     }], [['alias'], 'unique', 'filter' => function ($query) {
         /** @var $query \yii\db\ActiveQuery */
         if ($parent = self::findOne($this->parent_id)) {
             $query->andWhere('lft>=:lft AND rgt<=:rgt AND level=:level', ['lft' => $parent->lft, 'rgt' => $parent->rgt, 'level' => $parent->level + 1]);
         }
     }], [['alias'], 'string', 'max' => 250], [['alias'], 'required', 'enableClientValidation' => false], [['tags', 'versionNote', 'lock'], 'safe'], [['ordering'], 'filter', 'filter' => 'intVal']];
 }
Example #29
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return [[['language', 'title', 'status'], 'required'], [['status', 'created_at', 'updated_at', 'created_by', 'updated_by', 'hits', 'lock'], 'integer'], [['language'], 'string', 'max' => 7], [['title'], 'string', 'max' => 100], [['alias', 'group', 'metakey'], 'string', 'max' => 255], [['metadesc'], 'string', 'max' => 2048], [['alias'], 'filter', 'filter' => 'trim'], [['alias'], 'filter', 'filter' => function ($value) {
         if (empty($value)) {
             return Inflector::slug(TransliteratorHelper::process($this->title));
         } else {
             return Inflector::slug($value);
         }
     }], [['alias'], 'unique', 'filter' => function ($query) {
         /** @var $query \yii\db\ActiveQuery */
         $query->andWhere(['language' => $this->language]);
     }], [['alias'], 'required', 'enableClientValidation' => false], [['translation_id'], 'unique', 'filter' => function ($query) {
         /** @var $query \yii\db\ActiveQuery */
         $query->andWhere(['language' => $this->language]);
     }, 'message' => Yii::t('gromver.platform', 'Локализация ({language}) для записи (ID:{id}) уже существует.', ['language' => $this->language, 'id' => $this->translation_id])]];
 }
Example #30
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return [[['language', 'title', 'detail_text', 'status'], 'required'], [['preview_text', 'detail_text'], 'string'], [['parent_id', 'created_at', 'updated_at', 'status', 'created_by', 'updated_by', 'lft', 'rgt', 'level', 'ordering', 'hits', 'lock'], 'integer'], [['language'], 'string', 'max' => 7], [['title'], 'string', 'max' => 1024], [['alias', 'metakey'], 'string', 'max' => 255], [['metadesc'], 'string', 'max' => 2048], [['alias'], 'filter', 'filter' => 'trim'], [['alias'], 'filter', 'filter' => function ($value) {
         if (empty($value)) {
             return Inflector::slug(TransliteratorHelper::process($this->title));
         } else {
             return Inflector::slug($value);
         }
     }], [['alias'], 'unique', 'filter' => function ($query) {
         /** @var $query \yii\db\ActiveQuery */
         if ($parent = self::findOne($this->parent_id)) {
             $query->andWhere('lft>=:lft AND rgt<=:rgt AND level=:level AND language=:language', ['lft' => $parent->lft, 'rgt' => $parent->rgt, 'level' => $parent->level + 1, 'language' => $this->language]);
         }
     }], [['alias'], 'string', 'max' => 250], [['alias'], 'required', 'enableClientValidation' => false], [['translation_id'], 'unique', 'filter' => function ($query) {
         /** @var $query \yii\db\ActiveQuery */
         $query->andWhere(['language' => $this->language]);
     }, 'message' => Yii::t('gromver.platform', 'Локализация ({language}) для записи (ID:{id}) уже существует.', ['language' => $this->language, 'id' => $this->translation_id])], [['tags', 'versionNote', 'lock'], 'safe'], [['ordering'], 'filter', 'filter' => 'intVal']];
 }