Display Repeater sub-field, a post object value - repeater

I have a custom post_type 'publications' and it has a Repeater field 'linked_author' with a sub-field 'paper_linked_author' - a post object.
Here is the code to get all of the publications post and run a loop to get all authors linked to each post.
$args = array(
'posts_per_page' => '-1',
'post_type' => 'publications'
);
$the_query = new WP_Query( $args );
$post_ids = wp_list_pluck( $the_query->posts, 'ID' );
echo "<pre>";
print_r($post_ids);
echo "</pre>";
$artist_list = array();
foreach($post_ids as $post_id){
$artist_repeater = get_field('linked_author', $post_id);
echo "<pre>";
print_r($artist_repeater);
echo "</pre>";
if ($artist_repeater) {
$speakers = get_sub_field('paper_linked_author');
if ($speakers && count($speakers)>0)
{
foreach ($speakers as $speaker)
{
echo $speaker->ID; //$speaker is a post object//
}
}
}
}
I have been able to get all the sub-field values of each publication post however I'm not able to echo details of each linked author - the sub-field values. A print_r($artist_repeater) shows below details for one of the posts.
So, my question is how to list all unique authors from below print_r() array? Also, I need to link each author name such that clicking will bring list of all publications post he/she is linked to? Please help!
Array
(
[0] => Array
(
[paper_linked_author] => WP_Post Object
(
[ID] => 4885
[post_author] => 1
[post_date] => 2018-06-26 04:56:29
[post_date_gmt] => 2018-06-26 04:56:29
[post_content] =>
[post_title] => Q1-Test
[post_excerpt] =>
[post_status] => publish
[comment_status] => closed
[ping_status] => closed
[post_password] =>
[post_name] => q1-test
[to_ping] =>
[pinged] =>
[post_modified] => 2018-06-26 05:14:13
[post_modified_gmt] => 2018-06-26 05:14:13
[post_content_filtered] =>
[post_parent] => 0
[menu_order] => 0
[post_type] => people
[post_mime_type] =>
[comment_count] => 0
[filter] => raw
)
)
[1] => Array
(
[paper_linked_author] => WP_Post Object
(
[ID] => 2115
[post_author] => 1
[post_date] => 2017-03-28 05:47:01
[post_date_gmt] => 2017-03-28 05:47:01
[post_content] =>
[post_title] => Julius Ceaser
[post_excerpt] =>
[post_status] => publish
[comment_status] => closed
[ping_status] => closed
[post_password] =>
[post_name] => julius-ceaser
[to_ping] =>
[pinged] =>
[post_modified] => 2018-06-25 11:02:55
[post_modified_gmt] => 2018-06-25 11:02:55
[post_content_filtered] =>
[post_parent] => 0
[menu_order] => 0
[post_type] => people
[post_mime_type] =>
[comment_count] => 0
[filter] => raw
)
)
)

Just so it helps others, I solved the above problem with below code.
Basically, I was looking to list all authors who have written at least one Publication. So, earlier I was querying publications custom post_type and then looping each publication to list linked authors and that is where the above print_r() dump can be seen.
So, instead I queries all authors (a custom post_type) and then queries publications to match the key "linked_author_$_paper_linked_author" with the ID of the author post. It worked.
<?php
add_filter( 'posts_orderby' , 'posts_orderby_lastname' );
$args = array(
'post_type' => 'people',
'posts_per_page' => -1, // Unlimited posts
'post_status' => 'publish'
// Order alphabetically by name
);
$loops = new WP_Query( $args );
while ($loops -> have_posts()) : $loops -> the_post();
$args = array(
'numberposts' => -1,
'post_type' => 'publications',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'linked_author_$_paper_linked_author',
'compare' => '=',
'value' => get_the_ID()
)
)
);
// query
$the_query = new WP_Query( $args );
if( $the_query->have_posts() ):
?>
<ul>
<li><?php echo the_title(); ?></li>
</ul>
<?php
endif;
endwhile;
?>

Related

Unable to get ETag value from the response

