I have to retrieve the data from multiple resources by using the Rets server. Is there any way to do so?
For example,
I have resources and classes like:
Property(Resource), Listing(Class)
Media(Resource), Media(Class)
Some data should be fetched from the first and a little bit from the second.
I am using the Phrets to retrieve the data from the Rets server.
I am using the source code:
<?php
date_default_timezone_set('America/New_York');
require_once("vendor/autoload.php");
$log = new \Monolog\Logger('PHRETS');
$log->pushHandler(new \Monolog\Handler\StreamHandler('php://stdout', \Monolog\Logger::DEBUG));
$config = new \PHRETS\Configuration;
$config->setLoginUrl('Url to connect with')
->setUsername('Username to login')
->setPassword('Password to login');
->setRetsVersion('1.5')
$rets = new \PHRETS\Session($config);
$rets->setLogger($log);
$connect = $rets->Login();
$resource = 'Property';
$class = 'Listing';
$query = "(Acres=0+)";
$options = array(
'Count' => 1,
'Format' => 'COMPACT-DECODED',
'Limit' => 50,
'StandardNames' => 0,
'Select'=>'Acres,City,ClosePrice,BathsFull,BathsHalf,PhotoCount,VirtualTourLink'
);
$results = $rets->Search($resource,$class,$query,$options);
foreach($results as $record){
echo "<table>";
echo "<tr>";
echo "<td>".$record['Acres']."</td> ";
echo "<td>".$record['City']."</td>";
echo "<td>".$record['ClosePrice']."</td>";
echo "<td>".$record['BathsFull']."</td>";
echo "<td>".$record['BathsHalf']."</td>";
echo "<td>".$record['VirtualTourLink']."</td>";
echo "</tr>";
echo "</table>";
}
?>
Thanks in advance!
Fetch your records from the first class and then fetch your records from the second class using the second classes dependent id. Media classes are always dependent on the property classes, so it will have some id that corresponds to the main id of the property class (usually the mls # of the listing). Without seeing your RETS server's metadata I won't be able to tell you the names of the fields you need to pull from. Also, your version is more than likely 1.7.2, AFAIK no one really uses 1.5 anymore.
You can fetch by using loop of class name.
$resource = 'Property';
$classes = array('Listing','Media');
$query = "(Acres=0+)";
$options = array(
'Count' => 1,
'Format' => 'COMPACT-DECODED',
'Limit' => 50,
'StandardNames' => 0,
'Select'=>'Acres,City,ClosePrice,BathsFull,BathsHalf,PhotoCount,VirtualTourLink'
);
foreach($classes as $class){
$results[$class] = $rets->Search($resource,$class,$query,$options);
}
Related
i'm trying to generates pdfs in loop against member id, but every time i got only the first one, i addedd code in foreach so it runs multiple times, but it gives me only one pdf.please someone help me.
public function pdf($ids){
$k = 0;
foreach ($ids as $key => $id) {
$data[$k]['academics'] = $this->Utility_model->get_all_from_table_where('member_academics', array('member_id' => $id));
$data[$k]['member_employment'] = $this->Utility_model->get_all_from_table_where('member_employment', array('member_id' => $id));
$data[$k]['member_data'] = $this->Utility_model->get_all_from_table_where('members',array('member_id' => $id));
$data[$k]['disclosure'] = $this->Utility_model->get_all_from_table('generalsettings',array('key'=>'disclosure'));
$data[$k]['enrollment_fee'] = $this->Utility_model->get_all_from_table('member_invoices',array('user_id' => $id,'paymentFor'=>'Enrollment Fee'));
$data[$k]['enrollment_fee']['payment'] = $this->Utility_model->get_all_from_table('member_payments',array('invoice_id'=>$data[$k]['enrollment_fee']['id']));
$j=0;
if (!empty($data[$k]['member_data'])) {
foreach ($data[$k]['member_data'] as $member) {
$data[$k]['member_data'][$j]['term'] = $this->Utility_model->get_all_from_table('term', array('term_id' => $member['term_id']));
$data[$k]['member_data'][$j]['degree'] = $this->Utility_model->get_all_from_table('degree', array('degree_id' => $member['degree_id']));
$data[$k]['member_data'][$j]['year'] = $this->Utility_model->get_all_from_table('year', array('year_id' => $member['year_id']));
$data[$k]['member_data'][$j]['address'] = $this->Utility_model->get_all_from_table('member_addresses', array('id' => $member['address_id']));
$j++;
}
}
$this->load->view('admin/reports_management/applications_pdf/pdf_output',$data[$k],false);
$html = $this->output->get_output();
$this->load->library('dompdf_gen');
$this->dompdf->load_html($html);
$this->dompdf->render();
$this->dompdf->stream($k."file".".pdf");
$k++;
}
// echo "<pre>";
// print_r($data);
// die;
}
As long as you only request the page once you cannot get the controller method to output more than one file. You could either try to instead make a multiple page PDF or you need to change how the controller is called, and call it multiple times.
See this answer for some input about making multiple page PDF: How to create several pages with dompdf
I got connected to RETS Server and i am able to get all metadata using functions in PHrets library like GetMetadataResources,GetMetadataClasses,and all feilds in each class,but i am unable to get data from that server using SearchQuery,I tried in all ways but no luck.
<pre>
/* Initialize Object */
require("PHRets_CREA.php");
require("credentials.php");
$rets = new PHRets();
$connect=$rets->Connect($RETSURL, $RETSUsername, $RETSPassword);
/* Connect */
/* Query Server */
if ($connect) {
echo "Connected";
$resources = $rets->GetMetadataResources();
foreach ($resources as $resource) {
echo "+ Resource {$resource['ResourceID']}\n";
$classes = $rets->GetMetadataClasses($resource['ResourceID']);
foreach ($classes as $class) {
echo " + Class {$class['ClassName']} described as " . $class['Description'] . "\n";
$rets_metadata = $rets->GetMetadata($resource['ResourceID'],$class['ClassName']);
foreach ($rets_metadata as $field) {
echo " + Field: {$field['SystemName']} ({$field['DataType']})\n";
}
}
}
/*
$search = $rets->SearchQuery("Property","RE_1","(L_ListingDate=2010-03-02-2010-03-03)");
while ($listing = $rets->FetchRow($search)) {
echo $listing['L_ListingID'];
}*/
$search = $rets->SearchQuery("Property","ResidentialProperty","(ListDate=1990-01-01+)",
array( "Count" => 1, "Format" => "COMPACT", "Limit" => "2", "Offset" => "2",
"RestrictedIndicator" => "****", "StandardNames" => 1 )
);
echo "data";
print_r($search);
while ($listing = $rets->FetchRow($search))
echo "{$listing['L_City']}";exit;
}
$rets->FreeResult($search);
}</pre>
Thanks
First make sure your Resource and Class name are correct. Use http://retsmd.com to verify. Resource is usually "Property" but check your Class name which you currently have to "ResidentialProperty". It may be "RE_1" which you had in your above code.
Next, modify your SearchQuery. Maybe use less parameters in the options array and try removing StandardNames and use the default System Names.
Something like this:
$search = $rets->SearchQuery("Property","RE_1","(L_ListingDate=1990-01-01+)", array("Limit" => "10"));
Please try this one, we get all active properties for this.
$search = $rets->SearchQuery("Property","1","(135=1990-01-01+),(246=A)");
I am using following code for saving data from form to database.
$data = $this->getRequest()->getPost();
$custom['name'] = $data['name'];
$model = Mage::getModel('my/custom_order');
$model->setOrderId($order_id);
$model->setKey('name');
$model->setValue(serialize($custom));
$model->save();
Data does not save in database.But When I pass static data like below, It is Working.
$custom['name'] = 'John';
When I use print_r($data),
Array(
[name] => xyz
[surname] =>
)
Maybe you need:
$data = $this->getRequest()->getPost()->getParams();
Please check this. Check data which sended to server in your browser Network tool.
You need
$params = json_decode(file_get_contents('php://input'));
I have a custom attribute for the products, and lets say I have 3-4 products that have the same value on that attribute. So, now I want to load these 3 products and store them in an array. Here's what I do:
$all_products = array();
$count = 0;
$collection = Mage::getModel('catalog/product')->getCollection();
$collection->addAttributeToSelect('ordernumber');
foreach($collection as $product)
{
$all_products[count] = array ('sku' => $product->getSku(), 'qty' => $this->getRequest()->get('qty'), 'size' => $product->getSize());
$count++;
}
return $all_products;
Note: ordernumber HAS a value, I just get it from another place.
Anyway, when I run it - I have no values. When I debug - the debugger terminates at $products[count] = ....
I tried loading a single product just by the custom attribute - Mage::...->loadByAttribute('ordernumber', $ordernumber); and it worked fine.
So, my guess is that I am not doing something correctly with the collection manipulation, or with the array, although, I saw some examples where I got the idea from.
What am I doing wrong?
Try it like this:
$all_products = array();
$count = 0;
$collection = Mage::getModel('catalog/product')->getCollection();
$collection->addAttributeToSelect('ordernumber');
//add a filter if needed - uncomment the next 2 lines and adjust the value or $ordernumber
//$ordernumber = '123';
//$addAttributeToFilter('ordernumber', $ordernumber)
foreach($collection as $product)
{
$all_products[$count] = array ('sku' => $product->getSku(), 'qty' => $this->getRequest()->get('qty'), 'size' => $product->getSize());
$count++;
}
return $all_products;
In wordpress, when a post category (or tag) is clicked, all posts that match the clicked category (or tag) is returned, because of <?php the_content(); ?>
In my case, every post has an image in it, so how can I only fetch the images when a category (or tag) is clicked? I'm not familiar what code I need to use.
Update: I'm trying not to use plugins. My apologies for not mentioning that earlier. What I'm trying to achieve is something like The Sartorialist - All posts have images, click on any category (or tag) associated with any post and only images are fetched.
Update 2: I tried this:
<?php
$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
'post_parent' => $post->ID
);
$attachments = get_posts( $args );
if ( $attachments ) {
foreach ( $attachments as $attachment ) {
echo '<li>';
echo wp_get_attachment_image( $attachment->ID, 'full' );
echo '</li>';
}
}
?>
The only weird thing is, and I'm trying to figure out, another image from the media library also shows up, without it being in any of my posts.
I also found this plugin which is very close to what I want, but unfortunately it has to be in a separate page, not the in category page.
You can achieve this with something like this:
<?php
function getImage($num) {
global $more;
$more = 1;
$link = get_permalink();
$content = get_the_content();
$count = substr_count($content, '<img');
$start = 0;
for($i=1;$i<=$count;$i++) {
$imgBeg = strpos($content, '<img', $start);
$post = substr($content, $imgBeg);
$imgEnd = strpos($post, '>');
$postOutput = substr($post, 0, $imgEnd+1);
$postOutput = preg_replace('/width="([0-9]*)" height="([0-9]*)"/', '',$postOutput);;
$image[$i] = $postOutput;
$start=$imgEnd+1;
}
if(stristr($image[$num],'<img')) { echo ''.$image[$num].""; }
$more = 0;
}
?>
source