Jump to content

elabx

Members
  • Posts

    1,523
  • Joined

  • Last visited

  • Days Won

    21

Everything posted by elabx

  1. Try setting template_id as an integer: $field->template_id = $templates->get("mm_state")->id
  2. Is there a smart wat to go about comparing two selectors to see if they are exactly the same? I want to iterate through a group of pages with selector fields, and compare each field selector string to another one coming in through $input->get eg. "baths>1, template=listing" == "template=listing, baths>1" //should return true. I've seen that this (Selectors:: keyValueStringToArray) static helper just handles "=" operator and discards other selectors with a different operator when converting the selectors to an array. (my objective was to compare both arrays)
  3. Also take a look at pro module Visual Page Selector which I think enables a kind of lister in the page editing.
  4. elabx

    So happy :)

    Congratulation @flydev !! You are an amazing contributor to this community and it shows in how you influence businesses decisions with your work and dedication and that's invaluable for all of us looking to get jobs using PW.
  5. @itsberni For the issue, What I've done to solve this is that I basically build a button separate from the calendar and build the url accordingly. Will get back with code details later, just in a bit of a hurry now. For the question, Doesn't passing a selector in the renderCalendar options let you filter the events you need? So that you could could use p=1 in the query parameters?
  6. Hi! I'm working on a module, and doing some Ajax operations, for example, I am creating some fields and doing this while checking if field already exists: if($fieldExists){ throw new WireException('Field already exists with that name. Please choose another name'); }else{ ... } In the response, I'm heading a 200 response code and the following code: {"error":true,"message":"Field already exists with that name. Please choose another name"} Is there a way I could customize that error message? if($fieldExists){ throw new WireException(array("message" => "...", "existingFieldId" => 1)); }else{ ... } And expect the response to have the custom info I want? I'm very intrigued on how the exception ends up as a json object in the resopnse. Thanks for further answers!
  7. Hi! Is this a valid approach to creating fieldsets? Doing this inside a module: $field = new Field(); $field->type = new FieldtypeFieldsetOpen(); $field->name = $sanitizedName; $field->label = $fieldLabel; $field->save(); $closer = $field->type->getFieldsetCloseField($field, true); Taken from here: https://github.com/processwire/processwire/blob/48fe0769a4eb3d0f5b4732fd01b4b4ed8262d952/wire/modules/Fieldtype/FieldtypeFieldsetOpen.module#L131
  8. I think the only available way built in is to use ASM inputfield with page fields and the setting becomes available in the Input Tab in the field configuration.
  9. Try to turn off output formatting before changing the value.
  10. My thought is that you could use a hook to add the html into the rendering of the Inputfield, or maybe you could add a Markup field in FormBuilder so you can place this link, right bellow the checkbox.
  11. Check this post: https://processwire.com/talk/topic/16932-adding-classes-to-repeater-items-for-custom-styling-in-admin/
  12. Hi everyone! I have a module that gets the top visited pages of a website, I have a problem that when the cache invalidates by time guest users doesn't seem to be able to use the module that actually get's the info. Heres the code on the template file: $mostPopular = $cache->get("mostpopular"); if(!$mostPopular){ $latest = $modules->get("GoogleAnalyticsAPI"); $latest = $latest->getMostPopular(); $pa = new PageArray(); foreach($latest as $popular){ $thePage = $pages->get($sanitizer->pagePathName($popular['path'])); if($thePage->id){ $pa->add($thePage); } } $pa = $pa->filter("template=articulo"); $mostPopular = $pa; $cache->save("mostpopular", $pa, 604800); } Here's the code for the Google Analytics module: <?php /** * GoogleAnalyticsAPI (0.0.1) * Google Analytics API Wrapper * * @author elabx * * ProcessWire 3.x * Copyright (C) 2011 by Ryan Cramer * Licensed under GNU/GPL v2, see LICENSE.TXT * * http://www.processwire.com * http://www.ryancramer.com * */ class GoogleAnalyticsAPI extends WireData implements Module,ConfigurableModule { public static function getModuleInfo() { return array( 'title' => 'Google Analytics API Wrapper', 'version' => 1, 'author' => 'Eduardo San Miguel', 'summary' => 'Description of what this module does and who made it.', 'href' => 'http://www.domain.com/info/about/this/module/', 'autoload' => true, // set to true if module should auto-load at boot 'requires' => array( 'PHP>=5.4.1', 'ProcessWire>=3.x' ), ); } public $configData = array(); public $analytics = null; public function init() { // $this->addStyle("custom.css"); // $this->addScript("custom.js"); // $this->addHookAfter("class::function", $this, "yourFunction"); } public function initClient(){ // Use the developers console and download your service account // credentials in JSON format. Place them in this directory or // change the key file location if necessary. $configData = wire('modules')->getModuleConfigData($this); $KEY_FILE_LOCATION = wire("config")->paths->assets . 'service.json'; $this->log->save("google-debug", $KEY_FILE_LOCATION); // Create and configure a new client object. $client = new Google_Client(); $client->setApplicationName("ProcessWire CMS Analytics Reporting"); $client->setAuthConfig($KEY_FILE_LOCATION); $client->setScopes(['https://www.googleapis.com/auth/analytics.readonly']); $analytics = new Google_Service_AnalyticsReporting($client); $this->analytics = $analytics; //return $analytics; } public function getMostPopular(){ $this->initClient(); $analytics = $this->analytics; $VIEW_ID = "123456789"; // Get unique pageviews and average time on page. // Create the DateRange object. $dateRange = new Google_Service_AnalyticsReporting_DateRange(); $dateRange->setStartDate("7daysAgo"); $dateRange->setEndDate("today"); // Create the Metrics object. $sessions = new Google_Service_AnalyticsReporting_Metric(); $sessions->setExpression("ga:sessions"); $sessions->setAlias("sessions"); $dimensions = new Google_Service_AnalyticsReporting_Dimension(); //$dimensions->setExpression("ga:sessions"); $dimensions->setName("ga:pagePath"); $orderby = new Google_Service_AnalyticsReporting_OrderBy(); //$orderby->setOrderType("HISTOGRAM_BUCKET"); $orderby->setFieldName("ga:sessions"); $orderby->setSortOrder("DESCENDING"); // Create the ReportRequest object. $request = new Google_Service_AnalyticsReporting_ReportRequest(); $request->setViewId($VIEW_ID); $request->setDateRanges($dateRange); $request->setMetrics(array($sessions)); $request->setDimensions(array($dimensions)); $request->setOrderBys(array($orderby)); $body = new Google_Service_AnalyticsReporting_GetReportsRequest(); $body->setReportRequests( array( $request) ); $response = $analytics->reports->batchGet( $body ); foreach($response->getReports() as $i => $report){ //d($reports->getData()->getRows()); //d($reports); //$report = $reports[0]; $header = $report->getColumnHeader(); $dimensionHeaders = $header->getDimensions(); //d($dimensionHeaders); $metricHeaders = $header->getMetricHeader()->getMetricHeaderEntries(); $rows = $report->getData()->getRows(); $sessionsPerPageData = array(); for ( $rowIndex = 0; $rowIndex < count($rows); $rowIndex++) { $row = $rows[ $rowIndex ]; $dimensions = $row->getDimensions(); $metrics = $row->getMetrics(); for ($i = 0; $i < count($dimensionHeaders) && $i < count($dimensions); $i++) { $sessionsPerPageData[$rowIndex]["path"] = $dimensions[$i]; //print_r($dimensionHeaders[$i] . ": " . $dimensions[$i] . "\n"); } for ($j = 0; $j < count($metrics); $j++) { $values = $metrics[$j]->getValues(); for ($k = 0; $k < count($values); $k++) { $entry = $metricHeaders[$k]; $sessionsPerPageData[$rowIndex]["sessions"] = $values[$k]; //print_r($entry->getName() . ": " . $values[$k] . "\n"); } } } $this->log->save("google-debug", print_r($sessionsPerPageData, true)); return $sessionsPerPageData; } } } Could anyone give me a hint on why guest users wouldn't be able to use this module? If I login as admin it all works fine again, every time the cache invalidates, the info gets retrieved again.
  13. I've done it getting the actual Inputfield module, not the Fieldtype, I'd be very curious to see if the getInputfield method works! Get back to us on what works @bernhard :D
  14. I guess that's because users are pages under admin, so If a user with "guest" role (which is the default for every request made to the site) runs that code, it won't normally have access to that data, unles specified with check_access selector.
  15. I have done several integrations and I just basically grab this library through composer and use a private app credentials, the library also handles the API throttling which is extra nice when working with large amounts of data.
  16. THIS has happened to me multiple times calling it in the wrong place.
  17. Shouldn't output formatting be turned off in the $copy page, which is the one getting saved?
  18. Try: $datetofind=strtotime($date); foreach($page->special_days->find("date_value={$datetofind}, time_from!='', time_to!=''") as $special_day) { $slot_txt.=$special_day->time_from." to ".$special_day->time_to."<br/>"; }
  19. i also stumbled on this issue! Needed a drink too! Even asked a few days ago why this behaves like this! https://processwire.com/talk/topic/14638-no-input-data-when-post-form-with-ajax/?tab=comments#comment-163444
  20. Can confirm it works on PW3 too, I had some issues with the included AWS SDK: So just for trying something out because I couldn't figure out anything from the error, I switched to installing the Amazon SDK through composer to get the latest version of the SDK and I basically just had to change how the S3 client is initialized. $this->client = new S3Client([ 'version' => 'latest', //Hardcoded value, think this has to do with the SDK version? 'region' => 'us-east-2', //Hard coded value for now, could be a config field 'credentials' => [ 'key' => $this->s3_key, 'secret' => $this->s3_secret, ], ]); Also removed the require_once for the included SDK.
  21. Doesn't the previous output the link already for download?? You can use an if statement to check if there is an uploaded file: <?php if($publication->repeater_download):?> <p><?=$publication->repeater_description?></p> <a href="<?=$publication->repeater_download->url?>">Download</a> <?php endif ?> It uses naming convention, the following code will render the file content in site/template/fields/Repeater_publication.php : (EDIT: Edited some code on previous post, I was mixing Repeater Matrix field rendering with normal Repeaters) <?php //Render the repeater field in the current page $page->render("Repeater_publication"); And inside site/template/fields/Repeater_publication.php : <?php foreach($value as $publication):?> <p> <?=$publication->publication_year?></p> <?php endforeach?> Maybe you can save this for later if you already got the rendering almost done with a more common approach
  22. Try setting the output formatting for the $flexibleContentRepeater repeater matrix item (which is a page!) $flexibleContentRepeater->of(false); I also think you shouldn't be saving the page inside the hook:
  23. I think you might have a mistake here: $publications = $subpage->publication_year(); If I understand your setup correctly that returns a year integer, so looping on that will have no relevant effect. I think the final code could look like this: <?php foreach($page->children() as $subpage): ?> <!-- $subpage are the "year" pages --> <h1>Publications on: <?php $subpage->title </h2> <!-- eg. Publications on 1997 --> <?php foreach($subpage->Repeater_publications as $publication): ?> <p><?=$publication->repeater_description?></p> <a href="<?=$publication->repeater_download->url?>">Download</a> <?php endforeach; ?> <?php endforeach; There is a way to render the repeater field as its own template (or any field for what matters) with a feature called field rendering, you would have to create a template file as: templates/fields/Repeater_publication.php that actually renders some markup when calling the render method on the repeater field reference. <?php foreach($page->children() as $subpage): ?> <!-- $subpage are the "year" pages --> <h1>Publications on: <?php $subpage->title </h2> <!-- eg. Publications on 1997 --> <?php echo $page->render("Repeater_publications"); ?> <?php endforeach; And inside site/template/fields/Repeater_publication.php : <?php foreach($value as $publication):?> <p> <?=$publication->publication_year?></p> <?php endforeach?> Check this blog post for more info on field rendering, to see which variables are available in the template file: https://processwire.com/blog/posts/more-repeaters-repeater-matrix-and-new-field-rendering/#processwire-3.0.5-introduces-field-rendering-with-template-files
  24. Haven't tested but from what I read from the core files, is that InputfieldAutocomplete uses ProcessPageSearch to look for the pages matching the fields options. You could hook into the executeFor() method on ProcessPageSearch and replace the returned output with another list rendering of your own mix of pages, the ones found by the module, and the ones you define as curated at the beginning of the rendered list. I'd even bet you could add some CSS classes to make them look different.
  25. Check this documentation page, you can also add properties: https://processwire.com/api/hooks/#add_new_method
×
×
  • Create New...