Whenever comment on any issue, last comment username not update in issues - php

Whenever comment on any one of the issues, comment save successfully.
Comment saving code in given below:
$user = elgg_get_logged_in_user_entity();
$p_url = parse_url($_SERVER['HTTP_REFERER']);
if($p_url['path'] == '/issues/view' || $p_url['path'] == '/issues/respond')
$tracker_comment = TRUE;
else
$tracker_comment = FALSE;
if($tracker_comment)
{
action_gatekeeper();
// Get input
$entity_guid = (int) get_input('entity_guid');
$comment_text = get_input('generic_comment');
// Let's see if we can get an entity with the specified GUID
if ($entity = get_entity($entity_guid)) {
$comment = new ElggComment();
$comment->description = $comment_text;
$comment->owner_guid = $user->getGUID();
$comment->container_guid = $entity->getGUID();
$comment->access_id = $entity->access_id;
$guid = $comment->save();
// If posting the comment was successful, say so
if ($guid) {
system_message(elgg_echo("generic_comment:posted"));
} else {
register_error(elgg_echo("generic_comment:failure"));
}
} else {
register_error(elgg_echo("generic_comment:notfound"));
}
// Forward to the
forward($entity->getURL());
}
else
RETURN TRUE;
I am unable to retrieve the last comment username not updated in list of issues. I am using elgg_get_annotation() to retrieve the last comment details.
But not retrieving the details. Last comment code in given bellow.
if ($table_rows) {
foreach ( $table_rows as $entity ) {
if ($entity->unread == 1) {
$unread = "Yes";
} else {
$unread = "No";
}
if ($entity->assigned_to == 0) {
$assigned = "No";
} else {
$assigned = "Yes";
}
$last_options = array ();
$comments = elgg_get_annotations(array(
'annotation_names' => 'issue_tracker_changes',
'guid' => $entity->guid,
'limit' => 1,
'order_by' => 'n_table.id DESC',
));
foreach ( $comments as $comment ) {
$last_comment = get_entity ( $comment->owner_guid );
}

Comments are no longer annotations since Elgg 1.9 but entities. You are creating comment using ElggComment class that represents entity so you're using Elgg 1.9 or newer. You just need to use elgg_get_entities instead of elgg_get_annotations. Use type object and subtype comment.

Related

else condition is working even if is true

I'm using codigniter 3.1.2 and using simple if condition in php but really confused when I checked my condition is true getting result from else condition as well and if as well mean getting data in from both cases.
public function editexperience($UserID = 0, $ID = 0) {
if ($this->Access->HaveAccess('Edit')) {
$Row = $this->Experience->Row($ID);
if ($ID > 0 && $Row){
print_r($Row);
Def(array(
'Update'=>'users/submit/updateexperience/'
),'Actions');
$User = $this->Model->Row(intval($UserID), '', 'CTRY.Currency');
$ID = intval($ID);
$Data['Row'] = $Row;
Def($Row,'Row');
$Data['Title'] = 'Edit Experience';
$Data['Fields'] = $this->GetExperienceFields($User->Currency, true);
$this->Main->SetPage('Helper/Edit', $Data, true);
} else {
TempNote('There is problem while getting request data!', 'Error');
redirect(URI(_E('{Page.List}'), true), 'refresh');
die();
}
}
}
In code I mentioned if I have Row then load template of edit.
Suppose:
I have Row and its loading edit template and also showing the error of else condition really confuse what is happening.
My PHP version is 5.6.31
TempNote Function
function TempNote($Message, $Type) {
//Prepare Data
$Current = array('Message'=>$Message,'Type'=>$Type);
//Get current instance
$Ins = & get_instance();
$Old = $Ins->Main->Messages;
// If another is already set and that should not be current
if (!empty($Old)) {
foreach ($Old as $Key=>$Now) {
if ($Now === $Current){
unset($Old[$Key]);
}
}
}
$Ins->Main->Messages[] = $Current;
$Ins->session->set_flashdata('Message', $Ins->Main->Messages);
}

Laravel Session works on Chrome, Not on Iphone

I have created a system where users can search for payment solutions for their business here: http://104.236.45.72/
When you click an answer for a question, you'll notice that as you click through on chrome, you get a list at the top of previously answered questions.
When you view this same thing on your mobile device, you'll notice that the questions as the top only show ONE. It's like the session is not persisting on mobile. I have no idea why and I've tried changing the session driver from database to file and tried replacing all of the "$request->session->" references with "Session::", which leads to the same thing, it working on desktop and only showing one previous answer on mobile.
Here is the function being called when you answer a question on the fontend.
public function questions(Request $request, $id, $parentId, $question)
{
//Get the industry...
$data['industry'] = Industries::find($id);
//Get the parent level question and one child...
$data['parentQuestion'] = Questions::where('parentId', $parentId)->where('industryId', $id)->get();
if(count($data['parentQuestion']) > 0) {
foreach($data['parentQuestion'] as $pq) {
if($pq->parentId != 0) {
//How many steps are currently in the array?
if ($request->session()->has('lastSteps')) {
$hasLastSteps = TRUE;
}else {
$hasLastSteps = FALSE;
}
$stepCount = 1;
if($hasLastSteps == TRUE) {
$stepCount += count(Session('lastSteps'));
}
//Get the last steps ready...
$lsQuestion = Questions::find($question);
$lsAnswer = Questions::find($parentId);
$lsQ = array(
'unique' => uniqid(),
'questionId' => $question,
'question' => $lsQuestion->question,
'answer' => $lsAnswer->question,
'url' => '/'.$request->path(),
'stepCount' => $stepCount
);
$dup = 0;
//see if the session has a lastSteps array...
if ($hasLastSteps == TRUE) {
$temp = Session('lastSteps');
foreach($temp as $t) {
if($t['questionId'] == $question) {
$dup = 1;
}
}
}
//No duplicates exist, go ahead and add it to the session!
if($dup === 0) {
$request->session()->push('lastSteps', $lsQ);
}
}
//Grab its children...
if($pq->type === 'question') {
$data['children'] = Questions::where('industryId', $id)->where('parentId', $pq->id)->get();
}else {
//its an endpoint / answer!
}
}
}
//see if the session has a follow up array...
if ($request->session()->has('followUp')) {
$data['followUp'] = Session('followUp');
}else {
$data['followUp'] = array();
}
//see if the session has a lastSteps array...
if ($request->session()->has('lastSteps')) {
$data['lastSteps'] = Session('lastSteps');
}else {
$data['lastSteps'] = array();
}
return view('frontend.questions', $data);
}

PDO Update 1 column multiple rows with array

I am struggling to workout a good method to update one column of my wcx_options table.
The new data is sent fine to the controller but my function isn't working at all.
I assumed i could loop through each column by option_id updating with the values from the array.
The database:
I update the option_value column with the new information via a jQuery AJAX Call to a controller which then calls a function from the backend class.
So far i have the following code:
if(isset($_POST['selector'])) {
if($_POST['selector'] == 'general') {
if($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' && isset($_POST['token'])
&& $_POST['token'] === $_SESSION['token']){
$site_name = $_POST['sitename'];
$site_url = $_POST['siteurl'];
$site_logo = $_POST['sitelogo'];
$site_tagline = $_POST['sitetagline'];
$site_description = $_POST['sitedescription'];
$site_admin = $_POST['siteadmin'];
$admin_email = $_POST['adminemail'];
$contact_info = $_POST['contactinfo'];
$site_disclaimer = $_POST['sitedisclaimer'];
$TimeZone = $_POST['TimeZone'];
$options = array($site_name, $site_url, $site_logo, $site_tagline, $site_description, $site_admin, $admin_email,$contact_info, $site_disclaimer, $TimeZone);
// Send the new data as an array to the update function
$backend->updateGeneralSettings($options);
}
else {
$_SESSION['status'] = '<div class="error">There was a Problem Updating the General Settings</div>';
}
}
}
This is what i have so far in terms of a function (It doesnt work):
public function updateGeneralSettings($options) {
$i = 1;
foreach($options as $option_value) {
$where = array('option_id' => $i);
$this->queryIt("UPDATE wcx_options SET option_value='$option_value' WHERE option_id='$where'");
$i++;
}
if($this->execute()) {
$_SESSION['success'] = 'Updated General Settings Successfully';
}
}
With the given DB-layout i'd suggest to organize your data as assiciative array using the db fieldnames, like:
$option = array(
'site_name' => $_POST['sitename'],
'site_url' => $_POST['siteurl'],
// etc.
'timeZone' => $_POST['TimeZone']
);
And than use the keys in your query:
public function updateGeneralSettings($options) {
foreach($options as $key => $value) {
$this->queryIt("UPDATE wcx_options SET option_value='$value' WHERE option_name='$key'");
if($this->execute()) {
$_SESSION['success'] = 'Updated General Settings Successfully';
}
}
}
(However, are you sure, you do not want to have all options together in one row?)
Change your query, you try to use an array as where condition. In the syntax you used that won't work. Just use the counter as where condition instead of define a $where variable. Try this:
public function updateGeneralSettings($options) {
$i = 1;
foreach($options as $option_value) {
$this->queryIt("UPDATE wcx_options SET option_value='$option_value' WHERE option_id='$i'");
$i++;
}
if($this->execute()) {
$_SESSION['success'] = 'Updated General Settings Successfully';
}
}

I need help to understand JSON Elements (Response Messages) from this function

I am working on a project that previously done with another developer. This project based on PHP Yii framework and mobile side is Android to get JSON messages from the web services that provided in the website.
I'm stuck in this web service function "getStamp"
I don't know what are the JSON response messages. I mean what are the string Values that I'll hold for 'stampID', 'stampName', 'stampImg'.
These are the information that I have:
request parameters:
kioskid
accesstoken
tagid
eventid
checking = 0 or 1
for failed response:
status = 0
message = error message
for success response:
status = 1
tappedStamp = the obtain stamp ID after tapping the device (if checking not equal to 1)
message = the message of the obtained stamp (if checking not equal to 1)
collectedStamp = list of collected stamp ID
If you want to use 'getStamp' web service to do the checking on how
many stamps that have been collected by the user, then you pass
'checking' as 1. If you want to use that web service to collect the
stamp of the kiosk, then you pass 'checking' as 0.
So far as what I understand from the Code and explanation that 'collectedStamp' and 'tappedStamp' are JSON Object names of a JSON Arrays
I need to know these 3 Elements (I suppose to get it from some where the names are random not real I just make it to explain to you what need)
'stampID', 'stampName','stampImg'
{ "collectedStamp" : [ { "stampID" : "1",
"stampName" : "stamp1",
"stampImg": "stamp1.png"
},
{ "stampID" : "2",
"stampName" : "stamp2",
"stampImg": "stamp2.png"
},
],
"status" : "1"
}
{ "tappedStamp" : [ { "stampID" : "1",
"stampName" : "stamp1",
"stampImg": "stamp1.png"
},
{ "stampID" : "2",
"stampName" : "stamp2",
"stampImg": "stamp2.png"
},
],
"status" : "1"
}
For Android Implementation most likely I'll use the same code that I provided in this post
Errors when getting JSON result into ListView
if you see in the web service function in that link you'll find this
$list = array();
foreach($events as $row){
$list[] = array('id'=>$row->id, 'name'=>$row->eventname);
}
$response['status'] = '1';
$response['list'] = $list;
}
which means that that the JSON response['list'] Contains 'id' and 'name' objects
and these are the String values that I add it inside ListView Adapter
I need to know the equivalent to 'id' and 'name' in this web Service
getStamp() Web Service Function:
public function actionGetStamp(){
if(isset($_POST['kioskid']) && isset($_POST['accesstoken']) && isset($_POST['tagid']) && isset($_POST['eventid']) && isset($_POST['checking'])){
$response = array();
$kiosk = Kiosk::model()->findByAttributes(array('kioskid'=>$_POST['kioskid'], 'accesstoken'=>$_POST['accesstoken']));
if(($kiosk === null || $kiosk->eventid != $_POST['eventid']) && $_POST['accesstoken'] != 'REPOST_SYNC'){
$response['status'] = '0';
$response['message'] = 'Invalid Kiosk';
} else {
$eventStation = EventStation::model()->findByAttributes(array('eventid'=>$_POST['eventid'],'deviceid'=>$_POST['kioskid']));
if($eventStation === null){
$response['status'] = '0';
$response['message'] = 'Invalid Kiosk';
} else {
$tag = EventTag::model()->findByAttributes(array('tagid'=>$_POST['tagid'], 'eventid'=>$eventStation->eventid, 'status'=>'A'));
if($tag === null || $tag->joinon == null){
$response['status'] = '0';
$response['message'] = 'Tag is not registered yet.';
} else {
$sql = 'SELECT es.id, (CASE WHEN esc.stampid IS NULL THEN 0 ELSE 1 END) collected,
(CASE WHEN es.kioskid = :kioskid THEN 1 ELSE 0 END) tapped,
es.message
FROM tap_event_stamp es
LEFT JOIN tap_event_stamp_collection esc ON es.id = esc.stampid and esc.tagid = :tagid
WHERE es.eventid = :eventid AND es.isdeleted = 0
GROUP BY es.id ORDER BY es.id
';
$params = array(':eventid'=>$_POST['eventid'], ':kioskid'=>$eventStation->id, ':tagid'=>$tag->id);
$stamps = Yii::app()->db->createCommand($sql)->queryAll(true, $params);
if(sizeof($stamps) == 0){
$response['status'] = '0';
$response['message'] = 'Invalid Request';
} else {
$feature = EventFeatures::model()->findByAttributes(array('eventid'=>$_POST['eventid'],'featureid'=>3));
if($feature === null){
$response['status'] = '0';
$response['message'] = 'Invalid Request';
} else {
$info = json_decode($feature->info, true);
$random = false;
if(isset($info['STAMPSEQ'])){
$random = $info['STAMPSEQ'] == 'R';
}
$collected = array();
$response['status'] = $_POST['checking'] == 1 ? '1' : '0';
$duplicate = false;
foreach($stamps as $stamp){
if ($stamp['tapped'] == 1 && $_POST['checking'] != 1){
$response['tappedStamp'] = $stamp['id'];
$response['message'] = $stamp['message'];
$response['status'] = '1';
$duplicate = $stamp['collected'] == 1;
} elseif($stamp['collected'] == 1){
$collected[] = $stamp['id'];
continue;
} elseif(!$random && $_POST['checking'] != 1){
if( !isset($response['tappedStamp']) ){
$response['message'] = 'You have tapped a wrong kiosk';
}
break;
}
}
if( $response['status'] == '1' ){
$response['collectedStamp'] = $collected;
if(!$duplicate && $_POST['checking'] != 1){
$newRecord = new StampCollection();
$newRecord->eventid = $_POST['eventid'];
$newRecord->tagid = $tag->id;
$newRecord->kioskid = $eventStation->id;
$newRecord->stampid = $response['tappedStamp'];
$newRecord->collectedon = time();
$newRecord->save();
}
}
if( $response['status'] == '1' && Yii::app()->params['isOffline'] && $_POST['checking'] != 1){
$params = array();
$params['tagid'] = $_POST['tagid'];
$params['eventid'] = $_POST['eventid'];
$params['kioskid'] = $_POST['kioskid'];
$params['accesstoken'] = 'REPOST_SYNC';
$model = new PendingRequest();
$model->request_url = '/ws/getStamp';
$model->request_param = json_encode($params);
$model->createdon = time();
$model->issent = 0;
$model->save();
}
}
}
}
}
}
$this->_sendResponse(200, CJSON::encode($response));
} else {
$this->_sendResponse(400);
}
}
One more question:
How can I check the web service from the Browser and pass the parameter (this Project uses Yii Framework)? So I can get JSON message either from browser.
Update:
After using "POSTMAN REST Client" I got this message
if checking = 1
{"status":"1","collectedStamp":[]}
if checking = 0
this is the HTML Code I got
https://drive.google.com/file/d/0B0rJZJK8qFz9MENzcWxhU3NPalk/edit?usp=sharing

How To Add An RSS Feed To My Search.php file?

I'm running a social network and right now my search.php shows results for people, and tags. How can I add an RSS Feed? I own a blog and I wanted to add my RSS Feed to the search so whenever someone searches for a topic it will show up on the search page.
Here's the search.php code:
$feed = new feed();
$feed->db = $db;
$feed->url = $CONF['url'];
if(isset($_SESSION['username']) && isset($_SESSION['password']) || isset($_COOKIE['username']) && isset($_COOKIE['password'])) {
$verify = $loggedIn->verify();
if($verify['username']) {
$feed->user = $verify;
$feed->username = $verify['username'];
$feed->id = $verify['idu'];
if(isset($_GET['tag'])) {
$skin = new skin('shared/top'); $top = '';
$TMPL['theme_url'] = $CONF['theme_url'];
$TMPL['private_message'] = $verify['privacy'];
$TMPL['avatar'] = $verify['image'];
$TMPL['url'] = $CONF['url'];
$top = $skin->make();
}
}
}
$feed->per_page = $settings['perpage'];
$feed->time = $settings['time'];
$feed->censor = $settings['censor'];
$feed->smiles = $settings['smiles'];
$feed->c_per_page = $settings['cperpage'];
$feed->c_start = 0;
$feed->l_per_post = $settings['lperpost'];
$TMPL_old = $TMPL; $TMPL = array();
$skin = new skin('shared/rows'); $rows = '';
if(empty($_GET['filter'])) {
$_GET['filter'] = '';
}
// Allowed types
if(isset($_GET['tag'])) {
// If the $_GET keyword is empty [hashtag]
if($_GET['tag'] == '') {
header("Location: ".$CONF['url']."/index.php?a=welcome");
}
$hashtags = $feed->getHashtags(0, $settings['qperpage'], $_GET['tag'], null);
$TMPL['messages'] = $hashtags[0];
} else {
// If the $_GET keyword is empty [user]
if($_GET['q'] == '') {
header("Location: ".$CONF['url']."/index.php?a=welcome");
}
$TMPL['messages'] = $feed->getSearch(0, $settings['qperpage'], $_GET['q'], $_GET['filter']);
}
$rows = $skin->make();
$skin = new skin('search/sidebar'); $sidebar = '';
if(isset($_GET['tag'])) {
$TMPL['trending'] = $feed->sidebarTrending($_GET['tag'], 10);
} else {
$TMPL['genre'] = $feed->sidebarGender($_GET['filter'], $_GET['q']);
}
$TMPL['ad'] = generateAd($settings['ad6']);
$sidebar = $skin->make();
$TMPL = $TMPL_old; unset($TMPL_old);
$TMPL['top'] = $top;
$TMPL['rows'] = $rows;
$TMPL['sidebar'] = $sidebar;
if(isset($_GET['logout']) == 1) {
$loggedIn->logOut();
header("Location: ".$CONF['url']."/index.php?a=welcome");
}
$TMPL['url'] = $CONF['url'];
if(isset($_GET['tag'])) {
$TMPL['title'] = '#'.$_GET['tag'].' - '.$settings['title'];
} else {
$TMPL['title'] = $LNG['title_search'].' - '.$_GET['q'].' - '.$settings['title'];
}
$skin = new skin('shared/timeline_x');
return $skin->make();
Please help :)
Try this example
<?php
$articles = $pages->find('blog')->children()->visible()->flip()->limit(10);
snippet('feed', array(
'link' => url('blog'),
'items' => $articles,
'descriptionField' => 'text',
'descriptionLength' => 300
));
?>
link:
This is the main link in our feed, which takes the visitor back to our site. In this case we want them to get back to our blog, so we build an url to our blog with the url() helper function.
items:
As items for our feed, we pass the set of $articles we found in the first line. The feed snippet will automatically take care of getting the right info out of those $articles (like title, url, etc.)
descriptionField:
If you want to show a description for each item in your feed, you need to specify a field, which is available in any item and should be used for the description.
descriptionLength:
This is maximum number of characters the description will have. An excerpt is automatically generated by the feed snippet.

Categories