Symfony sfGuard pull a field in a specific user's profile - symfony-1.4

I'm trying to have a "product" page display a specific user's blurb and picture. The code I have is below but it keeps pulling the currently logged on user's blurb and picture which is not what I want. As soon as I log out, I get the Call to a member function getBlurb() on a non-object error message. Is there a way to pull up a specific user's "blurb" and "Picture" fields?
public function executeShow(sfWebRequest $request)
{
$this->car = $this->getRoute()->getObject();
$seller_id = $this->car->getSeller_id();
$this->seller = $this->getUser()->getGuardUser($seller_id);
$this->blurb = $this->seller->getBlurb();
$this->picture = $this->seller->getPicture();
}

$this->seller is not an object because $this->getUser()->getGuardUser($seller_id); don't accept any parameters, it only retrieves current user. Look at that method definition at sfGuardSecurityUser.
You have to do it like:
Doctrine: $this->seller = $this->car->getSeller();
Propel: $this->seller = SfGuardUserPeer::retrieveByPK($seller_id);

Related

Adding users and attributes programatically in Concrete5 version 8

Hi I have recently followed some documentation to create new users from a csv file programatically. According to the Concrete5 docs/api there was method called getByID( $uID ) but this has since be deprecated!
I am creating a new user like so:
$userRegistration = Core::make('user/registration');
$file = fopen("test-users.csv","r");
while (($data = fgetcsv($file)) !== FALSE) {
echo "email address " . $data[0];
$userRegistration->create([
'uName' => $data[0],
'uPassword' => $data[1],
'uEmail' => $data[2],
'uIsValidated' => true,
]);
}
However if I want to add a value to an existing non-core attribute for instance lets call it user_county then how would I change this after programatically adding the user? I may need to do this for several user attributes as well so the values would need to come from the CSV and automatically be looped through to apply the correct value to the corresponding attribute whether it is blank or filled.
The create() method will return a UserInfo object (Concrete\Core\User\UserInfo) after successfully adding a new user. With the returned UserInfo object, you can use the setAttribute() method to set your custom user attribute.
Make sure that you have created the customer user attribute first and check that it is available before setting it, otherwise setting it will throw an error. I believe you can do this using Concrete\Core\Attribute\Key\UserKey::getByHandle('my_user_attribute') and seeing if it returns an object.
The create() method is in the RegistrationService class:
https://github.com/concrete5/concrete5/blob/develop/concrete/src/User/RegistrationService.php#L51-L140

CreateEnvelopeFromTemplates - Guid should contain 32 digits with 4 dashes

I am attempting to create a DocuSign envelope from a template document using the CreateEnvelopeFromTemplates method, available within their v3 SOAP API web service. This is being instantiated from a asp.NET v4.0 web site.
Upon calling the method armed with the required parameter objects being passed in. I am recieving an exception from the web service, basically telling me that the Template ID is not a valid GUID.
669393: Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).
Line 14889:
Line 14890: public DocuSignDSAPI.EnvelopeStatus CreateEnvelopeFromTemplates(DocuSignDSAPI.TemplateReference[] TemplateReferences, DocuSignDSAPI.Recipient[] Recipients, DocuSignDSAPI.EnvelopeInformation EnvelopeInformation, bool ActivateEnvelope) {
Line 14891: return base.Channel.CreateEnvelopeFromTemplates(TemplateReferences, Recipients, EnvelopeInformation, ActivateEnvelope);
Line 14892: }
Line 14893:
The template reference, a guid. Must be specified as the "Template" string property against TemplateReference object. This is then added to a dynamic array of TemplateReferences, which is one of the input parameters of the CreateEnvelopeFromTemplates method.
Actual template GUID: f37b4d64-54e3-4723-a6f1-a4120f0e9695
I am building up my template reference object using the following function that i wrote to try and make the functionality reusable:
Private Function GetTemplateReference(ByVal TemplateID As String) As TemplateReference
Dim templateReference As New TemplateReference
Dim guidTemplateID As Guid
With TemplateReference
.TemplateLocation = TemplateLocationCode.Server
If Guid.TryParse(TemplateID, guidTemplateID) Then
.Template = guidTemplateID.ToString
End If
End With
Return TemplateReference
End Function
The TemplateID is being passed in from a appSetting configuration value at the time of the TemplateReferences array instantiation like so...
templateReferences = New TemplateReference() {GetTemplateReference(ConfigurationManager.AppSettings("DocuSignTemplate_Reference"))}
recipients = New Recipient() {AddRecipient("myself#work.email", "My Name")}
envelopeInformation = CreateEnvelopeInformation()
envelopeStatus = client.CreateEnvelopeFromTemplates(templateReferences, recipients, envelopeInformation, True)
As you can see from my GetTemplateReference function I am also parsing the GUID before setting it back as a string so i know its valid. The template is managed and stored at the DocuSign end, hence specifying the document location.
I am referring to their own documentation:
CreateEnvelopeFromTemplates
Why oh why is the method not liking my Template ID? I can successfully use their REST API to call the same method, using their own code samples. Worst case I can make use of this but would rather interact with the web service as I would need to construct all the relevent requests in either XML or JSON.
I would really appreciate if someone could perhaps shed some light on this problem.
Thanks for taking the time to read my question!
Andrew might be spot on with the AccountId mention - are you setting the AccountId in the envelope information object? Also, have you seen the DocuSign SOAP SDK up on Github? That has 5 sample SOAP projects including one MS.NET project. The .NET project is in C# not Visual Basic, but still I think it will be helpful to you. Check out the SOAP SDK here:
https://github.com/docusign/DocuSign-eSignature-SDK
For instance, here is the test function for the CreateEnvelopeFromTemplates() function:
public void CreateEnvelopeFromTemplatesTest()
{
// Construct all the recipient information
DocuSignWeb.Recipient[] recipients = HeartbeatTests.CreateOneSigner();
DocuSignWeb.TemplateReferenceRoleAssignment[] finalRoleAssignments = new DocuSignWeb.TemplateReferenceRoleAssignment[1];
finalRoleAssignments[0] = new DocuSignWeb.TemplateReferenceRoleAssignment();
finalRoleAssignments[0].RoleName = recipients[0].RoleName;
finalRoleAssignments[0].RecipientID = recipients[0].ID;
// Use a server-side template -- you could make more than one of these
DocuSignWeb.TemplateReference templateReference = new DocuSignWeb.TemplateReference();
templateReference.TemplateLocation = DocuSignWeb.TemplateLocationCode.Server;
// TODO: replace with template ID from your account
templateReference.Template = "server template ID";
templateReference.RoleAssignments = finalRoleAssignments;
// Construct the envelope information
DocuSignWeb.EnvelopeInformation envelopeInfo = new DocuSignWeb.EnvelopeInformation();
envelopeInfo.AccountId = _accountId;
envelopeInfo.Subject = "create envelope from templates test";
envelopeInfo.EmailBlurb = "testing docusign creation services";
// Create draft with all the template information
DocuSignWeb.EnvelopeStatus status = _apiClient.CreateEnvelopeFromTemplates(new DocuSignWeb.TemplateReference[] { templateReference },
recipients, envelopeInfo, false);
// Confirm that the envelope has been assigned an ID
Assert.IsNotNullOrEmpty(status.EnvelopeID);
Console.WriteLine("Status for envelope {0} is {1}", status.EnvelopeID, status.Status);
}
This code calls other sample functions in the SDK which I have not included, but hopefully this helps shed some light on what you're doing wrong...
This problem arises when you don't set up the field AccountId. This field can be retrieved from your account. In Docusign's console go to Preferences / API and look here
Where to find AccountID Guid in Docusign's Console
Use API Account ID (which is in GUID format) and you should be OK.

