Esempio n. 1
0
 /**
  * doExecute
  *
  * @return  void
  */
 public function doExecute()
 {
     $faker = Factory::create();
     $articleIds = ArticleMapper::findAll()->id;
     if (WarderHelper::tableExists('users')) {
         $userIds = UserMapper::findAll()->id;
     } else {
         $userIds = range(1, 50);
     }
     foreach ($articleIds as $articleId) {
         foreach (range(3, mt_rand(5, 7)) as $i) {
             $data = new Data();
             $data['target_id'] = $articleId;
             $data['type'] = 'article';
             $data['user_id'] = $faker->randomElement($userIds);
             $data['title'] = $faker->sentence(mt_rand(3, 5));
             $data['content'] = $faker->paragraph(5);
             $data['reply'] = $faker->paragraph(3);
             $data['reply_user_id'] = $faker->randomElement($userIds);
             $data['created'] = $faker->dateTime->format(DateTime::getSqlFormat());
             $data['created_by'] = $faker->randomElement($userIds);
             $data['modified'] = $faker->dateTime->format(DateTime::getSqlFormat());
             $data['modified_by'] = $faker->randomElement($userIds);
             $data['ordering'] = $i;
             $data['state'] = 1;
             $data['params'] = '';
             CommentMapper::createOne($data);
             $this->outCounting();
         }
     }
 }
Esempio n. 2
0
 /**
  * postSave
  *
  * @param Data $data
  *
  * @return  void
  */
 protected function postSave(Data $data)
 {
     $this->post = $data;
     $this->topic = $topic = $this->model->getRecord('Topic');
     $topic->load($data->topic_id);
     $this->category = $this->model->getRecord('Category');
     $this->category->load($topic->category_id);
     if ($this->isNew) {
         if (!$data->primary) {
             $user = User::get();
             $date = DateTime::create();
             $topic->last_reply_user = $user->id;
             $topic->last_reply_post = $data->id;
             $topic->last_reply_date = $date->toSql();
             $topic->replies++;
             $topic->store();
         } else {
             $this->category->topics++;
         }
         $this->category->posts++;
         $this->category->store();
     }
     // Mail
     $this->sendMail($topic, $data);
     // Add Notification
     Notification::addNotification('topic', $topic->id, $topic->user_id);
 }
Esempio n. 3
0
 /**
  * request
  *
  * @return  bool
  *
  * @throws \Exception
  */
 protected function request()
 {
     $email = $this->input->getEmail('email');
     if (!$email) {
         $this->setRedirect($this->router->http('forgot'), Translator::translate('windwalker.user.no.email'));
         return false;
     }
     $view = $this->getView();
     $token = md5($this->app->get('secret') . uniqid() . CryptHelper::genRandomBytes());
     $link = $this->router->http('forgot', array('task' => 'confirm', 'token' => $token), Router::TYPE_FULL);
     $user = User::get(array('email' => $email));
     if ($user->notNull()) {
         $password = new Password();
         $user->reset_token = $password->create($token);
         $user->reset_last = DateTime::create('now', DateTime::TZ_LOCALE)->toSql(true);
         User::save($user);
     }
     $view['user'] = $user;
     $view['token'] = $token;
     $view['link'] = $link;
     $body = $view->setLayout('email')->render();
     // Please send email here.
     // ----------------------------------------------------
     // ----------------------------------------------------
     $this->setRedirect($this->router->http('forgot', array('task' => 'confirm')), array('This is test message.', $body));
     return true;
 }