Code:
$response = $s3->copyObject(array(
'Bucket' => $bucket,
'Key' => $key,
));
Response:
Aws\Result Object
(
[data:Aws\Result:private] => Array
(
[CopyObjectResult] => Array
(
[ETag] => "s906113sa3401932f56f79ec75a1c877"
[LastModified] => Aws\Api\DateTimeResult Object
(
[date] => 2021-05-31 04:51:54.000000
[timezone_type] => 2
[timezone] => Z
)
)
[Expiration] =>
[CopySourceVersionId] =>
[VersionId] =>
[ServerSideEncryption] =>
[SSECustomerAlgorithm] =>
[SSECustomerKeyMD5] =>
[SSEKMSKeyId] =>
[SSEKMSEncryptionContext] =>
[BucketKeyEnabled] =>
[RequestCharged] =>
[#metadata] => Array
(
[statusCode] => 200
[effectiveUri] => https://bucket-dev.s3.amazonaws.com/store111/RawVideo/videogallery/file_example_MP4_480_1_5MG_1622436712.mp4
[headers] => Array
(
[x-amz-id-2] => DFzipf5adLLXV1435xCQO5d+R0LgDDl74o143UicbYF5biXv78G/j4HEDhoS8FsBY9C8HC+mOw8=
[x-amz-request-id] => 4SVDA143BSDZ49A6QJK
[date] => Mon, 31 May 2021 04:51:54 GMT
[content-type] => application/xml
[content-length] => 234
[server] => AmazonS3
)
[transferStats] => Array
(
[http] => Array
(
[0] => Array
(
)
)
)
)
[ObjectURL] => https://bucket-dev.s3.amazonaws.com/store111/RawVideo/videogallery/file_example_MP4_480_1_5MG_1622436712.mp4
)
[monitoringEvents:Aws\Result:private] => Array
(
)
)
The above out I want to get the ETag value in the below code
$etag = $response->get('ETag');
I am getting the $etag value as empty. Please help and let me know how I will get it?
Note: It was working fine for aws v2 when we migrate it from aws v2 to v3 we are getting different types of responses.
After checking finally I just call the below:
$etag = $response['CopyObjectResult']['ETag'];
It's working fine as expected.

CakePHP 3.x - save not work in associate table

I have below table structure.
Mandator table
class MandatorTable extends Table
{
public function initialize(array $config)
{
$this->table('mandators');
$this->belongsToMany('Seminar', [
'foreignKey' => 'mandator_id',
'targetForeignKey' => 'seminar_id',
'joinTable' => 'mandators_seminars'
]);
}
}
Semiar table
class SeminarTable extends Table
{
public function initialize(array $config)
{
$this->table('seminars');
$this->belongsToMany('Mandator', [
'foreignKey' => 'seminar_id',
'targetForeignKey' => 'mandator_id',
'joinTable' => 'mandators_seminars'
]);
}
}
both table are belong to 'mandators_seminars' table
mandator_id, seminar_id
When I save data it's save in seminar table but not in 'mandators_seminars' table
Query
$seminartable = $this->Seminar->newEntity();
$this->request->data['mandator'][0] = 1;
$seminardata = $this->Seminar->patchEntity($seminartable, $this->request->data);
$this->Seminar->save($seminardata)
Request data
Array
(
[bookable] => test
[released] => aaa
[linkable] => bb
[name] => ccc
[internalnote] => ddd
[abstract] => ttt
[description] => ddd
[Category] => 14
[mandator] => Array
(
[0] => 1
)
[mandator_owner_id] => 1
)
Look you have two table Mandator and Similar as singular , but your connecting table is plural. Firstly check this. If there is still a problem check this CakePHP Through Association
As you can see your association should be like this:
$this->belongsToMany('Mandator', [
'foreignKey' => 'seminar_id',
'targetForeignKey' => 'mandator_id',
'through' => 'PluginName.MandatorsSeminars'
'joinTable' => 'mandators_seminars',
'className' => 'PluginName.Mandator'
]);
And one more tip: table should be called as plural.

How to create an entity reference field which will allow unlimited values in a configuration form?

public function buildForm(array $form, FormStateInterface $form_state) {
$form = parent::buildForm($form, $form_state);
$config = $this->config('category_dynamic_block.settings');
$form['section_title'] = array(
'#type' => 'textfield',
'#title' => $this->t('Section Title'),
'#description' => $this->t('Enter a Section Title'),
);
$form['term_name'] = array(
'#type' => 'entity_autocomplete',
'#target_type' => 'taxonomy_term',
'#selection_settings' => [
'target_bundles' => array('categories'),
],
'#title' => $this->t('Term Name'),
'#description' => $this->t('Enter a Category Vocab Term Name'),
);
$form['page_title'] = array(
'#type' => 'entity_autocomplete',
'#target_type' => 'node',
'#selection_settings' => [
'target_bundles' => array('article'),
],
'#title' => $this->t('Page Title (' . $i . ')'),
'#description' => $this->t('Enter Page Title to be displayed'),
);
return $form;}
I'm creating a configuration form and I'm trying to find if there is a way in drupal 8 which will allow the user to enter multiple values for $form['page_title'] field.
This question (unlimited text fields with form api) may be what you are looking for: https://drupal.stackexchange.com/questions/208012/unlimited-textfields-with-form-api
Basically you'll need to add some ajax:
'#ajax' => [
'callback' => array($this, 'addMultipleItems'),
'event' => 'change',
'progress' => array(
'type' => 'throbber',
'message' => t('Adding another item...'),
),
],

how to add two product in opencart?

How to add two products . For example I added product1 . I want to split that product1 into product with media and product1 without media. Quantity are same .
In the product list it has to show in two different entries . Below is the code for adding product. now it is taking only one ..
$this->data[$key] = array(
'key' => $key,
'product_id' => $product_query->row['product_id'],
'name' => $product_query->row['name'],
'model' => $product_query->row['model'],
'shipping' => $product_query->row['shipping'],
'image' => $product_query->row['image'],
'option' => $option_data,
'download' => $download_data,
'quantity' => $quantity,
'minimum' => $product_query->row['minimum'],
'subtract' => $product_query->row['subtract'],
'stock' => $stock,
'price' => ($price + $option_price),
'total' => ($price + $option_price) * $quantity,
'reward' => $reward * $quantity,
'points' => ($product_query->row['points'] ? ($product_query->row['points'] + $option_points) * $quantity : 0),
'tax_class_id' => $product_query->row['tax_class_id'],
'weight' => ($product_query->row['weight'] + $option_weight) * $quantity,
'weight_class_id' => $product_query->row['weight_class_id'],
'length' => $product_query->row['length'],
'width' => $product_query->row['width'],
'height' => $product_query->row['height'],
'length_class_id' => $product_query->row['length_class_id'],
'recurring' => $recurring
);

Authentication using Doctrine 2 MongoDbODM Module

I'm trying to set a login(Authentication) using Zend2 and DoctrineODMModule but I am getting an error.
I have followed the tutorial to setup the Authentication of Zend2 with doctorineODMModule on github
any suggestion what I am doing wrong? or what I have to do?
i have done it in the following way.
in doctrine mdule.config.php
'authentication' => array(
'odm_default' => array(
'object_manager' => 'doctrine.documentmanager.odm_default',
'identity_class' => 'Admin\Document\User',
'identity_property' => 'username',
'credential_property' => 'password',
),
),
'odm_driver' => array(
'class' => 'Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver',
'paths' => array(__DIR__ . '/../src/' . __NAMESPACE__ . '/Document')
),
'odm_default' => array(
'drivers' => array(
__NAMESPACE__ . '\Document' => 'odm_driver'
)
)
in Admin/Document/User.php created two methods getUsername and getPassword.
public function getUsername(){
return $this->username;
}
public function getPassword(){
return $this->password;
}
created controller in index controller.php
public function loginAction(){
$this->layout('layout/login-layout.phtml');
$login_error=false;
$loginForm = new LoginForm();
if ($this->request->isPost())
{
$loginForm->setData($this->request->getPost());
if ($loginForm->isValid())
{
// try {
// throw new \Exception("My exception");
$data = $loginForm->getData();
$authService = $this->getServiceLocator()
->get('doctrine.authenticationservice.odm_default');
$adapter = $authService->getAdapter();
$adapter->setIdentityValue($data['username']); // i am using username
$adapter->setCredentialValue(md5($data['password']));
$authResult = $authService->authenticate();
if ($authResult->isValid()) {
$this->redirect()->toRoute('admin_index'); // or last viewed page
}
/*} catch (Exception $e) {
echo "Caught exception $e\n";
echo $e->getPrevious();
$login_error=false;
return new ViewModel(array(
'loginForm' => $loginForm,
'login_error' => $login_error,
));
//exit;
}/
return array(
'loginForm' => $loginForm,
'errors' => 'username or password is not valid',
);
$this->redirect()->toRoute('admin_index');
} else {
//
// LOG Event ( login|password not valide )
//
//Zend\Debug\Debug::dump("not valid data");
//Zend\Debug\Debug::dump($loginForm->getMessages());
$login_error=true;
}//* */
}
}
//
return new ViewModel(array(
'loginForm' => $loginForm,
'login_error' => $login_error,
));
}
With the message you give,
A value for the identity was not provided prior to authentication with ObjectRepository authentication adapter
I'd say that either you didn't give the field to use as identity on you're User Document or during authentication process (in your action) you didn't populate the value for identity (aka login)
Please give more informations about your app (odm module configuration, Identity class...) to provide you a better help
as configuration you should have stg like :
...
'doctrine' => array(
'driver' => array(
__NAMESPACE__ . '_orm_driver' => array(
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => array(__DIR__ . '/../src/' . __NAMESPACE__ . '/Entity')
),
'orm_default' => array(
'drivers' => array(
__NAMESPACE__ . '\Entity' => __NAMESPACE__ . '_orm_driver'
)
),
__NAMESPACE__ . '_odm_driver' => array(
'class' => 'Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver',
'paths' => array(__DIR__ . '/../src/' . __NAMESPACE__ . '/Document')
),
'odm_default' => array(
'drivers' => array(
__NAMESPACE__ . '\Document' => __NAMESPACE__ . '_odm_driver'
)
)
),
'authentication' => array(
'odm_default' => array(
'objectManager' => 'doctrine.documentmanager.odm_default',
'identityClass' => 'Application\Document\User',
'identityProperty' => 'username',
'credentialProperty' => 'password',
'credentialCallable' => 'Application\Utils::hashPassword' // Not needed if you don't hash passwords
),
),
),
...
This was working great for some of my projects