Пример #1
0
 /**
  * Parse custom attribute filter conditions
  *
  * Generate conditions of the custom attributes for the SQL WHERE statement.
  * The filter conditions are defined through the two dimensional array $arrFilter.
  * Each key-value pair represents an attribute and its associated condition to which it must fit to.
  * The condition could either be a integer or string depending on the attributes type, or it could be
  * a collection of integers or strings represented in an array.
  *
  * Matches single (scalar) or multiple (array) search terms against a
  * number of fields.  Generally, the term(s) are enclosed in percent
  * signs ("%term%"), so any fields that contain them will match.
  * However, if the search parameter is a string and does contain a percent
  * sign already, none will be added to the query.
  * This allows searches using custom patterns, like "fields beginning
  * with "a" ("a%").
  * (You might even want to extend this to work with arrays, too.
  * Currently, only the shop module uses this feature.) -- RK 20100910
  * @param   mixed     $arrFilter    The term or array of terms
  * @return  array                   The array of SQL snippets
  */
 protected function parseCustomAttributeFilterConditions($arrFilter)
 {
     if (empty($this->objAttribute)) {
         $this->initAttributes();
     }
     $arrConditions = array();
     foreach ($arrFilter as $attribute => $condition) {
         if ($this->objAttribute->load($attribute) && !$this->objAttribute->isCoreAttribute($attribute)) {
             switch ($this->objAttribute->getDataType()) {
                 case 'string':
                     $percent = '%';
                     if (!is_array($condition) && strpos('%', $condition) !== false) {
                         $percent = '';
                     }
                     $arrConditions[] = "tblA.`attribute_id` = " . $attribute . " AND (tblA.`value` LIKE '{$percent}" . (is_array($condition) ? implode("{$percent}' OR tblA.`value` LIKE '{$percent}", array_map('addslashes', $condition)) : addslashes($condition)) . "{$percent}')";
                     break;
                 case 'int':
                     $arrConditions[] = "tblA.`attribute_id` = " . $attribute . " AND (tblA.`value` = '" . (is_array($condition) ? implode("' OR tblA.`value` = '", array_map('intval', $condition)) : intval($condition)) . "')";
                     break;
                 case 'array':
                     if (count($this->objAttribute->getChildren())) {
                         foreach ($this->objAttribute->getChildren() as $childAttributeId) {
                             $arrSubFilter[$childAttributeId] = $condition;
                         }
                         $arrConditions[] = implode(' OR ', $this->parseCustomAttributeFilterConditions($arrSubFilter));
                     }
                     break;
             }
         }
     }
     return $arrConditions;
 }
Пример #2
0
 function _configDeleteAttribute()
 {
     global $_ARRAYLANG, $objDatabase;
     // only administrators are allowed to modify the config
     if (!\Permission::hasAllAccess()) {
         \Permission::noAccess();
     }
     $objAttribute = new \User_Profile_Attribute();
     $attributeId = isset($_REQUEST['id']) ? contrexx_addslashes($_REQUEST['id']) : 0;
     if ($attributeId && $objAttribute->load($attributeId)) {
         if ($objAttribute->delete()) {
             self::$arrStatusMsg['ok'][] = $_ARRAYLANG['TXT_ACCESS_SUCCESS_DEL_ATTRIBUTE'];
             if ($objAttribute->getParent()) {
                 $_REQUEST['id'] = $objAttribute->getParent();
                 return $this->_configModifyAttribute();
             } else {
                 $_REQUEST['id'] = 0;
                 return $this->_configAttributes();
             }
         } else {
             self::$arrStatusMsg['error'][] = $objAttribute->getErrorMsg();
             if ($objAttribute->getParent()) {
                 $_REQUEST['id'] = $objAttribute->getParent();
                 return $this->_configModifyAttribute();
             } else {
                 $_REQUEST['id'] = 0;
                 return $this->_configAttributes();
             }
         }
     } else {
         self::$arrStatusMsg['error'][] = $_ARRAYLANG['TXT_ACCESS_INVALID_PROFILE_ATTRIBUTE_SPECIFIED'];
         $_REQUEST['id'] = 0;
         return $this->_configAttributes();
     }
 }