Esempio n. 4
0
 /**
  * doExecute
  *
  * @return  void
  */
 public function doExecute()
 {
     $faker = Factory::create();
     if (WarderHelper::tableExists('users')) {
         $userIds = UserMapper::findAll()->id;
     } else {
         $userIds = range(1, 50);
     }
     $positions = $faker->words(20);
     $types = ModuleHelper::getModuleTypes()->dump();
     foreach (range(1, 75) as $i) {
         $data = new Data();
         /** @var \Lyrasoft\Luna\Module\ModuleType $module */
         $module = $faker->randomElement($types);
         $data['title'] = $faker->sentence(mt_rand(3, 5));
         $data['type'] = $module->type;
         $data['class'] = $module->class;
         $data['position'] = $faker->randomElement($positions);
         $data['note'] = $faker->sentence(5);
         $data['content'] = $faker->paragraph(5);
         $data['state'] = $faker->randomElement(array(1, 1, 1, 1, 0, 0));
         $data['created'] = $faker->dateTime->format(DateTime::getSqlFormat());
         $data['created_by'] = $faker->randomElement($userIds);
         $data['modified'] = $faker->dateTime->format(DateTime::getSqlFormat());
         $data['modified_by'] = $faker->randomElement($userIds);
         $data['ordering'] = $i;
         $data['language'] = 'en-GB';
         $data['params'] = '';
         ModuleMapper::createOne($data);
         $this->outCounting();
     }
 }
Esempio n. 5
0
 /**
  * buildInput
  *
  * @param array $attrs
  *
  * @return  string
  */
 public function buildInput($attrs)
 {
     // Convert timezone
     $from = $this->get('from', 'UTC');
     $to = $this->get('to', Ioc::getConfig()->get('system.timezone', 'UTC'));
     if ($attrs['value'] && $attrs['value'] != static::EMPTY_DATETIME) {
         $attrs['value'] = DateTime::convert($attrs['value'], $from, $to);
     }
     $input = parent::buildInput($attrs);
     $format = $this->get('format', 'YYYY-MM-DD HH:mm:ss');
     $id = $this->getId();
     return WidgetHelper::render('phoenix.form.field.calendar', array('id' => $id, 'input' => $input, 'attrs' => $attrs, 'format' => $format, 'field' => $this), WidgetHelper::EDGE);
 }
Esempio n. 6
0
 /**
  * prepareRecord
  *
  * @param Record $record
  *
  * @return  void
  */
 protected function prepareRecord(Record $record)
 {
     $user = User::get();
     $date = DateTime::create();
     if (!$record->id) {
         $record->version = 1;
         $record->rating = 0;
         $record->state = 1;
         $record->user_id = $user->id;
         $record->created = $date->toSql();
         $record->created_by = $user->id;
         $this->setOrderPosition($record);
     } else {
         $record->modified = $date->toSql();
         $record->modified_by = $user->id;
     }
 }
Esempio n. 7
0
 /**
  * doExecute
  *
  * @return  void
  */
 public function doExecute()
 {
     $faker = Factory::create();
     $languages = LanguageMapper::find(array('state' => 1))->code;
     $languages[] = '*';
     $categories = CategoryMapper::find(array('parent_id != 0', 'type' => 'article'));
     if (WarderHelper::tableExists('users')) {
         $userIds = UserMapper::findAll()->id;
     } else {
         $userIds = range(1, 50);
     }
     $tags = TagMapper::findAll()->dump();
     foreach ($categories as $category) {
         foreach (range(7, 15) as $i) {
             $data = new Data();
             $lang = $faker->randomElement($languages);
             $data['category_id'] = $category->id;
             $data['title'] = '(' . $lang . ') ' . $faker->sentence(mt_rand(3, 5));
             $data['alias'] = OutputFilter::stringURLSafe($data['title']);
             $data['introtext'] = '(' . $lang . ') ' . $faker->paragraph(5);
             $data['fulltext'] = $faker->paragraph(5);
             $data['image'] = UnsplashHelper::getImageUrl();
             $data['state'] = $faker->randomElement(array(1, 1, 1, 1, 0, 0));
             $data['version'] = mt_rand(1, 50);
             $data['created'] = $faker->dateTime->format(DateTime::getSqlFormat());
             $data['created_by'] = $faker->randomElement($userIds);
             $data['modified'] = $faker->dateTime->format(DateTime::getSqlFormat());
             $data['modified_by'] = $faker->randomElement($userIds);
             $data['ordering'] = $i;
             $data['language'] = $lang;
             $data['params'] = '';
             ArticleMapper::createOne($data);
             foreach ($faker->randomElements($tags, mt_rand(5, 7)) as $tag) {
                 $map = new Data();
                 $map->tag_id = $tag->id;
                 $map->target_id = $data->id;
                 $map->type = 'article';
                 TagMapMapper::createOne($map);
             }
             $this->outCounting();
         }
     }
 }
