Jump to content

Orkun

Members
  • Posts

    295
  • Joined

  • Last visited

Everything posted by Orkun

  1. Oh, missed that ^^. I have updated the post. Thanks @szabesz. It's still possible to have duplicate keys(authors which has the same name?) but probably is less likely. You could add a random prefix or something which you can remove at output with str_replace() or exlode() or something...
  2. I would do something like you mentioned: $articleCountPerAuthor = array(); foreach($pages->find("template=author") as $author){ $articleCount = $pages->count("template=article, author=$author"); $articleCountPerAuthor[$author->title] = $articleCount; } arsort($articleCountPerAuthor); // result of $articleCountPerAuthor /* array( "Actor XXX" => 500, "Actor XXX" => 400, "Actor XXX" => 200, )*/ $pages->count() - little overhead, since it doesn't load the pages like $pages->find() does arsort() - Sort an array in reverse by array value Since Processwire is extremly performant and efficient in handling pages you shouldn't have Problems.
  3. Wouldn't skip this the PageAdd Section? The customer need to define a specific filename(not an auto generated). He also wanted this "pre-selection" of languages and if its a internal newsletter checkbox. So "Name format for children" is possibly not an option. But still thanks for your effort @Robin S.
  4. I made a Newsletter-System for the customer where you can create Newsletters in "different languages", this means at the creation you have multiple checkboxes with the languages where you can check in which language your newsletter should be. After the creation it renders only the checked languages as language tabs for each multilang field you have (including the title field). Now the title field represents the "Filename" of the Newsletter which dont need to be multilang. The Problem I encountered: Let's say I create a new Newsletter called 20160811_testNewsletter only in the german language. Since french is the default language I must fill it out. After the creation the user only sees the german tabs for each field including the title field. The Problem that the user encounter is, that he can't change the Filename(title) when he makes a mistake and need to change it or when he copies a existing german newsletter where he want to change the filename, because he can only see the German Tab. Since the Filename(title) dosen't have multilang names, it doesn't need to be a multilang field. Now the other problem is that when I can change the fieldtype of title to a normal PageTitle it affects it globally which is not right. There other Custom-Build-Tools in the System where the title field need to be multilang. I think there are two possible ways: - Anykind of Hack to allow type changing for fields on Template basis (Perhaps with a hook?). - A hook which would update the default value of the title field every time with the value of the the other lang tabs, when I change/fill up the other field(german, italian etc... ) and save afterwards.
  5. Hi Everyone Can I change the type of the title field from PageTitleLanguage to PageTitle per template and not only global? Greetings Nukro
  6. Changed it completely, now it implements a little bit css with a hook inside InputfieldForm::render which does the magic of hiding and showing fields depending on language checkboxes. Since it's only a visual thing I removed the older hook where the languages get unpublished depending on the checkboxes. It just creates more bugs when playing around with the languages itself because the languages are a widespread feature in ProcessWire which are affecting other classes. With the new hook I am preventing that in some way since I have more control over what I am doing. public function init() { $this->addHookAfter('InputfieldForm::render', $this, 'renderForm'); } public function renderForm(HookEvent $event) { $id = $event->object->attr("id"); if($id != "ProcessPageEdit") return; $pageID = (int) $this->input->get->id; if(!$pageID) return; $page = $this->pages->get($pageID); $_out = ""; $index = ""; if($page->id){ foreach($this->languages as $key => $language) { if(!$page->languages_active->has($language)){ $_out .= "div[data-language='{$language->id}']{ display: none!important; }\n"; if($language->isDefault()){ $_out .= ".langTabs > ul li:first-child{ display: none!important; }\n"; } else { $_out .= "li[aria-controls$='__{$language->id}']{ display: none!important; }\n"; } } else { if(!$index) $index = $key; } } if($index) { $tabJSConfig = $this->wire('config')->js('LanguageTabs'); $tabJSConfig['activeTab'] = $index; $this->wire('config')->js('LanguageTabs', $tabJSConfig); } } if($_out) $_out = "<style>$_out</style>"; $event->return .= $_out; } Example: The above selection creates this inline CSS: <style> div[data-language='1029']{ display: none!important; } li[aria-controls$='__1029']{ display: none!important; } div[data-language='4286']{ display: none!important; } li[aria-controls$='__4286']{ display: none!important; } div[data-language='5842']{ display: none!important; } li[aria-controls$='__5842']{ display: none!important; } </style>
  7. This worked halfway for me: // First define your Hooks public function init() { $this->addHookAfter('ProcessPageAdd::buildForm', $this, 'addFields'); $this->addHookAfter('ProcessPageEdit::buildForm', $this, 'restrictLanguages'); } // Function for adding Fields to ProcessPageAdd public function addFields(HookEvent $event){ $form = $event->return; if($this->input->parent_id){ if($this->pages->get($this->input->parent_id)->template->id == 68){ $fieldsToAdd = array('is_internal_newsletter', 'languages_active', 'title'); foreach ($fieldsToAdd as $field) { $fieldForPage = $this->fields->get($field)->getInputfield($this->page); if($field=="title"){ $fieldForPage->label = "Filename"; } $form->prepend($field); } } } } // Function for disabling(unpublishing) Language Pages which are not checked in the field "languages_active". public function restrictLanguages(HookEvent $event){ $page = $event->object->getPage(); if($page->languages_active->count){ foreach($this->languages as $language){ if(!$page->languages_active->has($language)){ $language->addStatus(Page::statusUnpublished); } } $this->languages->reloadLanguages(); } } It works correctly but still it has some inaccuracies. - restrictLanguage Function doesn't effect at creation. It starts working after the first save. - when adding new items to repeater and saving afterwords it changes to its normal state (all language tabs are shown). But saving for the second time after added the repeater item, it starts working again. Have you some suggestions to fix the inaccuracies? Greetings Nukro
  8. Is it possible to manipulate the Form of the ProcessPageAdd with hooks or something? Like adding some other fields (from the corresponding Template) besides the title field. The values which you type in while creating the Page should also be adapted on the ProcessPageEdit of the created Page. Why I need this? I have a newsletter template with different multilanguage fields (using 5 Languages). The user has the ability to create new newsletter pages in different languages. But now there is a little problem of understanding the workflow. Let's say I want to create a new newsletter Page called "20160621_This_is_a_example_Newsletter" which only has two language versions of content. When editing the page I see 5 Lanuage Tabs per field and I fill up the ones with content that I need, which is normal. But now every time the user edits a newsletter page he will also see a empty language tab when the default language is empty (can be empty because fields are not required and perhaps the user doesn't need a newsletter which uses the default language) which can be confusing. To solve the confusion of the user I want to implement a field (type of PageListSelectMultiple) inside the ProcessPageAdd where you can choose in which language the new newsletter should be / will be. After that It should only show the Language Tabs which the user has selected on the ProcessPageAdd respectively the ones he really needs to fill up. This makes the Workflow a lot easier for the user. So the last thing to mention is - have you any idea how to make this work?
  9. Thank you, this worked for me: $q = $sanitizer->selectorValue($q); $selector = "(title|body|headline|link|linktext|introheadline|body2|content.body|content.body2|homeSections.title|homeSections.headline|homeSections.body|slider.body|team.body~=$q), (newsSections=[news.title|news.body~=$q]), limit=50, template!=news"; $matches = $pages->find($selector);
  10. How can I query pages from a pagetable which has a repeater, and this repeater has a title or body field. It's like a sub - sub - selector. At the moment I am trying this: $selector = "title|body|headline|link|linktext|introheadline|body2|content.body|content.body2|homeSections.title|homeSections.headline|homeSections.body|newsSections.news.title|newsSections.news.body|slider.body|team.body~=$q, limit=50, template!=news"; But "newsSections.news.title|newsSections.news.body" doesn't work (expected that). I need it because of my News Overview Page which has a newsSections PageTable Field for creating News Year Pages. The PageTable has a repeater where I can create the specific News for the corresponding News Year Page. I want to query the Title and Body field of the News Items.
  11. I want to thank of all the nice and clear comments. I was just curious about what is possible with processwire depending on developing custom systems and applications. Your answers pointet that out.
  12. I refering to the answer of Soma in this post where he makes assumptions about creating a own CMS based on pw-core since the core is a Framework. Probably my Question was perhaps not correctly formulated. I wanted to know, if someone had tried to build a own CMS based on the pw-core framework. Sorry for my confusing Question.
  13. Does someone has ever used the Processwire Core to build a own CMS/System? I remember that i saw a post about it, that it is possible to write your own CMS with the core. Has someone ever tried? Would interest me.
  14. Hi Guys Do you know how I could do multiple conditions (OR) with the Inputfield Dependencies with the Form API? At the moment I am doing this but that doesn't work: $showIfSelector = ""; foreach ($optionsArray as $list_id => $values) { $field = $this->modules->get("InputfieldSelect"); $field->label = "Field Parameter"; $field->attr("name", "fieldParam_".$list_id); //$field->columnWidth = 40; $field->showIf = "list_id=$list_id, method_recipient=groupSegment"; foreach ($values as $optgroup => $fieldValues) { if(array_key_exists($optgroup, $values)){ $field->addOption($optgroup, $fieldValues); } } $conditionContainer->add($field); $showIfSelector .= "fieldParam_$list_id%=mergefield, "; } $showIfSelector = trim($showIfSelector, ", "); $field = $this->modules->get("InputfieldSelect"); $field->label = "Logical Operator"; $field->attr("name", "operatorParamSeg_".$list_id); $field->addOptions(array( 'is' => "is", 'not' => "is not", 'contains' => "contains", 'notcontain' => "does not contain", 'starts' => "starts with", 'ends' => "ends with", 'greater' => "is greater than", 'less' => "is less than", 'blank' => "is blank", 'blank_not' => "is not blank" )); $field->showIf = "list_id=$list_id, method_recipient=groupSegment, $showIfSelector"; $conditionContainer->add($field); $field = $this->modules->get("InputfieldText"); $field->label = "Search Parameter"; $field->attr("name", "searchParam_".$list_id); $field->showIf = "list_id=$list_id, method_recipient=groupSegment, $showIfSelector"; $conditionContainer->add($field); I am generating multiple Selects for my different Values. Everytime I select a List, it would show me the right fieldParam Field with the right mergefields and groups values. So at the moment I have multiple "names" which containe the phrase fieldParam + _listID. So I create a showIfSelector Var which will be filled with all possible conditions for every Select. After that i give the $showIfSelector to my showIf option inside "operatorParamSeg" and "searchParam" Inputfield. Now It should show me the operator select and the search inputfield everytime when i Select a mergefield in the fieldParam. With this way I don't have to render the search and operator Inputfield multiple times inside the foreach. PS: I know my English is terrible at the moment because I am not focused. Why I am not focused? Because I am tired. Why I am tired? Because I have watched to much series last night. Greetings Orkun
  15. Nevermind... Solved it by adding the $list_id to the fieldParam name attribute. After that I just have to do this: $field->showIf = "method_recipient=groupSegment, fieldParam_$list_id=$groupID";
  16. Hi Guys At first my created Inputfields InputfieldSelect - label: "Email List", name: "list_id" InputfieldSelect - label: "Field Parameter", name: "fieldParam" InputfieldAsmSelect - label: "Interests Parameter", name: "interestParam" I have a problem with the showIf Option for my interestParam field. I have multiple "fieldParam" Selects because of the "list_id" Select. Everytime i select a Email List it displays me the right "fieldParam" Select because of the showIf option I defined in "fieldParam": $field->showIf = "list_id=$list_id, method_recipient=groupSegment"; Since the "list_id" Select exists only one time this works great. Now I'am trying to do this for the "interestParam" MultipleSelect. Everytime I select a group inside fieldParam it should show me the right "interestParam" Select. For this I am also adding a showIf Option: $field->showIf = "method_recipient=groupSegment, fieldParam=$groupID"; This fails because the fieldParam exists multiple times. So what can I do about it? Greetings Nukro
  17. This worked for me: I'm doing a "addHookBefore" inside the ProcessPageAdd::executeTemplate Method. public function init() { if(!$this->user->isSuperuser() && $this->user->hasRole("XXXXXXXX")) $this->addHookBefore('ProcessPageAdd::executeTemplate', $this, 'redirectParent'); } Inside the redirectParent Hook Method public function redirectParent(HookEvent $event){ //Get ID from URL $templateID = (int) $this->input->get->template_id; //Check if it's a Newsletter if($templateID == 66){ //Get the Parent Page specified by the choose_sender_2016 Pagefield in the user & newsletter Template $parent = $this->pages->get("template=newsletter-clinic, choose_sender_2016={$this->user->choose_sender_2016}"); //Check if a Parent was found if($parent->id){ //Skip the Parent Selection with a redirect $url = "./?parent_id=" . $parent->id; if($this->wire('input')->get('modal')) $url .= "&modal=1"; $this->wire('session')->redirect($url); } } }
  18. Do I have to make a hook inside ProcessPageAdd::___executeTemplate or something like that?
  19. Hi Guys I have a question about the Add Page Shortcut Functionality. In General you can set the family settings on template so that you have to choose a new Parent when adding a new page of the defined template with the shortcut menu. In my case I can add new "Newsletter" Pages but I have to choose under which Parent it should be added. But as a "Clinic" - User I can only add the Newsletter Pages under the Parent Page which belongs to this User (was made with a Hook inside Page::addable / Page:editable). Because of that I only see one Parent Item in the Dropdown Shortcut Menu which is correct. Can this Selection be skipped when the shortcut menu only has one Parent to choose (Also in ProLister "Add New")?
  20. I saw in the 'template structure methods' in the doc section that ryan mentioned a mvc method for beginners. When will it be published? https://processwire.com/docs/tutorials/how-to-structure-your-template-files/page5 I'm just curious
  21. Hi Guys I'am trying to add a csv-import for our mailchimp module in processwire. So I added a new InputfieldFieldset["Import Mailchimp-Members via CSV File"] to the InputfieldWrapper["List Members"] which is also added final to the InputfieldForm. Inside the Inputfieldset I added a InputfieldFile with this configuration: $fieldsetImport = $this->modules->get("InputfieldFieldset"); $fieldsetImport->label = "Import Mailchimp-Members via CSV File"; $fieldsetImport->collapsed = Inputfield::collapsedYes; $field = $this->modules->get("InputfieldFile"); $field->name = 'csv_file'; $field->label = 'CSV File'; $field->extensions = 'csv txt'; $field->maxFiles = 1; $field->overwrite = true; $field->descriptionRows = 0; $field->required = false; $field->description = "The list of field names must be provided as the first row in the Spreadsheet file. " . "UTF-8 compatible encoding is assumed. File must have the extension '.csv' or '.txt' "; $fieldsetImport->add($field); $field = $this->modules->get("InputfieldSubmit"); $field->attr("name", "import"); $field->attr("value", "Import"); $fieldsetImport->add($field); When I add a File and the click on import the "executeEdit" Function will be triggered. This function does the processing of the Form. It handles multiple $this->input->post->submitname: public function executeEdit(){ if($this->input->post->submit) { //other form processing } if($this->input->post->subscribe) { //other form processing } if($this->input->post->import) { $form->processInput($this->input->post); if(!$form->getErrors()) { $csv_file = $form->get("csv_file")->value; if(count($csv_file)) { $csvFile = $csvFile->first(); $csvFile->rename("address-import.csv"); $csvFilename = $csvFile->filename; }else{ echo "No files were found"; } //$this->session->redirect("../edit/?id=$list_id"); } } if($this->input->post->createSegment) { // other form processing } } The processing part of the $this->input->post->import is from the ImportPagesCSV.module from Ryan. But I always get the output "No files were found". What I'm missing?
  22. I've solve the problem by setting the setlocale(LC_ALL, 'xx_XX.utf8') in every case with the right locale code. SOLVED: The endsolution looks like this: foreach ($languages->find("name!=en") as $language) { $user->language = $languages->get($language->name); switch ($language->name) { case 'default': setlocale(LC_ALL, 'fr_FR.utf8'); $date = strftime("%d. %B %G", $page->getUnformatted('date')); break; case 'de': setlocale(LC_ALL, 'de_DE.utf8'); $date = strftime("%d. %B %G", $page->getUnformatted('date')); break; case 'it': setlocale(LC_ALL, 'it_IT.utf8'); $date = strftime("%d. %B %G", $page->getUnformatted('date')); break; } echo $date."<br />"; } I thought, that when I would change the user language on every loop, it would also change the LC_ALL but somehow it doesn't do that. So I set the setlocale manuallay on every loop. When you need other locale-codes here is a list of all languages(or probably the most of it): http://www.red-route.org/code/php-international-language-and-locale-codes-demonstration And also thank you to @LostKobrakai, he pointed me to the right direction!
  23. Somehow i get every time: fr_FR.utf8 fr_FR.utf8 fr_FR.utf8 does $user->language = $languages->get($language->name); dont have any effect or what?
  24. Now i get this : 01. avril 1600-FR/DEFAULT 01. avril 1600-DE 01. avril 1600-IT My date field configuration looks like this:
×
×
  • Create New...