Esempio n. 1
0
 /**
  *   unlinkAction
  *
  *   Get user contents which are related to particular content
  *
  *   @author 2010 Mikko Korpinen
  *
  */
 public function unlinkAction()
 {
     // Get authentication
     $auth = Zend_Auth::getInstance();
     // If user has identity
     if ($auth->hasIdentity()) {
         // Get requests
         $params = $this->getRequest()->getParams();
         $relatestoid = isset($params['relatestoid']) ? $params['relatestoid'] : '';
         $id_usr = $auth->getIdentity()->user_id;
         $contenttype = '';
         $contents = array();
         $model_content = new Default_Model_Content();
         $contentexists = $model_content->checkIfContentExists($relatestoid);
         $isOwner = $model_content->checkIfUserIsOwner($relatestoid, $id_usr);
         if ($contentexists && $isOwner) {
             $relatesToContent = $model_content->getDataAsSimpleArray($relatestoid);
             $this->view->relatesToContentTitle = $relatesToContent['title_cnt'];
             $model_content_types = new Default_Model_ContentTypes();
             $model_cnt_has_cnt = new Default_Model_ContentHasContent();
             $contenttype = $model_content_types->getTypeById($relatesToContent['id_cty_cnt']);
             $contentContents = $model_cnt_has_cnt->getContentContents($relatestoid);
         }
         if (!$isOwner) {
             $contentexists = false;
         }
         $this->view->contentexists = $contentexists;
         $this->view->relatesToId = $relatestoid;
         $this->view->linkingContentType = $contenttype;
         $this->view->contents = $contentContents;
     } else {
         // If not logged, redirecting to system message page
         $message = 'content-link-not-logged';
         $url = $this->_urlHelper->url(array('controller' => 'msg', 'action' => 'index', 'language' => $this->view->language), 'lang_default', true);
         $this->flash($message, $url);
     }
 }
Esempio n. 2
0
 public function contentfavouriteAction()
 {
     // Get authentication
     $auth = Zend_Auth::getInstance();
     $favouriteUserId = 0;
     if ($auth->hasIdentity()) {
         $favouriteUserId = $auth->getIdentity()->user_id;
     }
     $params = $this->getRequest()->getParams();
     // get favourite method, "add" or "remove"
     $favouriteMethod = isset($params['method']) ? $params['method'] : "NONE";
     $id = isset($params['id_cnt']) ? $params['id_cnt'] : "0";
     // Get contents total favourites
     $userFavouritesModel = new Default_Model_UserHasFavourites();
     $contentModel = new Default_Model_Content();
     $totalFavourites = $userFavouritesModel->getUsersCountByFavouriteContent($id);
     $totalFavourites = $totalFavourites[0]['users_count_fvr'];
     $isFavourite = $userFavouritesModel->checkIfContentIsUsersFavourite($id, $favouriteUserId);
     $isOwner = $contentModel->checkIfUserIsOwner($id, $favouriteUserId);
     if ($favouriteMethod != "NONE" && $auth->hasIdentity() && !$isOwner) {
         //If favourite method was "add", then add content to user favourites
         if ($favouriteMethod == "add" && !$isFavourite) {
             if ($userFavouritesModel->addContentToFavourites($id, $favouriteUserId)) {
                 $isFavourite = true;
                 $totalFavourites++;
             } else {
                 $this->flash('favourite-adding-failed', $baseUrl . '/en/msg');
             }
         } elseif ($favouriteMethod == "remove" && $isFavourite) {
             if ($userFavouritesModel->removeUserFavouriteContent($id, $favouriteUserId)) {
                 $isFavourite = false;
                 $totalFavourites--;
             } else {
                 $this->flash('favourite-removing-failed', $baseUrl . '/en/msg');
             }
         } else {
             unset($favouriteMethod);
         }
     }
     $favourite = array('total_favourites' => $totalFavourites, 'is_favourite' => $isFavourite);
     $thie->view->userid = $favouriteUserId;
     $this->view->favourite = $favourite;
 }