Пример #1
0
 public function upload()
 {
     if ($this->validate()) {
         $cat = Categories::findOne($this->id);
         $contr = Yii::$app->controllerNamespace . '\\' . ucfirst($cat->handler) . 'Controller';
         $base = $contr::baseStorePath();
         $store_to = $base['real'] . $cat->route;
         foreach ($this->files as $f) {
             $new_fn = $this->newFileName($f->baseName, $f->extension);
             if ($f->saveAs($store_to . $new_fn)) {
                 $res = new Resources();
                 $res->attachBehavior('ImageBehavior', ['class' => ImageBehavior::className()]);
                 $res->category_id = $this->id;
                 $res->title = $res->description = $f->baseName;
                 $res->keywords = $new_fn;
                 //реальное имя файла с расширением
                 $res->alias = str_replace('.' . $f->extension, '', $new_fn);
                 //псевдоним изначально равен имени файла
                 $res->path = $store_to;
                 $res->webroute = $base['web'] . $cat->route;
                 $res->filename = $new_fn;
                 $res->save();
             }
             //TODO обработка ошибки сохранения файла
         }
         return true;
     }
     return false;
 }
Пример #2
0
 public function getIsEmpty()
 {
     $count = Categories::find()->where(['parent_id' => $this->id])->count();
     if ($count == 0) {
         $count = Resources::find()->where(['category_id' => $this->id])->count();
     }
     return $count == 0;
 }
Пример #3
0
 public function search($input)
 {
     $query = Resources::query();
     $columns = Schema::getColumnListing('resources');
     $attributes = array();
     foreach ($columns as $attribute) {
         if (isset($input[$attribute]) and !empty($input[$attribute])) {
             $query->where($attribute, $input[$attribute]);
             $attributes[$attribute] = $input[$attribute];
         } else {
             $attributes[$attribute] = null;
         }
     }
     return [$query->get(), $attributes];
 }
 /**
  * Store a newly created ResourceLike in storage.
  * POST /resourceLikes
  *
  * @param Request $request
  *
  * @return Response
  */
 public function store(Request $request)
 {
     if (sizeof(ResourceLike::$rules) > 0) {
         $this->validateRequestOrFail($request, ResourceLike::$rules);
     }
     $input = $request->all();
     $resourceLikes = $this->resourceLikeRepository->create($input);
     $resource = Resources::find($input['postId']);
     if ($resource) {
         $resource->likes = $resource->likes + 1;
         $resource->update();
     } else {
         return response()->json("Invalid Resources Id!", 400);
     }
     return response()->json($resource->likes);
 }
Пример #5
0
 private function getChilds($item_id)
 {
     $node = true;
     $childs = Categories::findAll(['parent_id' => $item_id]);
     Yii::trace('Categories count: ' . count($childs));
     if (!count($childs)) {
         $node = false;
         $childs = Resources::findAll(['category_id' => $item_id]);
         Yii::trace('Resources count: ' . count($childs));
     }
     if (!count($childs)) {
         $_items = [];
         return;
     }
     foreach ($childs as $item) {
         $this->_items[] = ['id' => $item->id, 'title' => $item->title, 'url' => '/' . $item->route, 'node' => $node];
     }
 }
Пример #6
0
 private function getStoreInfo()
 {
     $path = [];
     switch ($this->tableId) {
         case Resources::$tableId:
             $model = Resources::findOne($this->id);
             $handler = $model->category->handler;
             $route = $model->route;
             break;
         case Categories::$tableId:
             $model = Categories::findOne($this->id);
             $handler = $model->handler;
             $route = $model->route;
             break;
         default:
             throw new InvalidConfigException('FileUploadModel - неизвестный ID таблицы');
             break;
     }
     $contrClass = Yii::$app->controllerNamespace . '\\' . ucfirst($handler) . 'Controller';
     $path = $contrClass::baseStorePath();
     $path['route'] = $route;
     return $path;
 }
