Example #1
0
 /**
  * The setter of the field uid.
  * @param User $user - the user which the meta belongs to
  */
 public function setUser(User $user)
 {
     if ($user == NULL) {
         throw new InvalidArgumentException('[Model\\UserMeta] Invalid Model\\User.');
     }
     $this->uid = $user->getUid();
 }
 /**
  * If user has cookie 'ref' then we create record
  * in USER_REFERRER and it will contain the url
  * from which use initially came from on his first visit
  * (before he was even registered)
  *
  * @param Registry $Registry
  * @param User     $User
  *
  * @return void
  */
 public static function createReferrerRecord(Registry $Registry, User $User)
 {
     $ref = !empty($_COOKIE['ref']) ? \filter_input(INPUT_COOKIE, 'ref', FILTER_SANITIZE_URL) : '';
     if (!empty($ref)) {
         $a = array('users_id' => $User->getUid(), 'referer_url' => $ref);
         $Registry->Mongo->USER_REFEREF->insert($a);
     }
 }
Example #3
0
 public static function get(Registry $Registry, User $User)
 {
     $uid = $User->getUid();
     if (0 === $uid) {
         d('not registered user');
         return '';
     }
     $pagerLinks = '';
     /**
      * Default pager path
      */
     $pagerPath = '/tab/a/' . $uid . '/oldest';
     $cond = $Registry->Request->get('sort', 's', 'recent');
     switch ($cond) {
         case 'oldest':
             $sort = array('_id' => 1);
             $pagerPath = '/tab/a/' . $uid . '/recent';
             break;
         case 'voted':
             $sort = array('i_votes' => -1);
             $pagerPath = '/tab/a/' . $uid . '/voted';
             break;
         case 'updated':
             $sort = array('i_lm_ts' => -1);
             $pagerPath = '/tab/a/' . $uid . '/updated';
             break;
         case 'best':
             $sort = array('accepted' => -1);
             $pagerPath = '/tab/a/' . $uid . '/best';
             break;
         default:
             $sort = array('_id' => -1);
             $pagerPath = '/tab/a/' . $uid . '/oldest';
             break;
     }
     $cursor = self::getCursor($Registry, $uid, $sort);
     $count = $cursor->count(true);
     d('$count: ' . $count);
     /**
      * If this user does not have any answers then return
      * empty string, skip any unnecessary template parsing
      */
     if (0 == $count) {
         d('no user answers');
         return '';
     }
     $pageID = $Registry->Request->get('pageID', 'i', 1);
     if ($count > self::PER_PAGE || $pageID > 1) {
         $oPaginator = Paginator::factory($Registry);
         $oPaginator->paginate($cursor, self::PER_PAGE, array('path' => $pagerPath));
         $pagerLinks = $oPaginator->getLinks();
         d('$pagerPath: ' . $pagerPath . ' pagerLinks: ' . $pagerLinks);
     }
     $answers = \tplUanswers::loop($cursor);
     d('$answers: ' . $answers);
     $vals = array('count' => $count, 'answers' => $answers, 'pagination' => $pagerLinks);
     return \tplUserAnswers::parse($vals);
 }
 public static function get(Registry $Registry, User $User)
 {
     $uid = $User->getUid();
     $db = $Registry->Mongo->getDb();
     $map = new \MongoCode("function() { emit(this.t, 1); }");
     $reduce = new \MongoCode("function(k, vals) { " . "var sum = 0;" . "for (var i in vals) {" . "sum += vals[i];" . "}" . "return sum; }");
     $votes = $db->command(array("mapreduce" => "VOTES", "map" => $map, "reduce" => $reduce, "query" => array("i_uid" => $uid)));
     if (empty($votes) || empty($votes['result'])) {
         return '';
     }
     $counter = $db->selectCollection($votes['result'])->find();
     $total = 0;
     $s = '';
     foreach ($counter as $vote) {
         $vars = array('type' => $vote['_id'], 'count' => $vote['value']);
         $total += $vote['value'];
         $s .= \tplVoteCount::parse($vars, false);
     }
     $ret = \tplUserVotes::parse(array('count' => $total, 'stats' => $s, 'username' => $User->getDisplayName()));
     return $ret;
 }
 /**
  *
  * Adds a_edited array of data to Question
  *
  * @param User $user
  * @param string $reason reason for editing
  *
  * @return object $this
  */
 public function setEdited(User $user, $reason = '')
 {
     if (!empty($reason)) {
         $reason = \strip_tags((string) $reason);
     }
     $aEdited = $this->offsetGet('a_edited');
     if (empty($aEdited) || !is_array($aEdited)) {
         $aEdited = array();
     }
     $aEdited[] = array('username' => $user->getDisplayName(), 'i_uid' => $user->getUid(), 'av' => $user->getAvatarSrc(), 'reason' => $reason, 'hts' => date('F j, Y g:i a T'));
     parent::offsetSet('a_edited', $aEdited);
     return $this;
 }
