Exemplo n.º 1
0
 /**
  * Returns an instance of class (singleton pattern implementation).
  *
  * @return PHOTO_BOL_PhotoAlbumDao
  */
 public static function getInstance()
 {
     if (self::$classInstance === null) {
         self::$classInstance = new self();
     }
     return self::$classInstance;
 }
Exemplo n.º 2
0
 public function findIndexedData($searchVal, array $entityTypes = array(), $limit = PHOTO_BOL_SearchService::SEARCH_LIMIT)
 {
     $condition = PHOTO_BOL_PhotoService::getInstance()->getQueryCondition('searchByDesc', array('photo' => 'p', 'album' => 'a'));
     $sql = 'SELECT `index`.*
         FROM `' . $this->getTableName() . '` AS `index`
             INNER JOIN `' . PHOTO_BOL_PhotoDao::getInstance()->getTableName() . '` AS `p` ON(`index`.`entityId` = `p`.`id`)
             INNER JOIN `' . PHOTO_BOL_PhotoAlbumDao::getInstance()->getTableName() . '` AS `a` ON(`a`.`id` = `p`.`albumId`)
         ' . $condition['join'] . '
         WHERE MATCH(`index`.`' . self::CONTENT . '`) AGAINST(:val IN BOOLEAN MODE) AND `p`.`privacy` = :everybody AND `p`.`status` = :status AND ' . $condition['where'];
     if (count($entityTypes) !== 0) {
         $sql .= ' AND `index`.`' . self::ENTITY_TYPE_ID . '` IN (SELECT `entity`.`id`
             FROM `' . PHOTO_BOL_SearchEntityTypeDao::getInstance()->getTableName() . '` AS `entity`
             WHERE `entity`.`' . PHOTO_BOL_SearchEntityTypeDao::ENTITY_TYPE . '` IN( ' . $this->dbo->mergeInClause($entityTypes) . '))';
     }
     $sql .= ' LIMIT :limit';
     return $this->dbo->queryForObjectList($sql, $this->getDtoClassName(), array_merge($condition['params'], array('val' => $searchVal, 'limit' => (int) $limit, 'everybody' => PHOTO_BOL_PhotoDao::PRIVACY_EVERYBODY, 'status' => 'approved')));
 }
Exemplo n.º 3
0
 public function findUserPhotos($userId, $start, $offset)
 {
     $photoService = PHOTO_BOL_PhotoService::getInstance();
     $photoDao = PHOTO_BOL_PhotoDao::getInstance();
     $albumDao = PHOTO_BOL_PhotoAlbumDao::getInstance();
     $query = 'SELECT p.* FROM ' . $photoDao->getTableName() . ' AS p
         INNER JOIN ' . $albumDao->getTableName() . ' AS a ON p.albumId=a.id
             WHERE a.userId=:u AND p.status = "approved" ORDER BY p.addDatetime DESC
                 LIMIT :start, :offset';
     $list = OW::getDbo()->queryForList($query, array('u' => $userId, 'start' => $start, 'offset' => $offset));
     $out = array();
     foreach ($list as $photo) {
         $id = $photo['id'];
         $out[$id] = array('id' => $id, 'thumb' => $photoService->getPhotoPreviewUrl($id), 'url' => $photoService->getPhotoUrl($id), 'path' => $photoService->getPhotoPath($id), 'description' => $photo['description'], 'permalink' => OW::getRouter()->urlForRoute('view_photo', array('id' => $id)));
         $out[$id]['oembed'] = json_encode(array('type' => 'photo', 'url' => $out[$id]['url'], 'href' => $out[$id]['permalink'], 'description' => $out[$id]['description']));
     }
     return $out;
 }
