Beispiel #1
0
 public function getFromStore($code)
 {
     $this->inner->UnitTags["store-{$code}"] = true;
     $qi = $this->inner->getQI();
     $siteCode = $this->inner->InnerProc->AppTool->getProperty('site');
     return $qi->queryFetchSingleCell('select o.val from store o inner join site s using (site_id) where s.code = ' . $qi->quote($siteCode, \PDO::PARAM_STR) . ' and o.code = ' . $qi->quote($code, \PDO::PARAM_STR));
 }
Beispiel #2
0
 public function getFieldValues(array $fieldCodes = null)
 {
     if (!isset($fieldCodes)) {
         $fieldCodes = $this->getFieldSet()['fields'];
     }
     if (empty($fieldCodes)) {
         return [];
     }
     // - Build the query
     $seq = 0;
     $qiJoin = [];
     $qiSelect = [];
     $fields = [];
     foreach ($fieldCodes as $code) {
         $fields[$code] = $field = $this->getMeta()->getField($code);
         $t = 'f' . ++$seq . '_' . $field['dbCode'];
         $join = [$field['table'] . " {$t} using (resource_id)", 'and', ["{$t}.field_code", '=', $field['dbCode'], \PDO::PARAM_STR]];
         if (!$field['required']) {
             array_unshift($join, 'left');
         }
         $qiJoin[] = $join;
         $qiSelect[] = "{$t}.val as " . $field['dbCode'];
         if ($field['dataType'] === 'richText') {
             $qiSelect[] = "{$t}.rtype_code as " . $field['dbCode'] . '_type';
         }
     }
     $qi = $this->inner->getQI();
     $row = $qi->select(['select' => $qiSelect, 'from' => 'resource r', 'join' => $qiJoin, 'where' => [['r.resource_id', '=', $this->resourceId, \PDO::PARAM_INT]]])->queryFetchSingleRow();
     if (!isset($row)) {
         throw new Error("Missing required fields for resource {$this->resourceId}");
     }
     // - Format the result set
     $map = [];
     foreach ($fields as $code => $field) {
         $val = $row[$field['dbCode']];
         switch ($field['dataType']) {
             case 'richText':
                 $map[$code] = ['type' => $row[$field['dbCode'] . '_type'], 'value' => $val];
                 break;
             case 'text':
             case 'string':
                 $map[$code] = $val;
                 break;
             case 'int':
                 $map[$code] = intval($val);
                 break;
             default:
                 throw new Error('Unknown data type: ' . $field['dataType']);
         }
     }
     return $map;
 }