Пример #7
0
 /**
  */
 protected function findModel($id)
 {
     if (($model = Resources::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Пример #8
0
 public static function findByAlias($alias, $cat_id = 0)
 {
     return Resources::find()->where(['alias' => $alias])->andWhere(['category_id' => $cat_id])->one();
 }
Пример #9
0
 protected function findAlbum($id)
 {
     if (($model = Resources::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('Ресурс не найден');
     }
 }
Пример #10
0
 public function share($id, Request $request)
 {
     $post_type = $request->input('postType');
     switch ($post_type) {
         case 'Post':
             $post = Post::find($id);
             if ($post) {
                 $post->share_count = $post->share_count + 1;
                 $post->update();
                 return response()->json($post->share_count);
             }
             break;
         case 'iWomenPost':
             $post = IwomenPost::find($id);
             if ($post) {
                 $post->share_count = $post->share_count + 1;
                 $post->update();
                 return response()->json($post->share_count);
             }
             break;
         case 'Resources':
             $post = Resources::find($id);
             if ($post) {
                 $post->share_count = $post->share_count + 1;
                 $post->update();
                 return response()->json($post->share_count);
             }
             break;
         case 'SubResourceDetail':
             $post = SubResourceDetail::find($id);
             if ($post) {
                 $post->share_count = $post->share_count + 1;
                 $post->update();
                 return response()->json($post->share_count);
             }
             break;
         default:
             # code...
             break;
     }
     return response()->json("Successfully shared your post!");
 }
Пример #11
0
 public function parseRequest($manager, $request)
 {
     $route = '';
     $params = [];
     $pathInfo = $request->getPathInfo();
     if ($pathInfo == '') {
         return false;
     }
     $parts = explode('/', $pathInfo);
     $next = self::CATEGORY_PART;
     //вначале всегда идет раздел
     $parent_id = 0;
     foreach ($parts as $p) {
         if ($p != '') {
             switch ($next) {
                 case self::CATEGORY_PART:
                     $this->_cat = Categories::findByAlias($p, $parent_id);
                     if ($this->_cat === null) {
                         throw new NotFoundHttpException('Страница не найдена');
                     }
                     if ($this->getHandlerType($this->_cat->handler) == MController::HANDLE_CAT) {
                         $next = self::CATEGORY_PART;
                         $parent_id = $this->_cat->id;
                     } else {
                         $next = self::RESOURCE_PART;
                     }
                     break;
                 case self::RESOURCE_PART:
                     $this->_res = Resources::findByAlias($p, $this->_cat->id);
                     if ($this->_res === null) {
                         throw new NotFoundHttpException('Страница не найдена');
                     }
                     $next = self::PARAM_PART;
                     break;
                 case self::PARAM_PART:
                     $this->_params[] = $p;
                     break;
             }
         }
     }
     $route = $this->_cat->handler;
     // Если раздел содержит всего один ресурс/подраздел и $show_single == 1, тогда покажем дочерний элемент
     // Если дочерний элемент подраздел и $show_single == 1 идем ниже и т.д.
     if ($this->_res == false) {
         $action = 'index';
         $params = ['id' => $this->_cat->id];
         if ($this->_cat->show_single) {
             while (count($this->_cat->subcategories) == 1 && $this->_cat->show_single == 1) {
                 $this->_cat = $this->_cat->subcategories[0];
             }
             $route = $this->_cat->handler;
             $params = ['id' => $this->_cat->id];
             if (count($this->_cat->resources) == 1 && $this->_cat->show_single) {
                 $action = 'view';
                 $params = ['id' => $this->_cat->resources[0]->id];
             }
         }
     } else {
         $action = 'view';
         $params = ['id' => $this->_res->id];
     }
     $route .= '/' . $action;
     return [$route, $params];
 }
Пример #12
0
 protected function findModel($id)
 {
     if ($id != 0) {
         if (($model = Resources::findOne($id)) !== null) {
             return $model;
         }
     } else {
         if (($model = Categories::findByAlias('0', 0)->resources[0]) !== null) {
             return $model;
         }
     }
     throw new NotFoundHttpException('The requested page does not exist.');
 }
Пример #13
0
 /**
  * Store a newly created Comment in storage.
  * POST /comments
  *
  * @param Request $request
  *
  * @return Response
  */
 public function store(Request $request)
 {
     if (sizeof(Comment::$rules) > 0) {
         $validator = $this->validateRequestOrFail($request, Comment::$rules);
         if ($validator) {
             return $validator;
         }
     }
     $input = $request->all();
     $input['objectId'] = str_random(10);
     $comments = $this->commentRepository->create($input);
     if (isset($input['postType']) && $input['postType'] == 'iWomenPost') {
         $post = IwomenPost::where('objectId', $input['postId'])->first();
         if ($post) {
             $post->comment_count = $post->comment_count + 1;
             $post->update();
         }
     } else {
         if (isset($input['postType']) && $input['postType'] == 'Post') {
             $post = Post::where('objectId', $input['postId'])->first();
             if ($post) {
                 $post->comment_count = $post->comment_count + 1;
                 $post->update();
             }
         } else {
             if (isset($input['postType']) && $input['postType'] == 'SubResourceDetail') {
                 $post = SubResourceDetail::where('objectId', $input['postId'])->first();
                 if ($post) {
                     $post->comment_count = $post->comment_count + 1;
                     $post->update();
                 }
             } else {
                 if (isset($input['postType']) && $input['postType'] == 'Resources') {
                     $post = Resources::where('objectId', $input['postId'])->first();
                     if ($post) {
                         $post->comment_count = $post->comment_count + 1;
                         $post->update();
                     }
                 }
             }
         }
     }
     if (isset($input['postType']) && $input['postType'] == 'Post' || isset($input['postType']) && $input['postType'] == 'SubResourceDetail' || isset($input['postType']) && $input['postType'] == 'Resources') {
         if (isset($post) && $post) {
             $device_list = [];
             $gcm = Gcm::where('user_id', $post->userId)->first();
             if ($gcm) {
                 $device_list[] = PushNotification::Device($gcm->reg_id);
                 $message['title'] = 'New Comment';
                 $message['message'] = $comments->comment_contents;
                 $devices = PushNotification::DeviceCollection($device_list);
                 $message = PushNotification::Message(json_encode($message), array());
                 $collection = PushNotification::app('appNameAndroid')->to($devices)->send($message);
             }
         }
     }
     $comments['comment_count'] = $post->comment_count;
     return $this->sendResponse($comments->toArray(), "Comment saved successfully");
 }
Пример #14
0
 public function import()
 {
     /*   $dataJson = $this->readJson('TlgProfile.json');
          foreach ($dataJson['results'] as $key => $data) {
              $data['tlg_group_logo'] = isset($data['tlg_group_logo']) ? $data['tlg_group_logo']['url'] : '';
              $data['tlg_leader_img'] = isset($data['tlg_leader_img']) ? $data['tlg_leader_img']['url'] : '';
              $data['tlg_member_ph'] = isset($data['tlg_member_ph']) ? json_encode($data['tlg_member_ph']) : '';
              TlgProfile::create($data);
          }
          $dataJson = $this->readJson('Post.json');
          foreach ($dataJson['results'] as $key => $data) {
              $data['image'] = isset($data['image']) ? $data['image']['url'] : '';
              $data['postUploadedDate'] = isset($data['postUploadedDate']) ? $data['postUploadedDate']['iso'] : '';
              $data['userId'] = isset($data['userId']) ? $data['userId']['objectId'] : '';
              Post::create($data);
          }*/
     $dataJson = $this->readJson('IwomenPost.json');
     foreach ($dataJson['results'] as $key => $data) {
         $data['image'] = isset($data['image']) ? $data['image']['url'] : '';
         $data['postUploadedDate'] = isset($data['postUploadedDate']) ? $data['postUploadedDate']['iso'] : '';
         $data['userId'] = isset($data['userId']) ? $data['userId']['objectId'] : '';
         $data['authorId'] = isset($data['authorId']) ? $data['authorId']['objectId'] : '';
         $data['postUploadPersonImg'] = isset($data['postUploadPersonImg']) ? $data['postUploadPersonImg']['url'] : '';
         $data['audioFile'] = isset($data['audioFile']) ? $data['audioFile']['url'] : '';
         IwomenPost::create($data);
     }
     $dataJson = $this->readJson('Resources.json');
     foreach ($dataJson['results'] as $key => $data) {
         $data['resource_icon_img'] = isset($data['resource_icon_img']) ? $data['resource_icon_img']['url'] : '';
         Resources::create($data);
     }
     $dataJson = $this->readJson('Author.json');
     foreach ($dataJson['results'] as $key => $data) {
         $data['authorImg'] = isset($data['authorImg']) ? $data['authorImg']['url'] : '';
         Author::create($data);
     }
     /*
             $dataJson = $this->readJson('Comment.json');
             foreach ($dataJson['results'] as $key => $data) {
                 $data['comment_created_time'] = isset($data['comment_created_time']) ? $data['comment_created_time']['iso'] : '';
                 $data['postId'] = isset($data['postId']) ? $data['postId']['objectId'] : '';
                 $data['userId'] = isset($data['userId']) ? $data['userId']['objectId'] : '';
                 Comment::create($data);
             }*/
     $dataJson = $this->readJson('SubResourceDetail.json');
     foreach ($dataJson['results'] as $key => $data) {
         $data['author_id'] = isset($data['author_id']) ? $data['author_id']['objectId'] : '';
         $data['posted_date'] = isset($data['posted_date']) ? $data['posted_date']['iso'] : '';
         $data['resource_id'] = isset($data['resource_id']) ? $data['resource_id']['objectId'] : '';
         SubResourceDetail::create($data);
     }
     /*
             $dataJson = $this->readJson('SisterDownloadApp.json');
             foreach ($dataJson['results'] as $key => $data) {
                 $data['app_img'] = isset($data['app_img']) ? $data['app_img']['url'] : '';
                 SisterDownloadApp::create($data);
             }
             $dataJson = $this->readJson('StickerStore.json');
             foreach ($dataJson['results'] as $key => $data) {
                 $data['stickerImg'] = isset($data['stickerImg']) ? $data['stickerImg']['url'] : '';
                 StickerStore::create($data);
             }
             $dataJson = $this->readJson('User.json');
             foreach ($dataJson['results'] as $key => $data) {
                 $data['password'] = isset($data['bcryptPassword']) ? $data['bcryptPassword'] : '';
                 $data['user_profile_img'] = isset($data['user_profile_img']) ? $data['user_profile_img']['url'] : '';
                 $data['profileimage'] = isset($data['profileimage']) ? $data['profileimage']['url'] : '';
                 User::create($data);
             }*/
     return response()->json('success');
 }
Пример #15
0
 public function thisWeekContent()
 {
     $resources = Resources::where('week_content', 1)->first();
     return response()->json($resources);
 }