Exemplo n.º 4
0
 public function updatePhotosPrivacy($userId, $privacy)
 {
     $albumIdList = $this->photoAlbumDao->getUserAlbumIdList($userId);
     if (!$albumIdList) {
         return;
     }
     $this->photoDao->updatePrivacyByAlbumIdList($albumIdList, $privacy);
     PHOTO_BOL_PhotoService::getInstance()->cleanListCache();
     foreach ($albumIdList as $albumId) {
         if (!($photos = $this->photoDao->getAlbumAllPhotos($albumId))) {
             continue;
         }
         $idList = array();
         foreach ($photos as $photo) {
             array_push($idList, $photo->id);
         }
         $status = $privacy == 'everybody';
         $event = new OW_Event('base.update_entity_items_status', array('entityType' => 'photo_rates', 'entityIds' => $idList, 'status' => $status));
         OW::getEventManager()->trigger($event);
     }
 }
Exemplo n.º 5
0
    public function __construct($photoId)
    {
        parent::__construct();
        if (($photo = PHOTO_BOL_PhotoDao::getInstance()->findById($photoId)) === NULL || ($album = PHOTO_BOL_PhotoAlbumDao::getInstance()->findById($photo->albumId)) === null || !($album->userId == OW::getUser()->getId() || OW::getUser()->isAuthorized('photo'))) {
            $this->setVisible(FALSE);
            return;
        }
        $this->addForm(new PHOTO_CLASS_EditForm($photo->id));
        $newsfeedAlbum = PHOTO_BOL_PhotoAlbumService::getInstance()->getNewsfeedAlbum($album->userId);
        $exclude = array();
        if (!empty($newsfeedAlbum)) {
            $exclude[] = $newsfeedAlbum->id;
        }
        $this->assign('albumNameList', PHOTO_BOL_PhotoAlbumService::getInstance()->findAlbumNameListByUserId(OW::getUser()->getId(), $exclude));
        $language = OW::getLanguage();
        OW::getDocument()->addOnloadScript(UTIL_JsGenerator::composeJsString(';var panel = $(document.getElementById("photo_edit_form"));
                var albumList = $(".ow_dropdown_list", panel);
                var albumInput = $("input[name=\'album\']", panel);
                var album = {$album};
                var hideAlbumList = function()
                {
                    albumList.hide();
                    $(".upload_photo_spinner", panel).removeClass("ow_dropdown_arrow_up").addClass("ow_dropdown_arrow_down");
                };
                var showAlbumList = function()
                {
                    albumList.show();
                    $(".upload_photo_spinner", panel).removeClass("ow_dropdown_arrow_down").addClass("ow_dropdown_arrow_up");
                };

                $(".upload_photo_spinner", panel).add(albumInput).on("click", function( event )
                {
                    if ( albumList.is(":visible") )
                    {
                        hideAlbumList();
                    }
                    else
                    {
                        showAlbumList();
                    }

                    event.stopPropagation();
                });

                albumList.find("li").on("click", function()
                {
                    hideAlbumList();
                    owForms["photo-edit-form"].removeErrors();
                }).eq(0).on("click", function()
                {
                    albumInput.val({$create_album});
                    $(".new-album", panel).show();
                    $("input[name=\'album-name\']", panel).val({$album_name});
                    $("textarea", panel).val({$album_desc});
                }).end().slice(2).on("click", function()
                {
                    albumInput.val($(this).html());
                    $(".new-album", panel).hide();
                    $("input[name=\'album-name\']", panel).val(albumInput.val());
                    $("textarea", panel).val("");
                });

                $(document).on("click", function( event )
                {
                    if ( event.target.id === "ajax-upload-album" )
                    {
                        event.stopPropagation();

                        return false;
                    }

                    hideAlbumList();
                });
                
                OW.bind("base.onFormReady.photo-edit-form", function()
                {
                    if ( album.name == {$newsfeedAlbumName} )
                    {
                        this.getElement("album-name").validators.length = 0;
                        this.getElement("album-name").addValidator({
                            validate : function( value ){
                            if(  $.isArray(value) ){ if(value.length == 0  ) throw {$required}; return;}
                            else if( !value || $.trim(value).length == 0 ){ throw {$required}; }
                            },
                            getErrorMessage : function(){ return {$required} }
                        });
                        this.bind("submit", function()
                        {
                            
                        });
                    }
                });
                ', array('create_album' => $language->text('photo', 'create_album'), 'album_name' => $language->text('photo', 'album_name'), 'album_desc' => $language->text('photo', 'album_desc'), 'album' => get_object_vars($album), 'newsfeedAlbumName' => OW::getLanguage()->text('photo', 'newsfeed_album'), 'required' => OW::getLanguage()->text('base', 'form_validator_required_error_message'))));
    }
Exemplo n.º 6
0
 public function findUserAlbums($userId, $start, $offset)
 {
     if (!$this->isActive()) {
         return null;
     }
     $service = PHOTO_BOL_PhotoAlbumService::getInstance();
     $albumDao = PHOTO_BOL_PhotoAlbumDao::getInstance();
     $example = new OW_Example();
     $example->andFieldEqual('userId', $userId);
     $example->setOrder('createDatetime DESC');
     $example->setLimitClause($start, $offset);
     $albumList = $albumDao->findListByExample($example);
     $albumListIds = array();
     foreach ($albumList as $album) {
         $albumListIds[] = $album->id;
     }
     $covers = $service->getAlbumCoverForList($albumIdList);
     $out = array();
     foreach ($albumList as $album) {
         $out[] = array('id' => $album->id, 'cover' => $covers[$album->id], 'name' => $album->name);
     }
     return $out;
 }
Exemplo n.º 7
0
 public function getPhotoListByIdList(array $idList)
 {
     if (empty($idList)) {
         return array();
     }
     $sql = 'SELECT `p`.*, `a`.`userId`
         FROM `' . $this->getTableName() . '` AS `p`
             INNER JOIN `' . PHOTO_BOL_PhotoAlbumDao::getInstance()->getTableName() . '` AS `a` ON(`p`.`albumId` = `a`.`id`)
         WHERE `p`.`id` IN(' . $this->dbo->mergeInClause($idList) . ')';
     return $this->dbo->queryForList($sql);
 }
Exemplo n.º 8
0
 /**
  * Get photo list (featured|latest|toprated)
  *
  * @param string $listtype
  * @param int $page
  * @param int $limit
  * @return array
  */
 public function getPhotoList($listtype, $page, $limit, $checkPrivacy = true)
 {
     $config = OW::getConfig();
     $limit = (int) $config->getValue('advancedphoto', 'photofeature_per_page');
     $first = ($page - 1) * $limit;
     $albumDao = PHOTO_BOL_PhotoAlbumDao::getInstance();
     $privacyCond = $checkPrivacy ? " AND `p`.`privacy` = 'everybody' " : "";
     switch ($listtype) {
         case 'featured':
             $photoFeaturedDao = PHOTO_BOL_PhotoFeaturedDao::getInstance();
             $config = OW::getConfig();
             $query = "\n                    SELECT `p`.*, `a`.`userId`\n                    FROM `" . $this->getTableName() . "` AS `p`\n                    LEFT JOIN `" . $albumDao->getTableName() . "` AS `a` ON ( `p`.`albumId` = `a`.`id` )\n                    LEFT JOIN `" . $photoFeaturedDao->getTableName() . "` AS `f` ON (`f`.`photoId`=`p`.`id`)\n                    WHERE `p`.`status` = 'approved' " . $privacyCond . " AND `f`.`id` IS NOT NULL\n                    ORDER BY RAND() \n                    LIMIT :first, :limit";
             break;
         case 'latest':
             $query = "\n\t\t            SELECT `p`.*, `a`.`userId`\n\t\t            FROM `" . $this->getTableName() . "` AS `p`\n\t\t            LEFT JOIN `" . $albumDao->getTableName() . "` AS `a` ON ( `p`.`albumId` = `a`.`id` )\n\t\t            WHERE `p`.`status` = 'approved' " . $privacyCond . "\n\t\t            ORDER BY `p`.`id` DESC\n\t\t            LIMIT :first, :limit";
             break;
     }
     $qParams = array('first' => $first, 'limit' => $limit);
     $cacheLifeTime = $first == 0 ? 24 * 3600 : null;
     $cacheTags = $first == 0 ? array(self::CACHE_TAG_PHOTO_LIST) : null;
     return $this->dbo->queryForList($query, $qParams, $cacheLifeTime, $cacheTags);
 }
Exemplo n.º 9
0
 public function findAlbumNameListByUserId($userId, array $excludeIdList = array())
 {
     return $this->photoAlbumDao->findAlbumNameListByUserId($userId, $excludeIdList);
 }
Exemplo n.º 10
0
 public static function processScheduler($scheduler, $user_aid = null, $limit = 10, $sendNotification = false, $sendActivity = true)
 {
     //register_shutdown_function(array('Ynmediaimporter','handleShutdown'), $scheduler -> id);
     //ini_set('max_execution_time',1);
     $movedCount = 0;
     $movedArray = array();
     $photos = array();
     $schedulerId = $scheduler->id;
     $userId = $scheduler->user_id;
     $user = BOL_UserService::getInstance()->findUserById($userId);
     $album = null;
     $example = new OW_Example();
     $example->andFieldEqual('scheduler_id', $schedulerId);
     $example->andFieldLessThan('status', '3');
     $example->andFieldGreaterThan('status', '0');
     $example->setLimitClause(0, $limit);
     if ($user_aid) {
         $example->andFieldEqual('user_aid', intval($user_aid));
     }
     $nodeList = YNMEDIAIMPORTER_BOL_NodeDao::getInstance()->findListByExample($example);
     $order = 0;
     foreach ($nodeList as $node) {
         if ('photo' == $node->media && $node->user_aid > 0) {
             $album = PHOTO_BOL_PhotoAlbumDao::getInstance()->findById($node->user_aid);
             if (!is_object($album)) {
                 continue;
             }
             //download file
             $dir = Ynmediaimporter::getValidDir();
             $file = $dir . $node->getUUID();
             $privacy = OW::getEventManager()->call('plugin.privacy.get_privacy', array('ownerId' => $album->userId, 'action' => 'photo_view_album'));
             $photo = new PHOTO_BOL_Photo();
             $photo->description = '';
             $photo->albumId = $album->id;
             $photo->addDatetime = time();
             $photo->status = 'approved';
             $photo->hasFullsize = '1';
             $photo->privacy = mb_strlen($privacy) ? $privacy : 'everybody';
             $source = self::saveImageFromUrl($node->getDownloadFilename(), $file);
             $photo = self::__savePhoto($photo, $source, $userId);
             if ($photo) {
                 $photos[] = $photo;
                 $movedArray[] = array('addTimestamp' => time(), 'photoId' => $photo->id);
                 $movedCount++;
             }
             $node->status = 3;
             YNMEDIAIMPORTER_BOL_NodeDao::getInstance()->save($node);
         } else {
             if (in_array($node->media, array('album', 'photoset', 'gallery')) && 0 == $node->user_aid) {
                 // create new albums for this roles
                 $album = self::createPhotoAlbums($scheduler, $node);
                 // setup album and node.
                 // update all sub node of current scheduler to this albums.
                 $example = new OW_Example();
                 $example->andFieldEqual('scheduler_id', $schedulerId);
                 $example->andFieldEqual('aid', $node->aid);
                 $nodeTemp = YNMEDIAIMPORTER_BOL_NodeDao::getInstance()->findObjectByExample($example);
                 $nodeTemp->user_aid = $album->id;
                 $nodeTemp->status = '1';
                 YNMEDIAIMPORTER_BOL_NodeDao::getInstance()->save($nodeTemp);
                 $node->user_aid = $album->id;
                 $node->status = 1;
                 YNMEDIAIMPORTER_BOL_NodeDao::getInstance()->save($node);
                 self::processScheduler($scheduler, $album->id, 10, 0, 0);
                 break;
                 // force process this album to escape no value style.
             }
         }
     }
     $example = new OW_Example();
     $example->andFieldEqual('scheduler_id', $schedulerId);
     $example->andFieldEqual('media', 'photo');
     $example->andFieldLessThan('status', '3');
     $remain = intval(YNMEDIAIMPORTER_BOL_NodeDao::getInstance()->countByExample($example));
     // all scheduler is completed. send notification to users
     if (is_object($album) && $remain == 0) {
         // Send notification
         if ($sendNotification) {
             $actor = array('username' => BOL_UserService::getInstance()->getUserName($userId), 'name' => BOL_UserService::getInstance()->getDisplayName($userId), 'url' => BOL_UserService::getInstance()->getUserUrl($userId));
             $avatars = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($userId));
             $event = new OW_Event('notifications.add', array('pluginKey' => 'ynmediaimporter', 'entityType' => 'ynmediaimporter_album', 'entityId' => (int) $album->id, 'action' => 'ynmediaimporter_album-added', 'userId' => $album->userId, 'time' => time()), array('avatar' => $avatars[$userId], 'string' => array('key' => 'ynmediaimporter+added_album_notification_string', 'vars' => array('actor' => $actor['name'], 'actorUrl' => $actor['url'], 'title' => $album->name, 'url' => OW::getRouter()->urlForRoute('photo_user_album', array('user' => $actor['username'], 'album' => $album->id)))), 'content' => $album->name, 'url' => OW::getRouter()->urlForRoute('photo_user_album', array('user' => $actor['username'], 'album' => $album->id))));
             OW::getEventManager()->trigger($event);
         }
         if ($sendActivity) {
             self::__sendActivity($album, $photos, $movedArray, $movedCount);
         }
     }
     $scheduler->status = $remain == 0 ? 3 : 1;
     $scheduler->last_run = time();
     YNMEDIAIMPORTER_BOL_SchedulerDao::getInstance()->save($scheduler);
     // and of process rec count all
     $tableName = OW_DB_PREFIX . 'ynmediaimporter_nodes';
     $sql = "SELECT\n\t\t\t\t  album.id,\n\t\t\t\t  (SELECT\n\t\t\t\t     COUNT( * )\n\t\t\t\t   FROM {$tableName} AS photo\n\t\t\t\t   WHERE photo.media = 'photo'\n\t\t\t\t       AND photo.aid = album.id\n\t\t\t\t       AND photo.status = 1) AS remaining\n\t\t\t\tFROM `{$tableName}` album\n\t\t\t\tWHERE album.media <> 'photo'\n\t\t\t\t    AND album.status = 1\n\t\t\t\tGROUP BY album.id\n\t\t\t\tHAVING remaining = 0";
     $completedList = OW::getDbo()->queryForColumnList($sql);
     if ($completedList) {
         $sql = "UPDATE `{$tableName}` SET `status` = '3' where `id` IN (" . implode(',', $completedList) . ")";
         OW::getDbo()->query($sql);
     }
     return array('remain' => $remain, 'scheduler_id' => $schedulerId);
 }
Exemplo n.º 11
0
 public function findPhotoListByAlbumId($albumId, $page, $limit, array $exclude = array())
 {
     if (!$albumId || ($album = PHOTO_BOL_PhotoAlbumDao::getInstance()->findById($albumId)) === NULL) {
         return array();
     }
     $first = ($page - 1) * $limit;
     $photos = $this->photoDao->getAlbumPhotoList($albumId, $first, $limit, $this->isCheckPrivacy($album->userId), $exclude);
     if ($photos) {
         foreach ($photos as $key => $photo) {
             $photos[$key]['url'] = $this->getPhotoUrlByType($photo['id'], self::TYPE_PREVIEW, $photo['hash'], !empty($photo['dimension']) ? $photo['dimension'] : FALSE);
         }
     }
     return $photos;
 }
Exemplo n.º 12
0
 public function countEntityPhotos($entityType, $entityId, $status = "approved")
 {
     $photoAlbumDao = PHOTO_BOL_PhotoAlbumDao::getInstance();
     $statusSql = $status === null ? "1" : "`p`.`status` = '{$status}'";
     $query = "\n            SELECT COUNT(`p`.`id`)\n            FROM `" . $this->getTableName() . "` AS `p`\n            LEFT JOIN `" . $photoAlbumDao->getTableName() . "` AS `a` ON ( `a`.`id` = `p`.`albumId` )\n            WHERE {$statusSql} AND `a`.`entityType` = :entityType AND `a`.`entityId`=:entityId\n        ";
     return $this->dbo->queryForColumn($query, array("entityType" => $entityType, "entityId" => $entityId));
 }