Symfony2: How to change Entity Manager just before doing login_check

I've two dbal connections. One static, defined in config.yml, and one defined dynamically. When I need it in a controller I set the connection parameters, such as host, database name, password, etc...
I need to set the dynamic connection just before doing the login check action (or in this action).
This is because my "User" entity is on different databases according to the URL. So I can't put the dynamic connection definition in config.yml file.
I use that method to set the entity manager I need:
public function switchConnection($connectionParam=array())
{
$conn = array_merge(
array('host'=>'127.0.0.1', 'port'=>'3306', 'dbName'=>'myDatabaseName', 'user'=>'myUser', 'pass'=>'myPass', 'driver'=>'pdo_mysql', 'connection'=>'default', 'em'=>'default')
, $connectionParam);
$dbalConnectionTo=sprintf('doctrine.dbal.%s_connection', $conn['connection']);
$connection = $this->container->get($dbalConnectionTo);
$connection->close();
$refConn = new \ReflectionObject($connection);
$refParams = $refConn->getProperty('_params');
$refParams->setAccessible('public');
$params = $refParams->getValue($connection);
$params['dbname'] = $conn['dbName'];
$params['user'] = $conn['user'];
$params['host'] = $conn['host'];
$params['port'] = $conn['port'];
$params['password'] = $conn['pass'];
$params['driver'] = $conn['driver'];
$params['charset']='UTF8';
$refParams->setAccessible('private');
$refParams->setValue($connection,$params);
$this->container->get('doctrine')->resetEntityManager($conn['em']);
return;
}
Could I change the "login_check" action code to set the Entity Manager my way?
In general it's bad practice to change the default database connection under a certain condition. Also the user needs to be loaded on any (logged in) request, not just in the login request.
But there is of course a symfony way to achieve to load the user froma different database.
You would need to implement your own UserProvider that loads the user from a different database connection. Here is an example of a userprovider.

How to get generated HTML-ID-Attribute from Symfony2-Form-Elements

I want to receive Error-Messages from a Symfony2-Form via ajax (JSON). Now I get the problem to join the $form_element->getName() with my form-element ID in HTML. Is there a possibility to get this ID from the $form_element-Object?
Yes, simply use
$form->get('field_name')->createView()->vars['id'];
In order to get view related data (like id and class options) from a form, first you have to create its view.
You can also do it the other way:
$formView = $form->createView(); // Creates view for every element of the form
$id = $formView->children['field_name']->var['id'];

Workflow Foundation: How to create Receive activity with custom message in xaml designer?

I need to have Receive activity which can receive my custom data. I found examples, but all use coded workflows like such
public class ProcessRequest : Activity
{
public ProcessRequest()
{
Variable<MyData> request = new Variable<MyData> { Name = "request" };
Receive receiveRequest = new Receive
{
ServiceContractName = "IProcessRequest",
OperationName = "Foo",
CanCreateInstance = true,
Content = ReceiveContent.Create(new OutArgument<MyData>(request))
};
}
}
The main point is that Receive.Content property. It is not clear for me how I can do it in XAML designer. What I have to set in the dialog of the Content property - Message or Parameters and what to set inside those options?
Thanks for the light!
I got it :-) I have to use Message option inside the Content dialog. Then put the name of the variable (in my case request) into the field Message data and browse MyData type for the Message type field. Piece of cake ;-)

Resources