Example #6
0
 /**
  * @todo finish this
  *
  * Finds and parses common tags a Viewer has
  * with User whos profile user is viewing
  *
  * @param User $oViewer
  * @param array $userTags
  */
 public static function getCommonTags(User $oViewer, array $userTags)
 {
     $uid = $oViewer->getUid();
     if (0 === $uid) {
         return '';
     }
     $aTags = $Registry->Mongo->USER_TAGS->findOne(array('_id' => $uid));
     if (empty($aTags) || empty($aTags['tags'])) {
         d('no tags for user: '******'';
     }
     $viewerTags = $aTags['tags'];
     $aCommon = array_intersect_key($viewerTags, $userTags);
     d('aCommon: ' . print_r($aCommon, 1));
     if (empty($aCommon)) {
         d('no common tags');
         return '';
     }
 }
Example #7
0
 /**
  * The setter of the field product_developer_id.
  * @param User $developer - the developer of the product
  */
 public function setDeveloper(User $developer)
 {
     if ($developer == NULL) {
         throw new InvalidArgumentException('[Model\\Product] Invalid developer (Model\\User).');
     }
     $this->product_developer_id = $developer->getUid();
 }
 /**
  * Create session for users who have signed in.
  * @param  Session $session - the HTTP Session
  * @param  User $user - the user object of current user
  */
 private function getSession($session, $user)
 {
     $session->set('isLoggedIn', true);
     $session->set('uid', $user->getUid());
 }
 /**
  *
  * Get block with links to tags that User is following
  * and also possibly a block on tags that both Viewer and User
  * are following
  *
  * @param Registry $Registry
  * @param User $User
  *
  * @return string html
  */
 public static function get(Registry $Registry, User $User)
 {
     $aUserTags = $User['a_f_t'];
     if (empty($aUserTags)) {
         return '';
     }
     if (count($aUserTags) > self::MAX_TO_SHOW) {
         $aUserTags = \array_slice($aUserTags, 0, self::MAX_TO_SHOW);
     }
     /**
      * @todo Translate string
      */
     $blockTitle = $User->getDisplayName() . ' is following these tags';
     $tags = $commonTags = '';
     $tags = \tplTagLink::loop($aUserTags, false);
     /**
      * If Viewer is not the same user as user whose profile
      * being viewer then attempt to get the 'common' tags
      * that both viewer and user are following
      */
     if ($User->getUid() !== $Registry->Viewer->getUid()) {
         $commonTags = self::getCommonTags($aUserTags, $Registry->Viewer['a_f_t']);
     }
     $vals = array('count' => $blockTitle, 'label' => 'tag', 'tags' => $tags);
     $ret = \tplUserTags::parse($vals);
     return $ret . $commonTags;
 }
Example #10
0
 public function getPostUid()
 {
     return User::getUid($this->post_by);
 }
Example #11
0
    $res_user = $db->executeQuery($sel_user);
} catch (MySQLException $ex) {
    print "ko;" . $ex->getMessage();
    exit;
}
if ($res_user->num_rows < 1) {
    print "ko;Nessun utente presente: {$sel_user}";
    exit;
}
$utente = $res_user->fetch_assoc();
$gid = split(",", $utente['gruppi']);
$user = new User($utente['uid'], $utente['nome'], $utente['cognome'], $gid, $utente['permessi']);
/**
 * profile
 */
