I am currently making a time-clock system that is inside of a custom-built application (CRM) that a previous developer did. I've got the timeclock coming along nicely but have just a few questions..
Upon clocking in I set a session like so: $this->get('session')->set('clockedin', 'true');
I set a session so that I in order to show the clockin or clockout button I figured the easiest method would be to just read a session variable to determine which button to show using a twig if/else statement in the templates (i have the buttons show in 2 places, 1 is in every page and 1 is only in the timeclock system itself)
So, is this the best way to go about doing this or is there a better recommended way of going about it?
The next thing I wondered about is session expiration... in my config.yml I see:
session:
cookie_lifetime: 43200
auto_start: true
So, does this mean that the way i've set it lasts for 12 hours? Or in order for that to be true, would I need to use a cookie instead? I think that a cookie might be better, because if the browser closes (many of the employees aren't technologically inclined) I'd need this to be a persistent upon the next page load..
Thanks for any help..
If another indefinitely later operation depends on clockedin state I would not rely on sessions. If user logs him/herself out session gets invalidated (whole session), so clockedin would be lost.
I would rather use {% include %} or {% render %} to determine state every time you need to display that button. For example:
/**
* #Template()
*/
public function clockedInAction(){
.... // do some login here
$clocked_in = ....;
return array(
'clockedin' => $clockedin
);
}
and in your Twig:
{% render "AcmeBundle:SomeController:clockedIn" %}
Template of this controller would contains that {% if .... %} you wanted originally:
{# AcmeBundle:SomeController:clockedIn.html.twig #}
{% if clockedIn %}
display "Clocked In" button
{% else %}
display "Clocked Out" button
{% endif %}
Now, this is more expensive since on each request you have to assess the situation and then print appropriate template, but it's always consistent with a system...
Related
How to make Shopify sort blog Posts from oldest to newest?
Now the newest post is on top. It does not work for the blog that tells the story. Naturally, you have to read a story from the begging.
Some other blogs have to be sorted in default order - from newest to older. I.e. newest top.
Q: How to make Old first sorting for some blogs?
It depends on the amount of blog posts.
There are 3 approaches.
Liquid way
You can overwrite the article paginate and reverse the loop.
Example:
{% paginate blog.articles by 9999 %}
{% for article in blog.articles reversed %}
...
{% endfor %}
{% endpaginate %}
The larger the article amount the slower the DOM load speed will be.
So if you have 1000+ articles this is not a good solution.
REST API
You can register a private app an set only the Store content like articles, blogs, comments, pages, and redirects permission to Read and everything will be disabled.
Then you will need to request the following URL: https://API_KEY:API_PASS#STORE.myshopify.com/admin/api/2020-01/blogs/BLOG_ID/articles.json?limit=250 ( multiply times if you have more than 250 articles )
And reverse the result array.
If you have many articles this solution is once again not great.
GraphQL
The best one is to use the StoreFront GraphQL API here where you can reverse the results.
Example query:
{
blogByHandle(handle:"news"){
articles(first: 50, reverse: true){
edges {
node {
title
}
}
}
}
}
This way you will keep the pagination intact ( since GraphQL return Cursor that you can use for the pagination ) and you will keep the requests at minimum.
I've actually made an app to drag and drop blogs into the positions you would like. Here's the link to the Shopify App: Article Organizer Pro
I am trying to use output data that I have set up using the builder plugin through the Record Details component and running into some issues.
In my created plugin, Schools, I have Instructors (set up as a relation to an instructors plugin I created separately). It is possible to have more than one instructor, so they are store in the database as an array. Like so:
[{"instructor":"69"},{"instructor":"79"},{"instructor":"80"},{"instructor":"96"}]
The numbers represent the row ID of the instructor table
In my CMS I can pull all of the School info just fine into a partial (Builder Details), and can pull the array of instructors, but I am struggling to pass this array over to look up the ID and get the instructors information. My thought right now is to send it to another partial like so:
{% "school/instructor" insProfile = instructorID %}
The partial school/instructor is getting the ID just fine. I have included the Builder Details component and set it up with the following:
Alias: builderDetails
ModelClass: Instructors Plugin
Identifier value: insProfile
Key Column: id
Display Column: member_name
I am getting record not found results. I am confused as to how to set the Identifier Value to match the value I passed through my partial. I tried {% set identifierValue = insProfile %} before the {% set record = ... %} is run, but that did not work either.
I cannot use the :slug because that is already generating the content needed for the School page. In a TLDR, it seems I ultimately want to duplicate this function through another partial and a different tag.
Still learning October, so any help is appreciated.
I think the original post was a bit lengthy and ultimately what I wanted to do was pass a variable into a component. Such as:
{% component 'builderDetails' identifierValue=dynamicVar %}
This does not appear to work as the builder details component generates too far into page load to pick up the variable change.
Per the OctoberCMS docs, the best solution for me was to create my own component that would accept the variable before the page processed using onRender() function.
public function onRender()
{
// This code will be executed before the default component
// markup is rendered on the page or layout.
$this->profileID = $this->property('insProfile');
$this->ins = $this->getUserInfo($this->profileID);
}
This allows me to put my component in a partial, and request the partial with the variable 'insProfile'. The component will pick up the property insProfile before page/plugin generates and use that variable instead of the default.
I then set up another function to query the correct user info needed (getUserInfo)
It would be nice if the builder plugin components could be updated in such a way that I did not have to do this as the builder plugin is rather extensive out of the box.
Posting this in case anyone else comes along this problem and isn't sure where/how to pass a partial variable into a component.
UPDATE FOR CLARIFICATION.
I deleted the original question because it was confusing. Maybe this one is better?
I currently have something like this (simplified for brevity):
module Jekyll
module TOCGenerator
def toc(html)
...via nokogiri, get all <h3> tags, make table of contents entry
for each.
end
def contentWithTocAnchorLinks(html)
...make "back to top" anchor links under each <h3> tag that will
take the user back up to the table of contents
end
end
end
Then in the template:
<section>{{ content | toc }}</section>
<section>{{ content | contentWithTocAnchorLinks }} </section>
This works fine, but it seems sloppy. I've also tried stuffing both toc and contentWithAnchorLinks into an array and then doing something like {{ content | tocArray | first }} which also worked, but not very well (in some cases there is no table of contents and it was confusing). Anyway, what I would like to be able to do is something like this:
{% capture toc_content %}{{ content | toc_generate }}{% endcapture %}
<section> {{ toc_content.toc }} </section>
<section> {{ toc_content.content }}</section>
Jekyll does this all the time, as in {{ page.title }} but I'm not clear on how to replicate it. I only assume that a Ruby class is involved somewhere.
Does that make more sense?
If I understand your question, you want to parse a content, get some customers infos from it, and render a table of content.
From the Information Architecture point of view, you are supposed to store your customer datas in an atomic manner. For this, Jekyll offers you data files and collections that can be very helpful in your case.
If you need to make some basic transformations on your "objects" you can use liquid or jekyll filters.
I'm having an issue with the Laravel 4 Package Former and the use of checkboxes. I'm trying to Former::populate() a user edit form within a blade template but my checkboxes are always checked.
Here is my current code:
{{ Former::checkbox('is_admin')->text('Is Admin?'); }}
I've tried:
{{ Former::checkbox('is_admin')->text('Is Admin?')->check(false); }}
and
{{ Former::checkbox('is_admin')->text('Is Admin?')->forceValue(false); }}
To no avail.
My database field 'is_admin' is a boolean field. I thought maybe Former didn't like 1s and 0s but it doesn't uncheck my checkboxes even if I set a getter to return false.
Any Ideas?
Thanks
Sounds like a bug with Former.. Keep in mind it looks like you can overrule whatever happened with populate with populateField.
I'm developing a plugin to facilitate multilingual Jekyll sites, and as part of this I have to categorise posts according to their language.
I'm trying to tag the post according to its language, so I have overwritten the aggregate_post_info method, but when I print the site.tags variable, it is empty.
module Jekyll
class Site
alias_method :_aggregate_post_info, :aggregate_post_info
def aggregate_post_info(post)
_aggregate_post_info(post)
#tags[post.data['lang']] << post
end
end
end
I have achieved something similar by defining my own language specific variables, like in this simplified example:
for post in site.posts.docs do
lang = post.data['lang']
for tag in post.data['tags'] do
slug = jekyll_tagging_slug(tag)
site.config['t'][lang]['tagnames'] = slug
end
end
I also automatically generate tag pages (and category pages using a different approach without plug-ins), avoid name collisions for multiple languages, and precompute aggregate counts for better performance. The whole thing is described in two blog posts http://www.guido-flohr.net/multilang-with-jekyll/ and http://www.guido-flohr.net/jekyll-multilang-tags/.
You can simply add the post language as a tag, i.e. tags: [english, ruby, etc], avoiding altogether the monkey patching. So, when you want to show only lang-tagged posts, you simply filter them:
<ul class="posts">
{% for post in site.tags.english %}
<li>
{{ post.title }}
</li>
{% endfor %}
</ul>
This way, most of the work is done by Jekyll, saving you some time and effort. :)