Get Photo of the object in widget - SocialEngine Widget - php

I am beginner in SocialEngine and I want to know if there is any way to get the photo of the object in the widget.
Like i know we can get the photo of the object in view using following code.
//in controller
$table = Engine_Api::_()->getDbTable("mytable","module");
$select = $table->select()->where->("table_id", 1);
$fetch = $table->fetchRow($select);
$this->view->fetch = $fetch;
//in view
echo $this->itemPhoto($this->fetch, "thumb.normal");
above line would product the image if there is any otherwise will load the default image.
But this line of code is not working in widget.
I really appreciate your help.

You need to make sure that first param you're passing to $this->itemPhoto is a User instance:
$this->itemPhoto($user, 'thumb.normal', $user->getTitle())
Seems that in your case $this->fetch is simply a Row. You can create user using this code: Engine_Api::_()->getItem('user', $user_id);. Hope this helps.

Related

JSON API PHP finding depth

I need help with figuring out how to call some depth elements in API call. We're connecting API which company gave us and this is the code I have
<?php
include("O3ON_API.php");
header('Content-type: text/html; charset=utf-8');
$apiclient = O3ON_API_Connector::getInstance();
$models = $apiclient->CallAPI('Model', 'sr-Latin-CS', '');
$categories = $apiclient->CallAPI('Category', 'sr-Latin-CS', '');
?>
So when I want to call it, I do it this way
<?php
foreach($models as $model){
echo '<div>'.$model->Name.'</div>';
}
?>
This all works well, but I am struggling on how to call field which has some depth. This is an example of their API
Model
Name
Image
Category
Price
So with the $model I can call first level which is Name and Image. But how can I call sub category Price or Category? I found some examples online, but since I got the documentation from company it's different then what I want to do.
I tried this but with no success
$model->Category->Name
$model->Category[0]
I am thankful to anyone who helps!
If I understood. The Category is nested inside Image This should work:
$model->Image->Category
$model->Name
Check the structure with var_dump()

Overwriting an image upload with Stapler - Laravel