$sel_profile = "SELECT * FROM profili WHERE id = " . $user->getUid();
try {
    $res_profile = $db->executeQuery($sel_profile);
} catch (MySQLException $ex) {
    print "ko;" . $ex->getMessage();
    exit;
}
if ($res_profile->num_rows) {
    $profile = $res_profile->fetch_assoc();
    $user->setProfile($profile);
}
/**
 * subjects and classes : only for teachers
 */
if ($user->isTeacher()) {
    $sel_subject = "SELECT materia FROM docenti WHERE id_docente = " . $user->getUid();
Example #12
0
 /**
  * The setter of the field issue_reply_submiter_uid
  * @param User $submiter - the user who submit the the reply
  */
 public function setSubmiter(User $submiter)
 {
     if ($submiter == NULL) {
         throw new InvalidArgumentException('[Model\\IssueReply] Invalid Model\\User.');
     }
     $this->issue_reply_submiter_uid = $submiter->getUid();
 }
Example #13
0
 /**
  * The setter of the field issue_hunter_id.
  * @param User $hunter - the hunter of the issue
  */
 public function setHunter(User $hunter)
 {
     if ($hunter == NULL) {
         throw new InvalidArgumentException('[Model\\Issue] Invalid Model\\User.');
     }
     $this->issue_hunter_id = $hunter->getUid();
 }
 /**
  * Get html block with User's followers
  *
  * @param User $User
  *
  * @return string html
  */
 public function getUserFollowers(User $User)
 {
     $uid = $User->getUid();
     d('uid: ' . $uid);
     $where = array('a_f_u' => $uid);
     $this->Cursor = $this->Registry->Mongo->USERS->find($where, array('_id', 'i_rep', 'username', 'fn', 'mn', 'ln', 'email', 'avatar', 'avatar_external'));
     $total = $this->Cursor->count();
     d('total followers: ' . $total);
     if (0 === $total) {
         d('no followers');
         return '';
     }
     /**
      * @todo translate string title
      *
      */
     $title = $total . ' ';
     $title .= 1 === $total ? 'Follower' : 'Followers';
     d('followers title: ' . $title);
     $func = null;
     $aGravatar = $this->Registry->Ini->getSection('GRAVATAR');
     if (count($aGravatar) > 0) {
         $func = function (&$a) use($aGravatar) {
             $a['gravatar'] = $aGravatar;
         };
     }
     $followers = \tplOneFollower::loop($this->Cursor, true, $func);
     return \tplFollowers::parse(array($title, $followers, $total), false);
 }
Example #15
0
 /**
  * Update the meta data of the user.
  * @param  User  $user       - the user who wants to update meta data
  * @param  String $metaKey   - the key of the meta
  * @param  String $metaValue - the value of the meta
  */
 private function updateUserMeta($user, $metaKey, $metaValue)
 {
     $userMeta = UserMeta::findFirst(array('conditions' => 'uid = ?1 AND meta_key = ?2', 'bind' => array(1 => $user->getUid(), 2 => $metaKey)));
     if ($userMeta == NULL) {
         if (empty($metaValue)) {
             return;
         }
         $userMeta = new UserMeta();
         $userMeta->setUser($user);
         $userMeta->setMetaKey($metaKey);
         $userMeta->setMetaValue($metaValue);
         $userMeta->create();
     } else {
         $userMeta->setMetaValue($metaValue);
         $userMeta->update();
     }
 }
Example #16
0
/**
 * Check to see if User $user is owner of Resource $resource
 * @param Resource $resource
 * @param User $user
 *
 * @return bool true if User is owner of Resource
 */
function isOwner(User $user, \Lampcms\Interfaces\LampcmsResource $resource)
{
    $uid = $user->getUid();
    return $uid > 0 && $uid === $resource->getOwnerId();
}
 /**
  *
  * Get parsed html of user questions div,
  * complete with pagination
  *
  * @todo there has to be an extra request param "tab" and ONLY if
  *       it equals to 'questions' then it would mean
  *       that sort and pagination is for this block because it could
  *       be for 'answer' block since they both come to the same controller
  *       OR just make separate controllers and then pagination and sorting
  *       will work ONLY with AJAX  and then just hide pagination from
  *       non-js browsers!
  *
  * @param Registry $Registry
  * @param User     $User
  *
  * @return string html of user questions
  */
 public static function get(Registry $Registry, User $User)
 {
     $perPage = $Registry->Ini->PROFILE_QUESTIONS_PER_PAGE;
     $uid = $User->getUid();
     if (0 === $uid) {
         d('not registered user');
         return '';
     }
     /**
      * @var string
      */
     $pagerLinks = '';
     /**
      * @var int
      */
     $pageID = $Registry->Router->getPageID();
     /**
      * @var array
      */
     $aUriMap = $Registry->Ini->getSection('URI_PARTS');
     //$mode = $Registry->Request->get('tab', 's', '');
     /**
      * sort order possible values:
      * recent, oldest, voted, updated, views
      *
      * default is oldest first
      *
      * $mode 'questions' means that user requested
      * either pagination or sorting specifically
      * for the User Questions
      * This is not necessarily an ajax request as pagination
      * will work without Ajax too.
      *
      * When there is no explicit 'questions' $mode
      * then we need to just get the cursor
      * with default sort and pageID, treating this
      * request as if it was for pageID 1 and sort=oldest
      */
     //if('q' === $mode){
     $cond = $Registry->Router->getSegment(3, 's', $aUriMap['SORT_RECENT']);
     d('$cond: ' . $cond);
     switch ($cond) {
         case $aUriMap['SORT_RECENT']:
             $sort = array('i_ts' => -1);
             $pagerPath = '{_WEB_ROOT_}/{_userinfotab_}/q/' . $uid . '/{_SORT_RECENT_}';
             break;
         case $aUriMap['SORT_VOTED']:
             $sort = array('i_votes' => -1);
             $pagerPath = '{_WEB_ROOT_}/{_userinfotab_}/q/' . $uid . '/{_SORT_VOTED_}';
             break;
         case $aUriMap['SORT_UPDATED']:
             $sort = array('i_etag' => -1);
             $pagerPath = '{_WEB_ROOT_}/{_userinfotab_}/q/' . $uid . '/{_SORT_UPDATED_}';
             break;
         case $aUriMap['SORT_VIEWS']:
             $sort = array('i_views' => -1);
             $pagerPath = '{_WEB_ROOT_}/{_userinfotab_}/q/' . $uid . '/{_SORT_VIEWS_}';
             break;
         default:
             $sort = array('i_ts' => 1);
             $pagerPath = '{_WEB_ROOT_}/{_userinfotab_}/q/' . $uid . '/{_SORT_OLDEST_}';
             break;
     }
     //}
     $cursor = self::getCursor($Registry, $uid, $sort);
     $count = $cursor->count(true);
     d('$count: ' . $count);
     /**
      * If this user does not have any questions then return
      * empty string
      */
     if (0 == $count) {
         d('no user questions');
         return '';
     }
     if ($count > $perPage || $pageID > 1) {
         $Paginator = Paginator::factory($Registry);
         $Paginator->paginate($cursor, $perPage, array('path' => $pagerPath, 'currentPage' => $pageID));
         $pagerLinks = $Paginator->getLinks();
         d('links: ' . $pagerLinks);
     }
     $questions = \tplUquestions::loop($cursor);
     $vals = array('{count}' => $count, '{questions}' => $questions, '{pagination}' => $pagerLinks);
     return \tplUserQuestions::parse($vals);
 }
Example #18
0
 /**
  *
  * Get parsed html of user questions div,
  * complete with pagination
  *
  * @todo there has to be an extra request param "tab" and ONLY if
  * it equals to 'questions' then it would mean
  * that sort and pagination is for this block because it could
  * be for 'answer' block since they both come to the same controller
  * OR just make separate controllers and then pagination and sorting
  * will work ONLY with AJAX  and then just hide pagination from
  * non-js browsers!
  *
  * @param Registry $Registry
  * @param User $User
  *
  * @return string html of user questions
  */
 public static function get(Registry $Registry, User $User)
 {
     $uid = $User->getUid();
     if (0 === $uid) {
         d('not registered user');
         return '';
     }
     $pagerLinks = '';
     $pageID = $Registry->Request->get('pageID', 'i', 1);
     /**
      * Default pager path
      */
     $pagerPath = '/tab/q/' . $uid . '/recent';
     /**
      * Default sort condition
      *
      * @var array
      */
     $sort = array('i_ts' => 1);
     //$mode = $Registry->Request->get('tab', 's', '');
     /**
      * sort order possible values:
      * recent, oldest, voted, updated, views
      *
      * default is oldest first
      *
      * $mode 'questions' means that user requested
      * either pagination or sorting specifically
      * for the User Questions
      * This is not necessaraly an ajax request as pagination
      * will work without Ajax too.
      *
      * When there is no explicit 'questions' $mode
      * then we need to just get the cursor
      * with default sort and pageID, treating this
      * request as if it was for pageID 1 and sort=oldest
      */
     //if('q' === $mode){
     $cond = $Registry->Request->get('sort', 's', 'recent');
     switch ($cond) {
         case 'recent':
             $sort = array('i_ts' => -1);
             $pagerPath = '/tab/q/' . $uid . '/recent';
             break;
         case 'voted':
             $sort = array('i_votes' => -1);
             $pagerPath = '/tab/q/' . $uid . '/voted';
             break;
         case 'updated':
             $sort = array('i_etag' => -1);
             $pagerPath = '/tab/q/' . $uid . '/updated';
             break;
         case 'views':
             $sort = array('i_views' => -1);
             $pagerPath = '/tab/q/' . $uid . '/views';
             break;
         default:
             $sort = array('i_ts' => 1);
             $pagerPath = '/tab/q/' . $uid . '/oldest';
             break;
     }
     //}
     $cursor = self::getCursor($Registry, $uid, $sort);
     $count = $cursor->count(true);
     d('$count: ' . $count);
     /**
      * If this user does not have any questions then return
      * empty string
      */
     if (0 == $count) {
         d('no user questions');
         return '';
     }
     if ($count > self::PER_PAGE || $pageID > 1) {
         $oPaginator = Paginator::factory($Registry);
         $oPaginator->paginate($cursor, self::PER_PAGE, array('path' => $pagerPath));
         $pagerLinks = $oPaginator->getLinks();
         d('links: ' . $pagerLinks);
     }
     $questions = \tplUquestions::loop($cursor);
     d('questions: ' . $questions);
     $vals = array('{count}' => $count, '{questions}' => $questions, '{pagination}' => $pagerLinks);
     return \tplUserQuestions::parse($vals);
 }
Example #19
0
 /**
  * Process follow user request
  *
  * @param Object $User object of type User user who follows
  * @param int $userid id user being followed (followee)
  *
  * @return object $this
  */
 public function followUser(User $User, $userid)
 {
     if (!is_int($userid)) {
         throw new \InvalidArgumentException('$userid must be an integer');
     }
     $aFollowed = $User['a_f_u'];
     d('$aFollowed: ' . print_r($aFollowed, 1));
     if (in_array($userid, $aFollowed)) {
         e('User ' . $User->getUid() . ' is already following $userid ' . $userid);
         return $this;
     }
     $this->Registry->Dispatcher->post($User, 'onBeforeUserFollow', array('uid' => $userid));
     $aFollowed[] = $userid;
     $User['a_f_u'] = $aFollowed;
     $User['i_f_u'] = count($aFollowed);
     $User->save();
     $this->Registry->Dispatcher->post($User, 'onUserFollow', array('uid' => $userid));
     $this->Registry->Mongo->USERS->update(array('_id' => $userid), array('$inc' => array('i_flwrs' => 1)));
     return $this;
 }