Пример #1
0
 public function getAttributesNamesByEntityType($sEntityType)
 {
     $sSubSql = "\n(SELECT DISTINCT name FROM %seav_attributes_%s as attrs, %seav_entities as entities\n\tWHERE entity_type = %s AND entities.id = attrs.id_entity)\n";
     foreach (\AEntity::getTypes() as $sSqlType) {
         $aSql[] = sprintf($sSubSql, $this->prefix(), $sSqlType, $this->prefix(), $this->escapeString($sEntityType));
     }
     $sSql = implode("UNION\n", $aSql);
     return $sSql;
 }
Пример #2
0
 /**
  * 
  * @param type $sType
  * @param type $aViewAttrs
  * @param type $iOffset
  * @param type $iLimit
  * @param type $aSearchAttrs
  * @param type $sOrderBy
  * @param type $iSortOrder
  * @param type $aIdsOrUUIDs
  * @return \AEntity
  */
 public function getEntities($sType, $aViewAttrs = array(), $iOffset = 0, $iLimit = 20, $aSearchAttrs = array(), $sOrderBy = '', $iSortOrder = \ESortOrder::ASC, $aIdsOrUUIDs = array())
 {
     $mResult = false;
     if ($aViewAttrs === null) {
         $aViewAttrs = array();
     } else {
         if (count($aViewAttrs) === 0) {
             $this->oConnection->Execute($this->oCommandCreator->getAttributesNamesByEntityType($sType));
             while (false !== ($oRow = $this->oConnection->GetNextRecord())) {
                 $aViewAttrs[] = $oRow->name;
             }
             $this->oConnection->FreeResult();
         }
     }
     if ($this->oConnection->Execute($this->oCommandCreator->getEntities($sType, $aViewAttrs, $iOffset, $iLimit, $aSearchAttrs, $sOrderBy, $iSortOrder, $aIdsOrUUIDs))) {
         $oRow = null;
         $mResult = array();
         while (false !== ($oRow = $this->oConnection->GetNextRecord())) {
             if (class_exists($sType)) {
                 $oEntity = call_user_func($sType . '::createInstance');
             } else {
                 $oEntity = new \AEntity($sType);
             }
             $oEntity->iId = (int) $oRow->entity_id;
             $oEntity->sUUID = $oRow->entity_uuid;
             $oEntity->sModuleName = $oRow->entity_module;
             foreach (get_object_vars($oRow) as $sKey => $mValue) {
                 if (strrpos($sKey, 'attr_', -5) !== false) {
                     $sAttrKey = substr($sKey, 5);
                     $oEntity->{$sAttrKey} = \CAttribute::createInstance($sAttrKey, $mValue, null, $oEntity->isEncryptedAttribute($sAttrKey), $oEntity->iId);
                 }
             }
             $mResult[] = $oEntity;
         }
         $this->oConnection->FreeResult();
     }
     $this->throwDbExceptionIfExist();
     return $mResult;
 }
Пример #3
0
 /**
  * 
  * @param \AEntity $oEntity
  * @return boolean
  * @throws type
  */
 protected function updateEntity(\AEntity $oEntity)
 {
     $mResult = false;
     if (0 < $oEntity->countAttributes()) {
         try {
             $this->setAttributes($oEntity->iId, $oEntity->getAttributes());
             $mResult = true;
         } catch (Exception $ex) {
             $mResult = false;
             throw CApiManagerException(Errs::Main_UnknownError);
         }
     }
     return $mResult;
 }