Пример #1
0
 public static function render($widget_area)
 {
     $view = Libraries_View::getInstance();
     $page = $view->getSharedData('_SYSTEM_PAGE');
     $page_template = $view->getSharedData('_SYSTEM_PAGE_TEMPLATE');
     $where = array();
     $where[] = array('AND', 'id_page', '=', $page->id);
     $where[] = array('AND', 'area_name', '=', $widget_area);
     $order = array();
     $order[] = array('order_index', 'ASC');
     $widget_instance = new Page_Models_Page_Widget_Instance();
     $widget_instances = $widget_instance->search($where, $order);
     foreach ($widget_instances as $widget_instance) {
         $widget = new Page_Models_Page_Widget();
         $widget->load($widget_instance->id_page_widget);
         $sys_object = new Crud_Models_Object();
         $sys_object->load($widget->id_sys_object);
         $row = new Libraries_Db_Mysql_Model($sys_object->table_name);
         $row->load($widget_instance->id_row);
         $widget_class_name = $widget->class_name;
         /*
         echo '<pre>'; print_r($widget); echo '</pre>';
         echo '<pre>'; print_r($widget_instance); echo '</pre>'; exit;
         */
         echo '<div class="widget" data-widget-id="' . $widget->id . '" data-widget-instance-id="' . $widget_instance->id . '" data-widget-object-id="' . $widget->id_sys_object . '" data-widget-row-id="' . $widget_instance->id_row . '">';
         call_user_func_array(array(new $widget_class_name(), 'render'), array($widget, $widget_instance, $row));
         echo '</div>';
     }
 }
Пример #2
0
 public function reordermanual()
 {
     $object = new Crud_Models_Object();
     $object->load($_POST['object_id']);
     $field = new Crud_Models_Field();
     $field->load($_POST['field_id']);
     $row = new Libraries_Db_Mysql_Model($object->table_name);
     $row->load($_POST['row_id']);
     $where = array();
     $order = array();
     $replacement_row = new Libraries_Db_Mysql_Model($object->table_name);
     $replacement_row->load(intval($_POST['value']), $field->field_name);
     if ($replacement_row->isEmpty()) {
         $sql = "SELECT MIN({$field->field_name}) as min, MAX({$field->field_name}) as max\r\n\t\t\t\t\tFROM {$object->table_name}\r\n\t\t\t\t\tWHERE is_deleted = 0";
         $min_max = Libraries_Db_Factory::getDb()->fetchRow($sql, array(), Libraries_Db_Adapter::FETCH_TYPE_CLASS);
         if ($_POST['value'] < $min_max->min) {
             $replacement_row = $replacement_row->load($min_max->min, $field->field_name);
             $_POST['value'] = $min_max->min;
         }
         if ($_POST['value'] > $min_max->max) {
             $replacement_row = $replacement_row->load($min_max->max, $field->field_name);
             $_POST['value'] = $min_max->max;
         }
         /*
         $response = array();
         $response['error'] = 'Can\'t find this object';
         
         echo json_encode($response);
         return;
         */
     }
     $replacement_row->{$field->field_name} = $row->{$field->field_name};
     $replacement_row->save();
     $row->{$field->field_name} = $_POST['value'];
     $row->save();
     $response = array();
     $response['success'] = 1;
     echo json_encode($response);
     return;
 }
Пример #3
0
<?php

$table_name = $control_properties->table_name;
$conditional_field_id = $control_properties->conditional_field_id;
if (!empty($table_name)) {
    $sys_object = new Crud_Models_Object();
    $sys_object->load($table_name, 'table_name');
    $sys_object->loadFieldsForObject();
} else {
    $sys_field = new Crud_Models_Field();
    $sys_field->load($conditional_field_id);
    $sys_field->loadControl();
    $sys_object = new Crud_Models_Object();
    $sys_object->load($row->{$sys_field->field_name});
    $sys_object->loadFieldsForObject();
}
$text_value = '';
if ($value) {
    $row = new Libraries_Db_Mysql_Model($sys_object->table_name);
    $row->load($value);
    if (!$row->isEmpty()) {
        foreach ($sys_object->sys_field_list as $sys_field) {
            if ($sys_field->is_identification == 1 && array_key_exists($sys_field->field_name, $row->data)) {
                $text_value .= $row->{$sys_field->field_name} . ', ';
            }
        }
    }
}
echo trim($text_value, ', ');
Пример #4
0
 public function save($sys_object_id, $row_id = '')
 {
     $sys_object = new Crud_Models_Object();
     $sys_object->load(intval($sys_object_id));
     $sys_object->loadFieldsForObject();
     if ($sys_object->is_system == 1 && $this->user->role->safe_title != 'administrator') {
         $response = array();
         $response['errors'] = array('Can\'t edit this object');
         echo json_encode($response);
         return;
     }
     if (!$this->user->role->canExecuteAction('can_edit_' . $sys_object->table_name)) {
         $response = array();
         $response['errors'] = array('Can\'t edit this object');
         echo json_encode($response);
         return;
     }
     if ($sys_object->custom_crud_class != '' && new $sys_object->custom_crud_class() instanceof Crud_Interfaces_Crud) {
         echo call_user_func(array(new $sys_object->custom_crud_class(), 'save'), $sys_object_id, $row_id);
     } else {
         $object = new Libraries_Db_Mysql_Model($sys_object->table_name);
         if (!empty($row_id)) {
             $object->load(intval($row_id));
             if (isset($_POST['last_modify']) && $_POST['last_modify'] != $object->last_modify) {
                 $response = array();
                 $response['errors']['general'] = array('Object is already saved by another user!');
                 echo json_encode($response);
                 return;
             }
         }
         $response = array();
         $response['errors'] = array();
         $response['message'] = '';
         foreach ($sys_object->sys_field_list as $field) {
             if ($field->is_hidden == 1) {
                 continue;
             }
             $field->loadValidators();
             $field_value = isset($_POST[$field->field_name]) ? $_POST[$field->field_name] : null;
             if (!empty($field->validators)) {
                 foreach ($field->validators as $validator) {
                     $validator_response = call_user_func(array($validator->class, 'validate'), $field_value);
                     if (!$validator_response) {
                         $response['errors'][] = array('field' => $field->field_name, 'message' => call_user_func(array($validator->class, 'getFalseMessage')));
                         continue 2;
                         // goto next field
                     }
                 }
             }
             $object->{$field->field_name} = $field_value;
         }
         unset($object->data['last_modify']);
         /*
         echo '<pre>'; print_r($_POST); echo '</pre>';
         echo '<pre>'; print_r($object); echo '</pre>'; exit;
         */
         if (empty($response['errors'])) {
             $response['message'] = 'Object is saved';
             Libraries_Event::trigger('beforeCrudSave', $sys_object, $object);
             $object->save();
             $response['id'] = $object->id;
             Libraries_Event::trigger('afterCrudSave', $sys_object, $object);
         }
         echo json_encode($response);
     }
 }