Beispiel #1
0
 /**
  * Create new  version
  * @property Db_Object $object
  * @return boolean
  */
 public function newVersion(Db_Object $object)
 {
     $object->commitChanges();
     $newVersion = $this->getLastVersion($object->getName(), $object->getId()) + 1;
     $newData = $object->getData();
     if ($object->getConfig()->hasEncrypted()) {
         $ivField = $object->getConfig()->getIvField();
         $ivKey = $object->get($ivField);
         if (empty($ivKey)) {
             $ivKey = Utils_String::createEncryptIv();
             $newData[$ivField] = $ivKey;
         }
         $newData = $this->getStore()->encryptData($object, $newData);
     }
     $newData['id'] = $object->getId();
     try {
         $vObject = new Db_Object('vc');
         $vObject->set('date', date('Y-m-d'));
         $vObject->set('data', base64_encode(serialize($newData)));
         $vObject->set('user_id', User::getInstance()->id);
         $vObject->set('version', $newVersion);
         $vObject->set('record_id', $object->getId());
         $vObject->set('object_name', $object->getName());
         $vObject->set('date', date('Y-m-d H:i:s'));
         if ($vObject->save()) {
             return $newVersion;
         }
         return false;
     } catch (Exception $e) {
         $this->logError('Cannot create new version for ' . $object->getName() . '::' . $object->getId() . ' ' . $e->getMessage());
         return false;
     }
 }
Beispiel #2
0
 public function getHid(Db_Object $object)
 {
     $name = strtolower($object->getName());
     switch ($object->getName()) {
         case 'sysdocs_class':
             return $this->getClassHid($object->get('fileHid'), $object->get('name'));
             break;
         case 'sysdocs_class_method':
             return $this->getMethodHid($object->get('classHid'), $object->get('name'));
             break;
         case 'sysdocs_class_method_param':
             return $this->getParamHid($object->get('methodHid'), $object->get('name'));
             break;
         case 'sysdocs_class_property':
             return $this->getPropertysHid($object->get('classHid'), $object->get('name'));
             break;
         case 'sysdocs_file':
             return $this->getFileHid($object->get('path'), $object->get('name'));
             break;
         default:
             throw new Exception('Undefined HID generator for ' . $name);
     }
 }
Beispiel #3
0
 /**
  * (non-PHPdoc)
  * @see Db_Object_Event_Manager::fireEvent()
  */
 public function fireEvent($code, Db_Object $object)
 {
     $objectName = ucfirst($object->getName());
     $triggerClass = Utils_String::classFromString('Trigger_' . $objectName);
     if (class_exists($triggerClass) && method_exists($triggerClass, $code)) {
         $trigger = new $triggerClass();
         if ($this->_cache) {
             $trigger->setCache($this->_cache);
         }
         $trigger->{$code}($object);
     } elseif (method_exists('Trigger', $code)) {
         $trigger = new Trigger();
         if ($this->_cache) {
             $trigger->setCache($this->_cache);
         }
         $trigger->{$code}($object);
     }
 }
Beispiel #4
0
 /**
  * Get Associated objects
  * @param Db_Object $object
  * @return array   like
  * array(
  * 	  'single' => array(
  * 			'objectName'=>array(id1,id2,id3),
  * 			...
  * 			'objectNameN'=>array(id1,id2,id3),
  * 	   ),
  * 	   'multy' =>array(
  * 			'objectName'=>array(id1,id2,id3),
  * 			...
  * 			'objectNameN'=>array(id1,id2,id3),
  * 	   )
  * )
  */
 public static function getAssociatedObjects(Db_Object $object)
 {
     $linkedObjects = array('single' => array(), 'multy' => array());
     self::_buildAssociations();
     $objectName = $object->getName();
     $objectId = $object->getId();
     if (!isset(self::$_objectAssociations[$objectName])) {
         return array();
     }
     foreach (self::$_objectAssociations as $testObject => $links) {
         if (!isset($links[$objectName])) {
             continue;
         }
         $sLinks = self::_getSingleLinks($objectId, $testObject, $links[$objectName]);
         if (!empty($sLinks)) {
             $linkedObjects['single'][$testObject] = $sLinks;
         }
     }
     $linkedObjects['multy'] = self::_getMultyLinks($objectName, $objectId);
     return $linkedObjects;
 }
Beispiel #5
0
 /**
  * Define the object data preview page URL
  * (needs to be redefined in the child class
  * as per the application structure)
  * @param Db_Object $object
  * @return string
  */
 public function getStagingUrl(Db_Object $object)
 {
     $frontendRouter = new Frontend_Router();
     $stagingUrl = $frontendRouter->findUrl(strtolower($object->getName()));
     if (!strlen($stagingUrl)) {
         return Request::url(array('404'));
     }
     return Request::url(array($stagingUrl, 'item', $object->getId()));
 }
Beispiel #6
0
 /**
  * Clear object links
  * @param Db_Object $object
  */
 public function clearObjectLinks(Db_Object $object)
 {
     $this->_db->delete($this->table(), 'src = ' . $this->_db->quote($object->getName()) . ' AND src_id = ' . intval($object->getId()));
 }
Beispiel #7
0
 /**
  * Check permissions for object
  * @param Db_Object $object - object name
  * @param string $permissionType - permission type
  * @return boolean
  */
 protected function _checkPermission(Db_Object $object, $permissionType)
 {
     return $this->can($permissionType, $object->getName());
 }
Beispiel #8
0
 protected function _getItemCacheKey(Db_Object $object)
 {
     $objectModel = Model::factory($object->getName());
     return $objectModel->getCacheKey(array('item', $object->getId()));
 }
Beispiel #9
0
 /**
  * Delete Db object
  * @param Db_Object $object
  * @param boolean $log - optional, log changes
  * @param boolean $transaction - optional , use transaction if available
  * @return boolean
  */
 public function delete(Db_Object $object, $log = true, $transaction = true)
 {
     if ($object->getConfig()->isReadOnly()) {
         if ($this->_log) {
             $this->_log->log('ORM :: cannot delete readonly object ' . $object->getName());
         }
         return false;
     }
     if (!$object->getId()) {
         return false;
     }
     if ($this->_eventManager) {
         $this->_eventManager->fireEvent(Db_Object_Event_Manager::BEFORE_DELETE, $object);
     }
     $transact = $object->getConfig()->isTransact();
     $db = $this->_getDbConnection($object);
     if ($transact && $transaction) {
         $db->beginTransaction();
     }
     Model::factory($this->_linksObject)->clearObjectLinks($object);
     if ($db->delete($object->getTable(), $db->quoteIdentifier($object->getConfig()->getPrimaryKey()) . ' =' . $object->getId())) {
         /**
          * @todo убрать жесткую связанность
          */
         if ($log && $object->getConfig()->hasHistory()) {
             Model::factory($this->_historyObject)->log(User::getInstance()->id, $object->getId(), Model_Historylog::Delete, $object->getTable());
         }
         $success = true;
     } else {
         $success = false;
     }
     if ($transact && $transaction) {
         if ($success) {
             $db->commit();
         } else {
             $db->rollBack();
         }
     }
     if ($this->_eventManager) {
         $this->_eventManager->fireEvent(Db_Object_Event_Manager::AFTER_DELETE, $object);
     }
     return $success;
 }