<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[FrontAccounting forum — Optimise get_company_pref()]]></title>
	<link rel="self" href="https://frontaccounting.com/punbb/extern.php?action=feed&amp;tid=6998&amp;type=atom" />
	<updated>2017-10-02T03:38:48Z</updated>
	<generator>PunBB</generator>
	<id>https://frontaccounting.com/punbb/viewtopic.php?id=6998</id>
		<entry>
			<title type="html"><![CDATA[Re: Optimise get_company_pref()]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=28803#p28803" />
			<content type="html"><![CDATA[<p>@joe: can commit this.<br /><a href="https://github.com/FrontAccountingERP/FA/commit/b4c00f88c87e776a7700879adb15a2b013d48045">Committed</a>.</p>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2017-10-02T03:38:48Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=28803#p28803</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Optimise get_company_pref()]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=28795#p28795" />
			<content type="html"><![CDATA[<p>The file <strong>admin/db/company_db.inc</strong> has the <strong><em>function</em> get_company_pref($prefs = null)</strong>:</p><div class="codebox"><pre><code>function get_company_pref($prefs = null)
{
    global $SysPrefs, $db_version;

    if (!isset($SysPrefs-&gt;prefs))     // just after first login or reset
        $SysPrefs-&gt;refresh();

    $all = $SysPrefs-&gt;prefs;

    if (!$prefs)
        return $all;
    elseif (is_string($prefs))
        return @$all[$prefs];

    $ret = array();
    foreach($prefs as $name)
        $ret[$name] = $all[$name];

    return $ret;
}</code></pre></div><p>This can be simplified and made efficient by replacing it with:</p><div class="codebox"><pre><code>function get_company_pref($prefs = null){
    global $SysPrefs, $db_version;

    if (!isset($SysPrefs-&gt;prefs))     // just after first login or reset
        $SysPrefs-&gt;refresh();

    $all = $SysPrefs-&gt;prefs;
    if ($prefs &amp;&amp; is_string($prefs))
        return @$all[$prefs];     // silent on absent array element

    if (!is_array($all))
        $all = array();

    return $all;}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2017-10-01T04:14:59Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=28795#p28795</id>
		</entry>
</feed>