Esempio n. 8
0
 /**
  * prepareRecord
  *
  * @param Record $record
  *
  * @return  void
  */
 protected function prepareRecord(Record $record)
 {
     $user = User::get();
     $date = DateTime::create();
     // New
     if (!$record->id) {
         $record->user_id = $user->id;
         $record->created_by = $user->id;
         $record->version = 1;
         $record->replies = 1;
         $record->hits = 0;
         $record->favorites = 0;
         $record->rating = 0;
         $record->created = $date->toSql();
         $record->state = 1;
     }
     $record->last_reply_user = $user->id;
     $record->last_reply_date = $date->toSql();
 }
Esempio n. 9
0
 /**
  * doExecute
  *
  * @return  void
  */
 public function doExecute()
 {
     $faker = Factory::create();
     $record = new CategoryRecord();
     $languages = LanguageMapper::find(array('state' => 1))->code;
     $languages[] = '*';
     if (WarderHelper::tableExists('users')) {
         $userIds = UserMapper::findAll()->id;
     } else {
         $userIds = range(1, 50);
     }
     $existsRecordIds = array();
     foreach ($this->types as $type) {
         $existsRecordIds[$type] = array(1);
     }
     foreach (range(1, 30) as $i) {
         $record->reset();
         $lang = $faker->randomElement($languages);
         $record['title'] = $faker->sentence(mt_rand(1, 3)) . ' - [' . $lang . ']';
         $record['alias'] = OutputFilter::stringURLSafe($record['title']);
         $record['type'] = $faker->randomElement($this->types);
         $record['description'] = $faker->paragraph(5);
         $record['image'] = UnsplashHelper::getImageUrl();
         $record['state'] = $faker->randomElement(array(1, 1, 1, 1, 0, 0));
         $record['version'] = mt_rand(1, 50);
         $record['created'] = $faker->dateTime->format(DateTime::getSqlFormat());
         $record['created_by'] = $faker->randomElement($userIds);
         $record['modified'] = $faker->dateTime->format(DateTime::getSqlFormat());
         $record['modified_by'] = $faker->randomElement($userIds);
         $record['language'] = $lang;
         $record['params'] = '';
         $record->setLocation($faker->randomElement($existsRecordIds[$record['type']]), $record::LOCATION_LAST_CHILD);
         $record->store();
         $record->rebuildPath();
         $existsRecordIds[$record['type']][] = $record->id;
         $this->outCounting();
     }
 }
Esempio n. 10
0
 /**
  * prepareRecord
  *
  * @param NestedRecord|Record $record
  *
  * @return  void
  */
 protected function prepareRecord(Record $record)
 {
     $user = User::get();
     $date = DateTime::create();
     if (!$record->alias) {
         $record->alias = $record->title;
     }
     $record->alias = OutputFilter::stringURLUnicodeSlug($record->alias);
     if (!$record->alias) {
         $record->alias = OutputFilter::stringURLSafe($date->format('Y-m-d-H-i-s'));
     }
     // Created date
     if (!$record->created) {
         $record->created = $date->toSql();
     }
     // Modified date
     if ($record->id) {
         $record->modified = $date->toSql();
     }
     // Created user
     if (!$record->created_by) {
         $record->created_by = $user->id;
     }
     // Modified user
     if ($record->id) {
         $record->modified_by = $user->id;
     }
     // Set Ordering or Nested ordering
     if (!$record->id) {
         $record->setLocation($record->parent_id, $record::LOCATION_LAST_CHILD);
     }
     if (!$record->id) {
         $record->state = 1;
         $record->access = 1;
         $record->topics = 0;
         $record->posts = 0;
     }
 }
