<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Modifies object record</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.hw-mapid.html">hw_mapid</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.hw-mv.html">hw_mv</a></div> <div class="up"><a href="ref.hw.html">Hyperwave Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.hw-modifyobject" class="refentry"> <div class="refnamediv"> <h1 class="refname">hw_Modifyobject</h1> <p class="verinfo">(PHP 4)</p><p class="refpurpose"><span class="refname">hw_Modifyobject</span> — <span class="dc-title">Modifies object record</span></p> </div> <div class="refsect1 description" id="refsect1-function.hw-modifyobject-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">bool</span> <span class="methodname"><strong>hw_modifyobject</strong></span> ( <span class="methodparam"><span class="type">int</span> <code class="parameter">$connection</code></span> , <span class="methodparam"><span class="type">int</span> <code class="parameter">$object_to_change</code></span> , <span class="methodparam"><span class="type">array</span> <code class="parameter">$remove</code></span> , <span class="methodparam"><span class="type">array</span> <code class="parameter">$add</code></span> [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$mode</code></span> ] )</div> <p class="para rdfs-comment"> This command allows to remove, add, or modify individual attributes of an object record. The object is specified by the Object ID <em><code class="parameter">object_to_change</code></em>. In order to modify an attribute one will have to remove the old one and add a new one. <span class="function"><strong>hw_modifyobject()</strong></span> will always remove the attributes before it adds attributes unless the value of the attribute to remove is not a string or array. </p> <p class="para"> The keys of both arrays are the attributes name. The value of each array element can either be an array, a string or anything else. If it is an array each attribute value is constructed by the key of each element plus a colon and the value of each element. If it is a string it is taken as the attribute value. An empty string will result in a complete removal of that attribute. If the value is neither a string nor an array but something else, e.g. an integer, no operation at all will be performed on the attribute. This is necessary if you want to add a completely new attribute not just a new value for an existing attribute. If the remove array contained an empty string for that attribute, the attribute would be tried to be removed which would fail since it doesn't exist. The following addition of a new value for that attribute would also fail. Setting the value for that attribute to e.g. 0 would not even try to remove it and the addition will work. </p> <p class="para"> If you would like to change the attribute 'Name' with the current value 'books' into 'articles' you will have to create two arrays and call <span class="function"><strong>hw_modifyobject()</strong></span>. <div class="example" id="example-4377"> <p><strong>Example #1 modifying an attribute</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /> </span><span style="color: #FF8000">// $connect is an existing connection to the Hyperwave server<br /> // $objid is the ID of the object to modify<br /> </span><span style="color: #0000BB">$remarr </span><span style="color: #007700">= array(</span><span style="color: #DD0000">"Name" </span><span style="color: #007700">=> </span><span style="color: #DD0000">"books"</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">$addarr </span><span style="color: #007700">= array(</span><span style="color: #DD0000">"Name" </span><span style="color: #007700">=> </span><span style="color: #DD0000">"articles"</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">$hw_modifyobject</span><span style="color: #007700">(</span><span style="color: #0000BB">$connect</span><span style="color: #007700">, </span><span style="color: #0000BB">$objid</span><span style="color: #007700">, </span><span style="color: #0000BB">$remarr</span><span style="color: #007700">, </span><span style="color: #0000BB">$addarr</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> In order to delete/add a name=value pair from/to the object record just pass the remove/add array and set the last/third parameter to an empty array. If the attribute is the first one with that name to add, set attribute value in the remove array to an integer. <div class="example" id="example-4378"> <p><strong>Example #2 adding a completely new attribute</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /> </span><span style="color: #FF8000">// $connect is an existing connection to the Hyperwave server<br /> // $objid is the ID of the object to modify<br /> </span><span style="color: #0000BB">$remarr </span><span style="color: #007700">= array(</span><span style="color: #DD0000">"Name" </span><span style="color: #007700">=> </span><span style="color: #0000BB">0</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">$addarr </span><span style="color: #007700">= array(</span><span style="color: #DD0000">"Name" </span><span style="color: #007700">=> </span><span style="color: #DD0000">"articles"</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">$hw_modifyobject</span><span style="color: #007700">(</span><span style="color: #0000BB">$connect</span><span style="color: #007700">, </span><span style="color: #0000BB">$objid</span><span style="color: #007700">, </span><span style="color: #0000BB">$remarr</span><span style="color: #007700">, </span><span style="color: #0000BB">$addarr</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> <p class="para"> <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara"> Multilingual attributes, e.g. 'Title', can be modified in two ways. Either by providing the attributes value in its native form 'language':'title' or by providing an array with elements for each language as described above. The above example would than be: </span> </p></blockquote> <div class="example" id="example-4379"> <p><strong>Example #3 modifying Title attribute</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /> $remarr </span><span style="color: #007700">= array(</span><span style="color: #DD0000">"Title" </span><span style="color: #007700">=> </span><span style="color: #DD0000">"en:Books"</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">$addarr </span><span style="color: #007700">= array(</span><span style="color: #DD0000">"Title" </span><span style="color: #007700">=> </span><span style="color: #DD0000">"en:Articles"</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">$hw_modifyobject</span><span style="color: #007700">(</span><span style="color: #0000BB">$connect</span><span style="color: #007700">, </span><span style="color: #0000BB">$objid</span><span style="color: #007700">, </span><span style="color: #0000BB">$remarr</span><span style="color: #007700">, </span><span style="color: #0000BB">$addarr</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> or <div class="example" id="example-4380"> <p><strong>Example #4 modifying Title attribute</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /> $remarr </span><span style="color: #007700">= array(</span><span style="color: #DD0000">"Title" </span><span style="color: #007700">=> array(</span><span style="color: #DD0000">"en" </span><span style="color: #007700">=> </span><span style="color: #DD0000">"Books"</span><span style="color: #007700">));<br /> </span><span style="color: #0000BB">$addarr </span><span style="color: #007700">= array(</span><span style="color: #DD0000">"Title" </span><span style="color: #007700">=> array(</span><span style="color: #DD0000">"en" </span><span style="color: #007700">=> </span><span style="color: #DD0000">"Articles"</span><span style="color: #007700">, </span><span style="color: #DD0000">"ge"</span><span style="color: #007700">=></span><span style="color: #DD0000">"Artikel"</span><span style="color: #007700">));<br /> </span><span style="color: #0000BB">$hw_modifyobject</span><span style="color: #007700">(</span><span style="color: #0000BB">$connect</span><span style="color: #007700">, </span><span style="color: #0000BB">$objid</span><span style="color: #007700">, </span><span style="color: #0000BB">$remarr</span><span style="color: #007700">, </span><span style="color: #0000BB">$addarr</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> This removes the English title 'Books' and adds the English title 'Articles' and the German title 'Artikel'. <div class="example" id="example-4381"> <p><strong>Example #5 removing attribute</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /> $remarr </span><span style="color: #007700">= array(</span><span style="color: #DD0000">"Title" </span><span style="color: #007700">=> </span><span style="color: #DD0000">""</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">$addarr </span><span style="color: #007700">= array(</span><span style="color: #DD0000">"Title" </span><span style="color: #007700">=> </span><span style="color: #DD0000">"en:Articles"</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">$hw_modifyobject</span><span style="color: #007700">(</span><span style="color: #0000BB">$connect</span><span style="color: #007700">, </span><span style="color: #0000BB">$objid</span><span style="color: #007700">, </span><span style="color: #0000BB">$remarr</span><span style="color: #007700">, </span><span style="color: #0000BB">$addarr</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara"> This will remove all attributes with the name 'Title' and adds a new 'Title' attribute. This comes in handy if you want to remove attributes recursively. </span> </p></blockquote> <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara"> If you need to delete all attributes with a certain name you will have to pass an empty string as the attribute value. </span> </p></blockquote> <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara"> Only the attributes 'Title', 'Description' and 'Keyword' will properly handle the language prefix. If those attributes don't carry a language prefix, the prefix 'xx' will be assigned. </span> </p></blockquote> <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara"> The 'Name' attribute is somewhat special. In some cases it cannot be complete removed. You will get an error message 'Change of base attribute' (not clear when this happens). Therefore you will always have to add a new Name first and than remove the old one. </span> </p></blockquote> <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara"> You may not surround this function by calls to <span class="function"><a href="function.hw-getandlock.html" class="function">hw_getandlock()</a></span> and <span class="function"><a href="function.hw-unlock.html" class="function">hw_unlock()</a></span>. <span class="function"><strong>hw_modifyobject()</strong></span> does this internally. </span> </p></blockquote> </p> </div> <div class="refsect1 parameters" id="refsect1-function.hw-modifyobject-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">connection</code></em></span> <dd> <p class="para"> The connection identifier. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">object_to_change</code></em></span> <dd> <p class="para"> The object to be changed. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">remove</code></em></span> <dd> <p class="para"> An array of attributes to remove. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">add</code></em></span> <dd> <p class="para"> An array of attributes to add. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">mode</code></em></span> <dd> <p class="para"> The last parameter determines if the modification is performed recursively. 1 means recursive modification. If some of the objects cannot be modified they will be skipped without notice. <span class="function"><a href="function.hw-error.html" class="function">hw_error()</a></span> may not indicate an error though some of the objects could not be modified. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.hw-modifyobject-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns <strong><code>TRUE</code></strong> on success or <strong><code>FALSE</code></strong> on failure. </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.hw-mapid.html">hw_mapid</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.hw-mv.html">hw_mv</a></div> <div class="up"><a href="ref.hw.html">Hyperwave Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>