Beispiel #1
0
 /**
  * Prepare configuratins before initialization
  */
 public function before()
 {
     parent::before();
     $configs = AppRecord::getConfigs('app', 'Content');
     // prevent null-type config data
     if ((int) $configs['gallerySize'] > 0) {
         $this->maxSize = (int) $configs['gallerySize'] * 1024;
     }
     if ((int) $configs['galleryResize'] > 0) {
         $this->maxResize = (int) $configs['galleryResize'];
     }
 }
Beispiel #2
0
 /**
  * Get commentaries count for pathway. Pathway should be array [itemId => pathway]
  * @throws NativeException
  * @return string
  */
 public function actionCount()
 {
     // set headers
     $this->setJsonHeader();
     // get configs
     $configs = AppRecord::getConfigs('widget', 'Comments');
     // get path array from request
     $path = $this->request->query->get('path');
     if (!Obj::isArray($path) || count($path) < 1) {
         throw new NativeException('Wrong query params');
     }
     $count = [];
     // for each item in path array calculate comments count
     foreach ($path as $id => $uri) {
         $query = CommentPost::where('pathway', '=', $uri)->where('moderate', '=', 0);
         // check if comments is depend of language locale
         if ((int) $configs['onlyLocale'] === 1) {
             $query = $query->where('lang', '=', $this->request->getLanguage());
         }
         // set itemId => count
         $count[(int) $id] = $query->count();
     }
     // render json response
     return json_encode(['status' => 1, 'count' => $count]);
 }
Beispiel #3
0
 /**
  * Get widget configs from admin part as array $cfg=>$value
  * @return array|null|string
  */
 public function getConfigs()
 {
     $realName = Str::lastIn(self::$class, '\\', true);
     return AppRecord::getConfigs('widget', $realName);
 }
Beispiel #4
0
 /**
  * Change user rating action
  * @throws ForbiddenException
  * @throws NativeException
  * @throws NotFoundException
  * @return string
  */
 public function actionChangerating()
 {
     if (!App::$User->isAuth()) {
         throw new ForbiddenException('Auth required');
     }
     $this->setJsonHeader();
     // get operation type and target user id
     $target_id = (int) $this->request->get('target');
     $type = $this->request->get('type');
     // check type of query
     if ($type !== '+' && $type !== '-') {
         throw new NativeException('Wrong data');
     }
     // check if passed user id is exist
     if (!Obj::isLikeInt($target_id) || $target_id < 1 || !App::$User->isExist($target_id)) {
         throw new NotFoundException('Wrong user info');
     }
     $cfg = \Apps\ActiveRecord\App::getConfigs('app', 'Profile');
     // check if rating is enabled for website
     if ((int) $cfg['rating'] !== 1) {
         throw new NativeException('Rating is disabled');
     }
     // get target and sender objects
     $target = App::$User->identity($target_id);
     $sender = App::$User->identity();
     // disable self-based changes ;)
     if ($target->getId() === $sender->getId()) {
         throw new ForbiddenException('Self change prevented');
     }
     // check delay
     $diff = Date::convertToTimestamp(time() - $cfg['ratingDelay'], Date::FORMAT_SQL_TIMESTAMP);
     $query = ProfileRating::where('target_id', '=', $target->getId())->where('sender_id', '=', $sender->getId())->where('created_at', '>=', $diff)->orderBy('id', 'DESC');
     if ($query !== null && $query->count() > 0) {
         throw new ForbiddenException('Delay required');
     }
     // delay is ok, lets insert a row
     $record = new ProfileRating();
     $record->target_id = $target->getId();
     $record->sender_id = $sender->getId();
     $record->type = $type;
     $record->save();
     // update target profile
     $profile = $target->getProfile();
     if ($type === '+') {
         $profile->rating += 1;
     } else {
         $profile->rating -= 1;
     }
     $profile->save();
     return json_encode(['status' => 1, 'data' => 'ok']);
 }