Esempio n. 11
0
 /**
  * doExecute
  *
  * @return  void
  */
 public function doExecute()
 {
     $faker = Factory::create();
     $pass = UserHelper::hashPassword(1234);
     foreach (range(1, 50) as $i) {
         $data = new Data();
         $data->name = $faker->name;
         $data->username = $faker->userName;
         $data->email = $faker->email;
         $data->password = $pass;
         $data->avatar = PravatarHelper::unique(600, uniqid($i));
         $data->group = 1;
         $data->blocked = 0;
         $data->activation = '';
         $data->reset_token = '';
         $data->last_reset = $faker->dateTime->format(DateTime::getSqlFormat());
         $data->last_login = $faker->dateTime->format(DateTime::getSqlFormat());
         $data->registered = $faker->dateTime->format(DateTime::getSqlFormat());
         $data->modified = $faker->dateTime->format(DateTime::getSqlFormat());
         $data->params = '';
         UserMapper::createOne($data);
         $this->outCounting();
     }
 }
Esempio n. 12
0
 /**
  * prepareDefaultData
  *
  * @param DataInterface|UserDataTrait $user
  *
  * @return  void
  */
 protected function prepareDefaultData(DataInterface $user)
 {
     $user->registered = $user->registered ?: DateTime::create()->format(DateTime::getSqlFormat());
     $user->blocked = $user->blocked === null ? 1 : $user->blocked;
 }
Esempio n. 13
0
 /**
  * doSave
  *
  * @param DataInterface $data
  *
  * @return  bool
  *
  * @throws ValidateFailException
  * @throws \Exception
  */
 protected function doSave(DataInterface $data)
 {
     $email = $this->input->getEmail('email');
     if (!$email) {
         throw new ValidateFailException(Translator::translate($this->langPrefix . 'message.user.not.found'));
     }
     $view = $this->getView();
     $user = User::get(array('email' => $email));
     if ($user->isNull()) {
         throw new ValidateFailException(Translator::translate($this->langPrefix . 'message.user.not.found'));
     }
     $token = UserHelper::getToken($user->email);
     $link = $this->router->route('forget_confirm', array('token' => $token, 'email' => $email), CoreRouter::TYPE_FULL);
     $password = new Password();
     $user->reset_token = $password->create($token);
     $user->last_reset = DateTime::create()->toSql();
     User::save($user);
     $view['user'] = $user;
     $view['token'] = $token;
     $view['link'] = $link;
     $body = $this->getMailBody($view);
     $this->sendEmail($user->email, $body);
     return true;
 }
Esempio n. 14
0
 /**
  * Created date.
  *
  * @param string $format The date format.
  * @param bool   $local  Use local timezone.
  *
  * @return string Date string.
  */
 public function createdDate($format = '', $local = false)
 {
     $field = $this->config->get('field.created', 'created');
     $format = $format ?: DateTime::$format;
     if ($local) {
         return DateTime::toLocalTime($this->current->{$field}, $format);
     }
     return DateTime::create($this->current->{$field})->format($format);
 }
Esempio n. 15
0
 /**
  * prepareDefaultData
  *
  * @param   DataInterface|UserRecord $user
  *
  * @return  void
  */
 protected function prepareDefaultData(DataInterface $user)
 {
     if (!$user->registered) {
         $date = new DateTime();
         $user->registered = $date->toSql();
     }
 }
Esempio n. 16
0
 /**
  * getDate
  *
  * @param string $date
  * @param bool   $tz
  *
  * @return DateTime
  */
 public function getDate($date = 'now', $tz = DateTime::TZ_LOCALE)
 {
     return DateTime::create($date, $tz);
 }