I am wanting to give the user an option to delete their current logo and replace it with a new one. Currently I am using Stapler, a Laravel package.
I initially had trouble adding the logo, by means of, I had to create the table entity by adding the logo first, and then updating the other fields:
$company = Company::create(['logo' => Input::file('logo')]);
$company->save();
$companyID = $company->id;
$company = Company::find($companyID);
$company->company_name = Input::get('company_name');
Now, should a user have selected a new logo to add, I want it to clear the current logo and add the new one. I am struggling on how to add the logo into the same company, as on the code above, the Company::create creates a new Company record.
Current code:
Even if I try and dd() the file directly, it returns NULL. Its as if it can't even find it within the view!
$logo = Input::file('logo');
if($logo !== null)
{
$company->logo->clear();
$company->logo = Input::file('logo');;
}
Thank you in advance.
The form wasn't allowing file uploads. By adding:
'files'=>'true'
into the Form::open(array( it added the file.

Get store ID that a page belongs to

I'm trying to find out what store a page belongs to in Magento. We currently have along these lines:
$cms_pages = Mage::getModel('cms/page')->getCollection();
$cms_pages->load();
foreach($cms_pages as $_page) {
$data = $_page->getData();
}
How would I get the store ID for each page? Ideally I'd like something as simple as $data->store_id(); but I've not found anything of use yet. Can anyone point me in the right direction?
Add Store id to your collection and it will only return the pages you need:
$collection = Mage::getModel('cms/page')->getCollection()
->addStoreFilter(Mage::ap‌​p()->getStore()->getId())
->setOrder('sortorder', 'asc');

Replace string in Array in array with truncate string

I'm using CodeIgniter for my website. I'm also using the tumblr API on my site to show posted news.
Because showing the entire text is a bit too much, I want to truncate the body copy to 150 characters, I do this by using the character_limiter function of CI.
The code is as followed in my 'home' controller:
public function index() {
//Title for home page
$data['title'] = "Home - Welcome";
// Obtain an array of posts from the specified blog
// See the config file for a list of settings available
$tumblr_posts = $this->tumblr->read_posts();
foreach($tumblr_posts as $tumblr_post) {
$tumblr_post['body'] = character_limiter($tumblr_post['body'], 150);
}
// Output the posts
$data['tumblr_posts'] = $tumblr_posts;
// Load the template from the views directory
$this->layout->view('home', $data);
}
The problem is, that $tumblr_post['body'] isn't shortened when I echo it on my view page. Doing it like above works in Asp.net (C#) but it doesn't seem to work in php, anyone know why and how to solve it or is there an other way?
Your problem is with the foreach loop. You need to add a & before $tumblr_post to pass it by reference. This makes sure you are actually editing the values in the array. Without the &, you're just editing a local variable and not the array.
Try it like this (notice the &):
foreach($tumblr_posts as &$tumblr_post) {
$tumblr_post['body'] = character_limiter($tumblr_post['body'], 150);
}

Drupal 6 - Content profile fields within page-user.tpl.php

Going a bit mad here... :)
I'm just trying to add CCK fields from a Content Profile content type into page-user.tpl.php (I'm creating a highly-themed user profile page).
There seem to be two methods, both of which have a unique disadvantage that I can't seem to overcome:
'$content profile' method.
$var = $content_profile->get_variables('profile');
print $var['field_last_name'][0]['safe'];
This is great, except I can't seem to pass the currently viewed user into $content_profile, and it therefore always shows the logged in user.
'$content profile load' method.
$account_id = arg(1);
$account = user_load($account_id);
$user_id = $account->uid;
$var = content_profile_load('profile', $user_id);
print $var->field_first_name[0]['value'];
Fine, but now I can't access the full rendered fields, only the plain values (i.e. if the field has paragraphs they won't show up).
How can I have both things at once? In other words how can I show fields relating to the currently viewed user that are also rendered (the 'safe' format in 1)?
I've Googled and Googled and I just end up going round in circles. :(
Cheers,
James
Your content profile load method seems to be the closest to what you want.
In your example:
$account_id = arg(1);
$account = user_load($account_id);
$user_id = $account->uid;
$var = content_profile_load('profile', $user_id);
print $var->field_first_name[0]['value'];
The $var is just a node object. You can get the "full rendered fields" in a number of ways (assuming you mean your field with a filter applied).
The most important thing to check is that you're field is actually configured properly.
Go to:
admin/content/node-type/[node-type]/fields/field_[field-name] to configure your field and make sure that under text processing that you've got "Filtered text" selected.
If that doesn't fix it,try applying this:
content_view_field(content_fields("field_last_name"), $var, FALSE, FALSE)
(more info on this here: http://www.trevorsimonton.com/blog/cck-field-render-node-formatter-format-output-print-echo )
in place of this:
print $var->field_first_name[0]['value'];
if none of that helps... try out some of the things i've got on my blog about this very problem:
http://www.trevorsimonton.com/blog/print-filtered-text-body-input-format-text-processing-node-template-field-php-drupal
When you're creating a user profile page there is a built in mechanism for it. just create a user template file, user_profile.tpl.php.
When you use the built in mechanism you automatically get access to the $account object of the user you are browsing, including all user profile cck fields. You have the fields you are looking for without having to programmatically load the user.
I have a field called profile_bio and am able to spit out any mark up that is in without ever having to ask for the $account.
<?php if ($account->content[Profile][profile_bio]['#value']) print "<h3>Bio</h3>".$account->content[Profile][profile_bio]['#value']; ?>
I've tried themeing content profiles by displaying profile node fields through the userpage before and it always seems a little "hacky" to me. What I've grown quite fond of is simply going to the content profile settings page for that node type and setting the display to "Display the full content". This is fine and dandy except for the stupid markup like the node type name that content profile injects.
a solution for that is to add a preprocess function for the content profile template. one that will unset the $title and remove the node-type name that appears on the profile normally.
function mymodule_preprocess_content_profile_display_view(&$variables) {
if ($variables['type'] == 'nodetypename') {
unset($variables['title']);
}
}
A function similar to this should do the trick. Now to theme user profiles you can simply theme your profile nodes as normal.

Categories