Пример #1
0
 /**
  * Update, delete and add new properties
  *
  * @access public
  * @param void
  * @return null
  */
 function update_properties()
 {
     if (logged_user()->isGuest()) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     $this->setTemplate('add_properties');
     $manager_class = array_var($_GET, 'manager');
     $object_id = get_id('object_id');
     $obj = Objects::findObject($object_id);
     if (!$obj instanceof ContentDataObject) {
         flash_error(lang('object dnx'));
         ajx_current("empty");
         return;
     }
     // if
     if (!logged_user()->getCanManageProperties()) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     // if
     $new_properties = array_var($_POST, 'new_properties');
     $update_properties = array_var($_POST, 'update_properties');
     $delete_properties = array_var($_POST, 'delete_properties');
     if (is_array(array_var($_POST, 'new_properties')) || is_array(array_var($_POST, 'update_properties'))) {
         try {
             DB::beginWork();
             //add new properties
             foreach ($new_properties as $prop) {
                 $property = new ObjectProperty();
                 $property->setFromAttributes($prop);
                 $property->setRelObjectId($object_id);
                 $property->save();
             }
             foreach ($update_properties as $prop) {
                 $property = ObjectProperties::getProperty(array_var($prop, 'id'));
                 //ObjectProperties::getPropertyByName($obj, array_var($prop,'name'));
                 $property->setPropertyValue(array_var($prop, 'value'));
                 $property->save();
             }
             foreach ($delete_properties as $prop) {
                 $property = ObjectProperties::getProperty(array_var($prop, 'id'));
                 //ObjectProperties::getPropertyByName($obj, array_var($prop,'name'));
                 $prop->delete();
             }
             tpl_assign('properties', ObjectProperties::getAllPropertiesByObject($obj));
             ApplicationLogs::createLog($obj, ApplicationLogs::ACTION_EDIT);
             DB::commit();
             flash_success(lang('success add properties'));
             $this->redirectToReferer($obj->getObjectUrl());
         } catch (Exception $e) {
             DB::rollback();
             flash_error($e->getMessage());
             ajx_current("empty");
         }
         //
     }
     // if
 }