当前位置: 首页>>代码示例>>PHP>>正文


PHP DateTimeValueLib::dateFromFormatAndString方法代码示例

本文整理汇总了PHP中DateTimeValueLib::dateFromFormatAndString方法的典型用法代码示例。如果您正苦于以下问题:PHP DateTimeValueLib::dateFromFormatAndString方法的具体用法?PHP DateTimeValueLib::dateFromFormatAndString怎么用?PHP DateTimeValueLib::dateFromFormatAndString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DateTimeValueLib的用法示例。


在下文中一共展示了DateTimeValueLib::dateFromFormatAndString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: format_value_to_print_task

function format_value_to_print_task($value, $type, $textWrapper = '', $dateformat = 'Y-m-d')
{
    switch ($type) {
        case DATA_TYPE_STRING:
            if (preg_match(EMAIL_FORMAT, strip_tags($value))) {
                $formatted = $value;
            } else {
                $formatted = $textWrapper . clean($value) . $textWrapper;
            }
            break;
        case DATA_TYPE_INTEGER:
            $formatted = clean($value);
            break;
        case DATA_TYPE_BOOLEAN:
            $formatted = $value == 1 ? lang('yes') : lang('no');
            break;
        case DATA_TYPE_DATE:
            if ($value != 0) {
                if (str_ends_with($value, "00:00:00")) {
                    $dateformat .= " H:i:s";
                }
                $dtVal = DateTimeValueLib::dateFromFormatAndString($dateformat, $value);
                $formatted = format_date($dtVal, null, 0);
            } else {
                $formatted = '';
            }
            break;
        case DATA_TYPE_DATETIME:
            if ($value != 0) {
                $dtVal = DateTimeValueLib::dateFromFormatAndString("{$dateformat} H:i:s", $value);
                $formatted = format_date($dtVal, null, 0);
            } else {
                $formatted = '';
            }
            break;
        default:
            $formatted = $value;
    }
    if ($formatted == '') {
        $formatted = '--';
    }
    return $formatted;
}
开发者ID:pnagaraju25,项目名称:fengoffice,代码行数:43,代码来源:total_task_times.php

示例2: executeReport


//.........这里部分代码省略.........
                         if ($fiterUsingTag && is_array($tags)) {
                             foreach ($tags as $tag_value) {
                                 $tag_value = trim($tag_value);
                                 if ($tag_value == '') {
                                     continue;
                                 }
                                 $allConditions .= ' AND t.id ' . ($tagCondition == '=' ? 'IN' : 'NOT IN') . ' (SELECT rel_object_id FROM ' . TABLE_PREFIX . 'tags WHERE rel_object_manager = \'' . $manager . '\' AND tag = \'' . $tag_value . '\')';
                             }
                         }
                     }
                 } else {
                     $skip_condition = false;
                     $model = $report->getObjectType();
                     $model_instance = new $model();
                     $col_type = $model_instance->getColumnType($condField->getFieldName());
                     $allConditions .= ' AND ';
                     $dateFormat = 'm/d/Y';
                     if (isset($params[$condField->getId()])) {
                         $value = $params[$condField->getId()];
                         if ($col_type == DATA_TYPE_DATE || $col_type == DATA_TYPE_DATETIME) {
                             $dateFormat = user_config_option('date_format');
                         }
                     } else {
                         $value = $condField->getValue();
                     }
                     if ($value == '' && $condField->getIsParametrizable()) {
                         $skip_condition = true;
                     }
                     if (!$skip_condition) {
                         if ($condField->getCondition() == 'like' || $condField->getCondition() == 'not like') {
                             $value = '%' . $value . '%';
                         }
                         if ($col_type == DATA_TYPE_DATE || $col_type == DATA_TYPE_DATETIME) {
                             $dtValue = DateTimeValueLib::dateFromFormatAndString($dateFormat, $value);
                             $value = $dtValue->format('Y-m-d');
                         }
                         if ($condField->getCondition() != '%') {
                             if ($col_type == DATA_TYPE_INTEGER || $col_type == DATA_TYPE_FLOAT) {
                                 $allConditions .= '`' . $condField->getFieldName() . '` ' . $condField->getCondition() . ' ' . mysql_real_escape_string($value);
                             } else {
                                 if ($condField->getCondition() == '=' || $condField->getCondition() == '<=' || $condField->getCondition() == '>=') {
                                     $equal = 'datediff(\'' . mysql_real_escape_string($value) . '\', `' . $condField->getFieldName() . '`)=0';
                                     switch ($condField->getCondition()) {
                                         case '=':
                                             $allConditions .= $equal;
                                             break;
                                         case '<=':
                                         case '>=':
                                             $allConditions .= '(`' . $condField->getFieldName() . '` ' . $condField->getCondition() . ' \'' . mysql_real_escape_string($value) . '\'' . ' OR ' . $equal . ') ';
                                             break;
                                     }
                                 } else {
                                     $allConditions .= '`' . $condField->getFieldName() . '` ' . $condField->getCondition() . ' \'' . mysql_real_escape_string($value) . '\'';
                                 }
                             }
                         } else {
                             $allConditions .= '`' . $condField->getFieldName() . '` like "%' . mysql_real_escape_string($value) . '"';
                         }
                     } else {
                         $allConditions .= ' true';
                     }
                 }
                 //else
             }
             //foreach
         }
开发者ID:pnagaraju25,项目名称:fengoffice,代码行数:67,代码来源:Reports.class.php

示例3: get_member_custom_property_value_for_listing

function get_member_custom_property_value_for_listing($cp, $member_id, $cp_vals = null)
{
    if (is_null($cp_vals)) {
        $cp_vals = MemberCustomPropertyValues::getMemberCustomPropertyValues($member_id, $cp->getId());
    }
    $val_to_show = "";
    foreach ($cp_vals as $cp_val) {
        if (in_array($cp->getType(), array('contact', 'user')) && $cp_val instanceof MemberCustomPropertyValue) {
            $cp_contact = Contacts::findById($cp_val->getValue());
            if ($cp_contact instanceof Contact) {
                $cp_val->setValue($cp_contact->getObjectName());
            } else {
                $cp_val->setValue("");
            }
        }
        if ($cp->getType() == 'date' && $cp_val instanceof MemberCustomPropertyValue) {
            $format = user_config_option('date_format');
            Hook::fire("custom_property_date_format", null, $format);
            $tmp_date = DateTimeValueLib::dateFromFormatAndString(DATE_MYSQL, $cp_val->getValue());
            if (str_starts_with($cp_val->getValue(), EMPTY_DATE)) {
                $formatted = "";
            } else {
                if (str_ends_with($cp_val->getValue(), "00:00:00")) {
                    $formatted = $tmp_date->format(user_config_option('date_format'));
                } else {
                    $formatted = $tmp_date->format($format);
                }
            }
            $cp_val->setValue($formatted);
        }
        if ($cp->getType() == 'address' && $cp_val instanceof MemberCustomPropertyValue) {
            $values = str_replace("\\|", "%%_PIPE_%%", $cp_val->getValue());
            $exploded = explode("|", $values);
            foreach ($exploded as &$v) {
                $v = str_replace("%%_PIPE_%%", "|", $v);
                $v = str_replace("'", "\\'", $v);
            }
            if (count($exploded) > 0) {
                $address_type = array_var($exploded, 0, '');
                $street = array_var($exploded, 1, '');
                $city = array_var($exploded, 2, '');
                $state = array_var($exploded, 3, '');
                $country = array_var($exploded, 4, '');
                $zip_code = array_var($exploded, 5, '');
                $country_name = CountryCodes::getCountryNameByCode($country);
                $tmp = array();
                if ($street != '') {
                    $tmp[] = $street;
                }
                if ($city != '') {
                    $tmp[] = $city;
                }
                if ($state != '') {
                    $tmp[] = $state;
                }
                if ($zip_code != '') {
                    $tmp[] = $zip_code;
                }
                if ($country_name != '') {
                    $tmp[] = $country_name;
                }
                $cp_val->setValue(implode(' - ', $tmp));
            }
        }
        $val_to_show .= ($val_to_show == "" ? "" : ", ") . ($cp_val instanceof MemberCustomPropertyValue ? $cp_val->getValue() : "");
    }
    $val_to_show = html_to_text($val_to_show);
    return $val_to_show;
}
开发者ID:abhinay100,项目名称:feng_app,代码行数:69,代码来源:format.php

示例4: getDateValue

/**
 * Returns a DateTimeValue from a date representation from pick_date_widget2
 *
 * @param string $value
 * @param DateTimeValue $default
 * @return DateTimeValue
 */
function getDateValue($value = '', $default = EMPTY_DATETIME)
{
    if ($value instanceof DateTimeValue) {
        return $value;
    }
    if ($value != '') {
        $date_format = user_config_option('date_format');
        return DateTimeValueLib::dateFromFormatAndString($date_format, $value);
    }
    return $default;
}
开发者ID:pnagaraju25,项目名称:fengoffice,代码行数:18,代码来源:general.php

示例5: add_custom_properties

 /**
  * Adds the custom properties of an object into the database.
  * 
  * @param $object
  * @return unknown_type
  */
 function add_custom_properties($object)
 {
     if (logged_user()->isGuest()) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     $obj_custom_properties = array_var($_POST, 'object_custom_properties');
     $customProps = CustomProperties::getAllCustomPropertiesByObjectType($object->getObjectTypeId());
     //Sets all boolean custom properties to 0. If any boolean properties are returned, they are subsequently set to 1.
     foreach ($customProps as $cp) {
         if ($cp->getType() == 'boolean') {
             $custom_property_value = CustomPropertyValues::getCustomPropertyValue($object->getId(), $cp->getId());
             if (!$custom_property_value instanceof CustomPropertyValue) {
                 $custom_property_value = new CustomPropertyValue();
             }
             $custom_property_value->setObjectId($object->getId());
             $custom_property_value->setCustomPropertyId($cp->getId());
             $custom_property_value->setValue(0);
             $custom_property_value->save();
         }
     }
     if (is_array($obj_custom_properties)) {
         foreach ($obj_custom_properties as $id => $value) {
             //Get the custom property
             $custom_property = null;
             foreach ($customProps as $cp) {
                 if ($cp->getId() == $id) {
                     $custom_property = $cp;
                     break;
                 }
             }
             if ($custom_property instanceof CustomProperty) {
                 // save dates in standard format "Y-m-d H:i:s", because the column type is string
                 if ($custom_property->getType() == 'date') {
                     if (is_array($value)) {
                         $newValues = array();
                         foreach ($value as $val) {
                             $dtv = DateTimeValueLib::dateFromFormatAndString(user_config_option('date_format'), $val);
                             $newValues[] = $dtv->format("Y-m-d H:i:s");
                         }
                         $value = $newValues;
                     } else {
                         $dtv = DateTimeValueLib::dateFromFormatAndString(user_config_option('date_format'), $value);
                         $value = $dtv->format("Y-m-d H:i:s");
                     }
                 }
                 //Save multiple values
                 if (is_array($value)) {
                     CustomPropertyValues::deleteCustomPropertyValues($object->getId(), $id);
                     foreach ($value as &$val) {
                         if (is_array($val)) {
                             // CP type == table
                             $str_val = '';
                             foreach ($val as $col_val) {
                                 $col_val = str_replace("|", "\\|", $col_val);
                                 $str_val .= ($str_val == '' ? '' : '|') . $col_val;
                             }
                             $val = $str_val;
                         }
                         if ($val != '') {
                             if (strpos($val, ',')) {
                                 $val = str_replace(',', '|', $val);
                             }
                             $custom_property_value = new CustomPropertyValue();
                             $custom_property_value->setObjectId($object->getId());
                             $custom_property_value->setCustomPropertyId($id);
                             $custom_property_value->setValue($val);
                             $custom_property_value->save();
                         }
                     }
                 } else {
                     if ($custom_property->getType() == 'boolean') {
                         $value = isset($value);
                     }
                     $cpv = CustomPropertyValues::getCustomPropertyValue($object->getId(), $id);
                     if ($cpv instanceof CustomPropertyValue) {
                         $custom_property_value = $cpv;
                     } else {
                         $custom_property_value = new CustomPropertyValue();
                     }
                     $custom_property_value->setObjectId($object->getId());
                     $custom_property_value->setCustomPropertyId($id);
                     $custom_property_value->setValue($value);
                     $custom_property_value->save();
                 }
                 //Add to searchable objects
                 if ($object->isSearchable() && ($custom_property->getType() == 'text' || $custom_property->getType() == 'list' || $custom_property->getType() == 'numeric')) {
                     $name = $custom_property->getName();
                     $searchable_object = SearchableObjects::findOne(array("conditions" => "`rel_object_id` = " . $object->getId() . " AND `column_name` = '{$name}'"));
                     if (!$searchable_object) {
                         $searchable_object = new SearchableObject();
                     }
                     if (is_array($value)) {
//.........这里部分代码省略.........
开发者ID:rorteg,项目名称:fengoffice,代码行数:101,代码来源:ObjectController.class.php

示例6: get_tasks_request_conditions

 private function get_tasks_request_conditions()
 {
     // get query parameters, save user preferences if necessary
     $status = array_var($_REQUEST, 'status', null);
     if (is_null($status) || $status == '') {
         $status = user_config_option('task panel status', 2);
     } else {
         if (user_config_option('task panel status') != $status) {
             set_user_config_option('task panel status', $status, logged_user()->getId());
         }
     }
     $previous_filter = user_config_option('task panel filter', 'no_filter');
     $filter_from_date = getDateValue(array_var($_REQUEST, 'from_date'));
     if ($filter_from_date instanceof DateTimeValue) {
         $copFromDate = $filter_from_date;
         $filter_from_date = $filter_from_date->toMySQL();
     }
     $tasks_from_date = '';
     $filter_to_date = getDateValue(array_var($_REQUEST, 'to_date'));
     if ($filter_to_date instanceof DateTimeValue) {
         $copToDate = $filter_to_date;
         $filter_to_date = $filter_to_date->toMySQL();
     }
     $tasks_to_date = '';
     if (user_config_option('tasksDateStart') != $filter_from_date) {
         if ($filter_from_date != '0000-00-00 00:00:00' || array_var($_REQUEST, 'resetDateStart')) {
             set_user_config_option('tasksDateStart', $copFromDate, logged_user()->getId());
         } else {
             $filter_from_date = user_config_option('tasksDateStart');
         }
     }
     if (user_config_option('tasksDateEnd') != $filter_to_date) {
         if ($filter_to_date != '0000-00-00 00:00:00' || array_var($_REQUEST, 'resetDateEnd')) {
             set_user_config_option('tasksDateEnd', $copToDate, logged_user()->getId());
         } else {
             $filter_to_date = user_config_option('tasksDateEnd');
         }
     }
     if ($filter_from_date != '0000-00-00 00:00:00' || $filter_to_date != '0000-00-00 00:00:00') {
         if ($filter_from_date != '0000-00-00 00:00:00') {
             $dateFrom = DateTimeValueLib::dateFromFormatAndString(DATE_MYSQL, $filter_from_date);
             $dateFrom->advance(logged_user()->getTimezone() * -3600);
             $dateFrom = $dateFrom->toMySQL();
         }
         if ($filter_to_date != '0000-00-00 00:00:00') {
             $dateTo = DateTimeValueLib::dateFromFormatAndString(DATE_MYSQL, $filter_to_date);
             $dateTo->setHour(23);
             $dateTo->setMinute(59);
             $dateTo->setSecond(59);
             $dateTo->advance(logged_user()->getTimezone() * -3600);
             $dateTo = $dateTo->toMySQL();
         }
         if ($filter_from_date != '0000-00-00 00:00:00' && $filter_to_date != '0000-00-00 00:00:00') {
             $tasks_from_date = " AND (((`start_date` BETWEEN '" . $dateFrom . "' AND '" . $dateTo . "') AND `start_date` != " . DB::escape(EMPTY_DATETIME) . ") OR ((`due_date` BETWEEN '" . $dateFrom . "' AND '" . $dateTo . "') AND `due_date` != " . DB::escape(EMPTY_DATETIME) . "))";
         } elseif ($filter_from_date != '0000-00-00 00:00:00') {
             $tasks_from_date = " AND (`start_date` > '" . $dateFrom . "' OR `due_date` > '" . $dateFrom . "') ";
         } else {
             $tasks_from_date = "AND ((`start_date` < '" . $dateTo . "' AND `start_date` != " . DB::escape(EMPTY_DATETIME) . ") OR (`due_date` < '" . $dateTo . "' AND `due_date` != " . DB::escape(EMPTY_DATETIME) . "))";
         }
     } else {
         $tasks_from_date = "";
     }
     $filter = array_var($_REQUEST, 'filter');
     if (is_null($filter) || $filter == '') {
         $filter = $previous_filter;
     } else {
         if ($previous_filter != $filter) {
             set_user_config_option('task panel filter', $filter, logged_user()->getId());
         }
     }
     if ($filter != 'no_filter') {
         $filter_value = array_var($_REQUEST, 'fval');
         if (is_null($filter_value) || $filter_value == '') {
             $filter_value = user_config_option('task panel filter value', null, logged_user()->getId());
             set_user_config_option('task panel filter value', $filter_value, logged_user()->getId());
             $filter = $previous_filter;
             set_user_config_option('task panel filter', $filter, logged_user()->getId());
         } else {
             if (user_config_option('task panel filter value') != $filter_value) {
                 set_user_config_option('task panel filter value', $filter_value, logged_user()->getId());
             }
         }
     }
     /*	$isJson = array_var($_GET,'isJson',false);
     		if ($isJson) ajx_current("empty");
     		*/
     $template_condition = "`e`.`is_template` = 0 ";
     //Get the task query conditions
     $task_filter_condition = "";
     switch ($filter) {
         case 'assigned_to':
             $assigned_to = $filter_value;
             if ($assigned_to > 0) {
                 $task_filter_condition = " AND (`assigned_to_contact_id` = " . $assigned_to . ") ";
             } else {
                 if ($assigned_to == -1) {
                     $task_filter_condition = " AND `assigned_to_contact_id` = 0";
                 }
             }
             break;
//.........这里部分代码省略.........
开发者ID:abhinay100,项目名称:feng_app,代码行数:101,代码来源:TaskController.class.php

示例7: save_object

 private function save_object($request)
 {
     $response = false;
     if (!empty($request['args'])) {
         $service = $request['srv'];
         switch ($service) {
             case "task":
                 if ($request['args']['id']) {
                     $object = ProjectTasks::instance()->findByid($request['args']['id']);
                 } else {
                     $object = new ProjectTask();
                 }
                 if ($object instanceof ProjectTask) {
                     if (!empty($request['args']['title'])) {
                         $object->setObjectName($request['args']['title']);
                     }
                     if (!empty($request['args']['description'])) {
                         $object->setText($request['args']['description']);
                     }
                     if (!empty($request['args']['due_date'])) {
                         if ($request['args']['due_date'] != '' && $request['args']['due_date'] != date_format_tip('dd/mm/yyyy')) {
                             $date_format = 'dd/mm/yyyy';
                             $object->setDueDate(DateTimeValueLib::dateFromFormatAndString($date_format, $value));
                         }
                     }
                     if (!empty($request['args']['completed'])) {
                         $object->setPercentCompleted($request['args']['completed']);
                     }
                     if (!empty($request['args']['assign_to'])) {
                         $object->setAssignedToContactId($request['args']['assign_to']);
                     }
                     if (!empty($request['args']['priority'])) {
                         $object->setPriority($request['args']['priority']);
                     }
                 }
                 break;
             case 'note':
                 if ($request['args']['id']) {
                     $object = ProjectMessages::instance()->findByid($request['args']['id']);
                 } else {
                     $object = new ProjectMessage();
                 }
                 if ($object instanceof ProjectMessage) {
                     if (!empty($request['args']['title'])) {
                         $object->setObjectName($request['args']['title']);
                     }
                     if (!empty($request['args']['title'])) {
                         $object->setText($request['args']['text']);
                     }
                 }
                 break;
         }
         // END SWITCH
         if ($object) {
             try {
                 $context = array();
                 $members = array();
                 if (!empty($request['args']['members'])) {
                     $members = $request['args']['members'];
                     $context = get_context_from_array($members);
                 }
                 //Check permissions:
                 if ($request['args']['id'] && $object->canEdit(logged_user()) || !$request['args']['id'] && $object->canAdd(logged_user(), $context)) {
                     DB::beginWork();
                     $object->save();
                     $object_controller = new ObjectController();
                     if (!$request['args']['id']) {
                         $object_controller->add_to_members($object, $members);
                     }
                     DB::commit();
                     $response = true;
                 }
             } catch (Exception $e) {
                 DB::rollback();
                 return false;
             }
         }
     }
     return $this->response('json', $response);
 }
开发者ID:abhinay100,项目名称:feng_app,代码行数:80,代码来源:ApiController.class.php

示例8: instantiate

 function instantiate()
 {
     $id = get_id();
     $template = COTemplates::findById($id);
     if (!$template instanceof COTemplate) {
         flash_error(lang("template dnx"));
         ajx_current("empty");
         return;
     }
     $parameters = TemplateParameters::getParametersByTemplate($id);
     $parameterValues = array_var($_POST, 'parameterValues');
     if (count($parameters) > 0 && !isset($parameterValues)) {
         ajx_current("back");
         return;
     }
     $objects = $template->getObjects();
     foreach ($objects as $object) {
         if (!$object instanceof ProjectDataObject) {
             continue;
         }
         // copy object
         $copy = $object->copy();
         if ($copy->columnExists('is_template')) {
             $copy->setColumnValue('is_template', false);
         }
         if ($copy instanceof ProjectTask) {
             // don't copy parent task and milestone
             $copy->setMilestoneId(0);
             $copy->setParentId(0);
         }
         $copy->save();
         $wsId = array_var($_POST, 'project_id', active_or_personal_project()->getId());
         // if specified, set workspace
         $workspace = Projects::findById($wsId);
         if (!$workspace instanceof Project) {
             $workspace = active_or_personal_project();
         }
         $copy->addToWorkspace($workspace);
         // add object tags and specified tags
         $tags = implode(',', $object->getTagNames());
         $copy->setTagsFromCSV($tags . "," . array_var($_POST, 'tags'));
         // copy linked objects
         $copy->copyLinkedObjectsFrom($object);
         // copy subtasks if applicable
         if ($copy instanceof ProjectTask) {
             ProjectTasks::copySubTasks($object, $copy, false);
             $manager = new ProjectTask();
         } else {
             if ($copy instanceof ProjectMilestone) {
                 ProjectMilestones::copyTasks($object, $copy, false);
                 $manager = new ProjectMilestone();
             }
         }
         // copy custom properties
         $copy->copyCustomPropertiesFrom($object);
         // set property values as defined in template
         $objProp = TemplateObjectProperties::getPropertiesByTemplateObject($id, $object->getId());
         foreach ($objProp as $property) {
             $propName = $property->getProperty();
             $value = $property->getValue();
             if ($manager->getColumnType($propName) == DATA_TYPE_STRING) {
                 if (is_array($parameterValues)) {
                     foreach ($parameterValues as $param => $val) {
                         $value = str_replace('{' . $param . '}', $val, $value);
                     }
                 }
             } else {
                 if ($manager->getColumnType($propName) == DATA_TYPE_DATE || $manager->getColumnType($propName) == DATA_TYPE_DATETIME) {
                     $operator = '+';
                     if (strpos($value, '+') === false) {
                         $operator = '-';
                     }
                     $opPos = strpos($value, $operator);
                     if ($opPos !== false) {
                         $dateParam = substr($value, 1, strpos($value, '}') - 1);
                         $dateUnit = substr($value, strlen($value) - 1);
                         // d, w or m (for days, weeks or months)
                         if ($dateUnit == 'm') {
                             $dateUnit = 'M';
                             // make month unit uppercase to call DateTimeValue::add with correct parameter
                         }
                         $dateNum = (int) substr($value, strpos($value, $operator), strlen($value) - 2);
                         $date = $parameterValues[$dateParam];
                         $date = DateTimeValueLib::dateFromFormatAndString(user_config_option('date_format'), $date);
                         $value = $date->add($dateUnit, $dateNum);
                     }
                 } else {
                     if ($manager->getColumnType($propName) == DATA_TYPE_INTEGER) {
                         if (is_array($parameterValues)) {
                             foreach ($parameterValues as $param => $val) {
                                 $value = str_replace('{' . $param . '}', $val, $value);
                             }
                         }
                     }
                 }
             }
             if ($value != '') {
                 $copy->setColumnValue($propName, $value);
                 $copy->save();
             }
//.........这里部分代码省略.........
开发者ID:pnagaraju25,项目名称:fengoffice,代码行数:101,代码来源:TemplateController.class.php

示例9: import_google_calendar_for_user

 function import_google_calendar_for_user($user)
 {
     if ($user instanceof ExternalCalendarUser) {
         $calendars = ExternalCalendars::findByExtCalUserId($user->getId());
         $service = $this->connect_with_google_calendar($user);
         $contact = Contacts::findById($user->getContactId());
         try {
             //update or insert events for calendars
             foreach ($calendars as $calendar) {
                 if ($calendar->getSync() == 0) {
                     continue;
                 }
                 $optParams = array();
                 $syncToken = $calendar->getExternalCalendarPropertyValue("syncToken");
                 //if syncToken is not present we have to make a full sync
                 if ($syncToken) {
                     //incremental sync get events created or updated from las check
                     $optParams['syncToken'] = $syncToken;
                 } else {
                     //full sync get events starting from past 2 weeks
                     $previous_week = strtotime("-2 week");
                     $time_min = date(DATE_RFC3339, $previous_week);
                     $optParams['timeMin'] = $time_min;
                 }
                 //Try to get events for this calendar
                 try {
                     $events = $service->events->listEvents($calendar->getOriginalCalendarId(), $optParams);
                 } catch (Exception $e) {
                     Logger::log("Fail to get events from external calendar: " . $calendar->getId());
                     Logger::log($e->getMessage());
                     //remove the syncToken for this calendar so the next time we do a full sync
                     $syncTokenProp = $calendar->getExternalCalendarProperty("syncToken");
                     if ($syncTokenProp) {
                         $syncTokenProp->delete();
                     }
                     //go to the next calendar
                     continue;
                 }
                 //Working with events
                 while (true) {
                     foreach ($events->getItems() as $event) {
                         //check if is a cancelled event
                         if ($event->getStatus() == "cancelled") {
                             $cancelled_event = ProjectEvents::findBySpecialId($event->getId(), $calendar->getId());
                             //delete ProjectEvent
                             if ($cancelled_event instanceof ProjectEvent) {
                                 $cancelled_event->delete();
                             }
                             continue;
                         }
                         //check if is a recurrent event
                         if (is_array($event->getRecurrence())) {
                             continue;
                         }
                         //check if is a recurrent event instance
                         if (!is_null($event->getRecurringEventId()) && $event->getRecurringEventId() != '') {
                             continue;
                         }
                         //get all the data that we need from google event
                         $event_id = $event->getId();
                         $event_name = $event->getSummary();
                         $event_desc = $event->getDescription();
                         $event_start_date = ExternalCalendarController::date_google_to_sql($event->getStart());
                         $event_end_date = ExternalCalendarController::date_google_to_sql($event->getEnd());
                         $event_type = 1;
                         if ($event->getStart()->getDate()) {
                             $event_type = 2;
                             //set this times because we have a bug with all day events times
                             $event_start_date = DateTimeValueLib::dateFromFormatAndString(DATE_MYSQL, $event_start_date);
                             $event_start_date->advance(12 * 3600);
                             $event_start_date = $event_start_date->toMySQL();
                             $event_end_date = DateTimeValueLib::dateFromFormatAndString(DATE_MYSQL, $event_start_date);
                             $event_end_date->advance(1 * 3600);
                             $event_end_date = $event_end_date->toMySQL();
                         }
                         $event_updated_date = EMPTY_DATETIME;
                         if (!is_null($event->getUpdated()) && $event->getUpdated() != '') {
                             $event_updated_date_str = strtotime($event->getUpdated());
                             $event_updated_date = date(DATE_MYSQL, $event_updated_date_str);
                         }
                         //Save event
                         try {
                             DB::beginWork();
                             //if event exist update it
                             $new_event = ProjectEvents::findBySpecialId($event_id, $calendar->getId());
                             if (!$new_event instanceof ProjectEvent) {
                                 //Create ProjectEvent from google event
                                 $new_event = new ProjectEvent();
                             }
                             $new_event->setSpecialID($event_id);
                             $new_event->setStart($event_start_date);
                             $new_event->setDuration($event_end_date);
                             $new_event->setTypeId($event_type);
                             $new_event->setObjectName($event_name);
                             $new_event->setDescription($event_desc);
                             $new_event->setUpdateSync($event_updated_date);
                             $new_event->setExtCalId($calendar->getId());
                             $new_event->save();
                             //Invitation insert only if not exists
                             $conditions = array('event_id' => $new_event->getId(), 'contact_id' => $user->getContactId());
//.........这里部分代码省略.........
开发者ID:abhinay100,项目名称:feng_app,代码行数:101,代码来源:ExternalCalendarController.class.php

示例10: lang

	<table>
		<tr style='height:30px;'>
			<td><span class="bold"><?php 
echo lang("date");
?>
:&nbsp;</span></td>
			<td align='left'><?php 
echo select_box('report[date_type]', array(option_tag(lang('today'), 1, array_var($report_data, "date_type") == 1 ? array('selected' => 'selected') : null), option_tag(lang('this week'), 2, array_var($report_data, "date_type") == 2 ? array('selected' => 'selected') : null), option_tag(lang('last week'), 3, array_var($report_data, "date_type") == 3 ? array('selected' => 'selected') : null), option_tag(lang('this month'), 4, array_var($report_data, "date_type") == 4 ? array('selected' => 'selected') : null), option_tag(lang('last month'), 5, array_var($report_data, "date_type") == 5 ? array('selected' => 'selected') : null), option_tag(lang('select dates...'), 6, array_var($report_data, "date_type") == 6 ? array('selected' => 'selected') : null)), array('onchange' => 'og.dateselectchange(this)'));
?>
</td>
		</tr>
		<?php 
if (array_var($report_data, "date_type") == 6) {
    $style = "";
    $st = DateTimeValueLib::dateFromFormatAndString(DATE_MYSQL, array_var($report_data, 'start_value'));
    $et = DateTimeValueLib::dateFromFormatAndString(DATE_MYSQL, array_var($report_data, 'end_value'));
} else {
    $style = 'display:none;';
    $st = DateTimeValueLib::now();
    $et = $st;
}
?>
		<tr class="dateTr"  style="<?php 
echo $style;
?>
">
			<td><span class="bold"><?php 
echo lang("start date");
?>
:&nbsp;</span></td>
			<td align='left'><?php 
开发者ID:abhinay100,项目名称:feng_app,代码行数:31,代码来源:total_task_times_p.php

示例11: add_custom_properties

 /**
  * Adds the custom properties of an object into the database.
  * 
  * @param $object
  * @return unknown_type
  */
 function add_custom_properties($object)
 {
     if (logged_user()->isGuest()) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     $obj_custom_properties = array_var($_POST, 'object_custom_properties');
     if (is_array($obj_custom_properties)) {
         foreach ($obj_custom_properties as $id => &$val) {
             $val = remove_scripts($val);
         }
     }
     $date_format = user_config_option('date_format');
     $date_format_tip = date_format_tip($date_format);
     $required_custom_props = array();
     $object_type_id = $object instanceof TemplateTask ? ProjectTasks::instance()->getObjectTypeId() : $object->getObjectTypeId();
     $customProps = CustomProperties::getAllCustomPropertiesByObjectType($object_type_id);
     //Sets all boolean custom properties to 0. If any boolean properties are returned, they are subsequently set to 1.
     foreach ($customProps as $cp) {
         if ($cp->getType() == 'boolean') {
             $custom_property_value = CustomPropertyValues::getCustomPropertyValue($object->getId(), $cp->getId());
             if (!$custom_property_value instanceof CustomPropertyValue) {
                 $custom_property_value = new CustomPropertyValue();
             }
             $custom_property_value->setObjectId($object->getId());
             $custom_property_value->setCustomPropertyId($cp->getId());
             $custom_property_value->setValue(0);
             $custom_property_value->save();
         }
         if ($cp->getIsRequired()) {
             $required_custom_props[] = $cp;
         }
     }
     foreach ($required_custom_props as $req_cp) {
         if (!isset($obj_custom_properties[$req_cp->getId()])) {
             throw new Exception(lang('custom property value required', $req_cp->getName()));
         }
     }
     if (is_array($obj_custom_properties)) {
         // check required custom properties
         foreach ($obj_custom_properties as $id => $value) {
             //Get the custom property
             $custom_property = null;
             foreach ($customProps as $cp) {
                 if ($cp->getId() == $id) {
                     $custom_property = $cp;
                     break;
                 }
             }
             if ($custom_property instanceof CustomProperty) {
                 // save dates in standard format "Y-m-d H:i:s", because the column type is string
                 if ($custom_property->getType() == 'date') {
                     if (is_array($value)) {
                         $newValues = array();
                         foreach ($value as $val) {
                             if (trim($val) != '' && trim($val) != $date_format_tip) {
                                 $dtv = DateTimeValueLib::dateFromFormatAndString($date_format, $val);
                                 $newValues[] = $dtv->format("Y-m-d H:i:s");
                             }
                         }
                         $value = $newValues;
                     } else {
                         if (trim($value) != '' && trim($val) != $date_format_tip) {
                             $dtv = DateTimeValueLib::dateFromFormatAndString($date_format, $value);
                             $value = $dtv->format("Y-m-d H:i:s");
                         } else {
                             $value = '';
                         }
                     }
                 }
                 foreach (array_var($_REQUEST, 'remove_custom_properties', array()) as $cpropid => $remove) {
                     if ($remove) {
                         CustomPropertyValues::deleteCustomPropertyValues($object->getId(), $cpropid);
                     }
                 }
                 Hook::fire('before_save_custom_property_value', array('custom_prop' => $custom_property), $value);
                 if (is_array($value)) {
                     if ($custom_property->getType() == 'address') {
                         if ($custom_property->getIsRequired()) {
                             if (array_var($value, 'street') == '' && array_var($value, 'city') == '' && array_var($value, 'state') == '' && array_var($value, 'country') == '' && array_var($value, 'zip_code') == '') {
                                 throw new Exception(lang('custom property value required', $custom_property->getName()));
                             }
                             $errors = array(lang('error form validation'));
                             Env::useHelper('form');
                             $ok = checkAddressInputMandatoryFields($value, $custom_property->getName(), $errors);
                             if (!$ok) {
                                 throw new Exception(implode("\n - ", $errors));
                             }
                         }
                         // Address custom property
                         $val = array_var($value, 'type') . '|' . array_var($value, 'street') . '|' . array_var($value, 'city') . '|' . array_var($value, 'state') . '|' . array_var($value, 'country') . '|' . array_var($value, 'zip_code');
                         CustomPropertyValues::deleteCustomPropertyValues($object->getId(), $id);
                         $custom_property_value = new CustomPropertyValue();
//.........这里部分代码省略.........
开发者ID:abhinay100,项目名称:feng_app,代码行数:101,代码来源:ObjectController.class.php

示例12: search

 /**
  * Execute search
  * TODO: Performance gus: 
  * Fetch only ids and execute a select statement by pk (fer each result)
  * @param void
  * @return null
  */
 function search()
 {
     // Init vars
     $search_for = array_var($_GET, 'search_for');
     $search_dimension = array_var($_GET, 'search_dimension');
     $advanced = array_var($_GET, 'advanced');
     $minWordLength = $this->minWordLength($search_for);
     $useLike = $minWordLength && $this->ignoreMinWordLength && $minWordLength < self::$MYSQL_MIN_WORD_LENGHT;
     $search_pieces = explode(" ", $search_for);
     $search_string = "";
     if (!$useLike) {
         // Prepare MATCH AGAINST string
         foreach ($search_pieces as $word) {
             if ((strpos($word, "@") || strpos($word, ".") || strpos($word, ",")) === false) {
                 // STRING Dont containt special characheters that mysql use as separator. Noramal  flow
                 if ($this->wildCardSearch) {
                     $word .= "*";
                 }
             } else {
                 $word = str_replace($this->mysqlWordSeparator, " +", $word);
             }
             if (!str_starts_with($word, " ")) {
                 $word = " +" . $word;
             }
             $search_string .= mysql_escape_string($word) . " ";
         }
         $search_string = substr($search_string, 0, -1);
     } else {
         // USE Like Query
         $search_string = mysql_escape_string($search_for);
     }
     $this->search_for = $search_for;
     $limit = $this->limit;
     $start = array_var($_REQUEST, 'start', $this->start);
     $this->start = $start;
     $limitTest = max($this->limitTest, $this->limit);
     $filteredResults = 0;
     $uid = logged_user()->getId();
     if (!isset($search_dimension)) {
         $members = active_context_members(false);
     } else {
         if ($search_dimension == 0) {
             $members = array();
         } else {
             $members = array($search_dimension);
         }
     }
     $members_sql = "";
     if (count($members) > 0) {
         $members_sql = "AND rel_object_id IN (SELECT object_id FROM " . TABLE_PREFIX . "object_members om WHERE member_id IN (" . implode(',', $members) . ")  \n                                    GROUP BY object_id\n                                    HAVING count(member_id) = " . count($members) . ")";
         $this->search_dimension = implode(',', $members);
     } else {
         $this->search_dimension = 0;
     }
     $revisionObjectTypeId = ObjectTypes::findByName("file revision")->getId();
     $listableObjectTypeIds = implode(",", ObjectTypes::getListableObjectTypeIds());
     if ($_POST) {
         $conditions = array_var($_POST, 'conditions');
         $search = array_var($_POST, 'search');
         $type_object = array_var($search, 'search_object_type_id');
         if (!is_array($conditions)) {
             $conditions = array();
         }
         $where_condiition = '';
         $conditions_view = array();
         $cont = 0;
         foreach ($conditions as $condition) {
             $condValue = array_key_exists('value', $condition) ? $condition['value'] : '';
             if ($condition['field_type'] == 'boolean') {
                 $value = array_key_exists('value', $condition);
             } else {
                 if ($condition['field_type'] == 'date') {
                     if ($condValue != '') {
                         $dtFromWidget = DateTimeValueLib::dateFromFormatAndString(user_config_option('date_format'), $condValue);
                         $value = date("m/d/Y", $dtFromWidget->getTimestamp());
                     }
                 } else {
                     $value = $condValue;
                 }
             }
             if ($condition['condition'] == "like") {
                 $where_condiition .= " AND " . $condition['field_name'] . " " . $condition['condition'] . " '" . $value . "%' ";
             } else {
                 $where_condiition .= " AND " . $condition['field_name'] . " " . $condition['condition'] . " '" . $value . "' ";
             }
             $conditions_view[$cont]['id'] = $condition['id'];
             $conditions_view[$cont]['custom_property_id'] = $condition['custom_property_id'];
             $conditions_view[$cont]['field_name'] = $condition['field_name'];
             $conditions_view[$cont]['condition'] = $condition['condition'];
             $conditions_view[$cont]['value'] = $value;
             $cont++;
         }
         tpl_assign('conditions', $conditions_view);
//.........这里部分代码省略.........
开发者ID:rorteg,项目名称:fengoffice,代码行数:101,代码来源:SearchController.class.php

示例13: getTaskTimeslots

 /**
  * Returns timeslots based on the set query parameters
  *
  * @param User $user
  * @param string $workspacesCSV
  * @param DateTimeValue $start_date
  * @param DateTimeValue $end_date
  * @param string $object_manager
  * @param string $object_id
  * @param array $group_by
  * @param array $order_by
  * @return array
  */
 static function getTaskTimeslots($workspace = null, $user = null, $workspacesCSV = null, $start_date = null, $end_date = null, $object_id = 0, $group_by = null, $order_by = null, $limit = 0, $offset = 0, $timeslot_type = 0, $custom_conditions = null, $object_subtype = null)
 {
     $wslevels = 0;
     foreach ($group_by as $gb) {
         if ($gb == "project_id") {
             $wslevels++;
         }
     }
     $wsDepth = 0;
     if ($workspace instanceof Project) {
         $wsDepth = $workspace->getDepth();
     }
     $wslevels = min(array($wslevels, 10 - $wsDepth));
     if ($wslevels < 0) {
         $wslevels = 0;
     }
     $select = "SELECT `ts`.*";
     for ($i = 0; $i < $wslevels; $i++) {
         $select .= ", `ws" . $i . "`.`name` AS `wsName" . $i . "`, `ws" . $i . "`.`id` AS `wsId" . $i . "`";
     }
     $preFrom = " FROM ";
     for ($i = 0; $i < $wslevels; $i++) {
         $preFrom .= "(";
     }
     $postFrom = "";
     for ($i = 0; $i < $wslevels; $i++) {
         $postFrom .= ") LEFT OUTER JOIN `" . TABLE_PREFIX . "projects` AS `ws" . $i . "` ON `pr`.`p" . ($wsDepth + $i + 1) . "` = `ws" . $i . "`.`id`";
     }
     $commonConditions = "";
     if ($start_date) {
         $commonConditions .= DB::prepareString(' AND `ts`.`start_time` >= ? ', array($start_date));
     }
     if ($end_date) {
         $commonConditions .= DB::prepareString(' AND (`ts`.`paused_on` <> 0 OR `ts`.`end_time` <> 0) AND `ts`.`end_time` < ? ', array($end_date));
     }
     //$commonConditions .= DB::prepareString(' AND (`ts`.`paused_on` <> 0 OR `ts`.`end_time` <> 0) AND `ts`.`end_time` > 0 AND `ts`.`end_time` < ? ', array($end_date));  -- another fix reported by a user, but we have to test it yet
     //User condition
     $commonConditions .= $user ? ' AND `ts`.`user_id` = ' . $user->getId() : '';
     //Object condition
     $commonConditions .= $object_id > 0 ? ' AND `ts`.`object_manager` = "ProjectTasks" AND `ts`.`object_id` = ' . $object_id : '';
     //Only applies to tasks
     $sql = '';
     //Custom properties conditions
     $custom_cond = '';
     $custom = false;
     if (count($custom_conditions) > 0) {
         $custom = true;
         foreach ($custom_conditions as $condCp) {
             //array_var($condCp, 'custom_property_id');
             $cp = CustomProperties::getCustomProperty(array_var($condCp, 'custom_property_id'));
             //$skip_condition = false;
             $dateFormat = 'm/d/Y';
             if (isset($params[array_var($condCp, 'id') . "_" . $cp->getName()])) {
                 $value = $params[array_var($condCp, 'id') . "_" . $cp->getName()];
                 if ($cp->getType() == 'date') {
                     $dateFormat = user_config_option('date_format');
                 }
             } else {
                 $value = array_var($condCp, 'value');
             }
             $custom_cond .= ' AND `pt`.id IN ( SELECT object_id as id FROM ' . TABLE_PREFIX . 'custom_property_values cpv WHERE ';
             $custom_cond .= ' cpv.custom_property_id = ' . array_var($condCp, 'custom_property_id');
             if (array_var($condCp, 'condition') == 'like' || array_var($condCp, 'condition') == 'not like') {
                 $value = '%' . $value . '%';
             }
             if ($cp->getType() == 'date') {
                 $dtValue = DateTimeValueLib::dateFromFormatAndString($dateFormat, $value);
                 $value = $dtValue->format('Y-m-d H:i:s');
             }
             if (array_var($condCp, 'condition') != '%') {
                 if ($cp->getType() == 'numeric') {
                     $custom_cond .= ' AND cpv.value ' . array_var($condCp, 'condition') . ' ' . mysql_real_escape_string($value);
                 } else {
                     $custom_cond .= ' AND cpv.value ' . array_var($condCp, 'condition') . ' "' . mysql_real_escape_string($value) . '"';
                 }
             } else {
                 $custom_cond .= ' AND cpv.value like "%' . mysql_real_escape_string($value) . '"';
             }
             $custom_cond .= ')';
         }
     }
     switch ($timeslot_type) {
         case 0:
             //Task timeslots
             $from = "`" . TABLE_PREFIX . "timeslots` AS `ts`, `" . TABLE_PREFIX . "project_tasks` AS `pt`, `" . TABLE_PREFIX . "projects` AS `pr`, `" . TABLE_PREFIX . "workspace_objects` AS `wo`";
             $conditions = " WHERE `ts`.`object_manager` = 'ProjectTasks'  AND `pt`.`id` = `ts`.`object_id` AND `pt`.`trashed_on` = " . DB::escape(EMPTY_DATETIME) . " AND `pt`.`archived_by_id` = 0 AND `wo`.`object_manager` = 'ProjectTasks' AND `wo`.`object_id` = `ts`.`object_id` AND `wo`.`workspace_id` = `pr`.`id`";
             //Project condition
//.........这里部分代码省略.........
开发者ID:pnagaraju25,项目名称:fengoffice,代码行数:101,代码来源:Timeslots.class.php

示例14: instantiate_template_task_parameters

function instantiate_template_task_parameters(TemplateTask $object, ProjectTask $copy, $parameterValues = array())
{
    $objProp = TemplateObjectProperties::getPropertiesByTemplateObject($object->getTemplateId(), $object->getId());
    $manager = $copy->manager();
    foreach ($objProp as $property) {
        $propName = $property->getProperty();
        $value = $property->getValue();
        if ($manager->getColumnType($propName) == DATA_TYPE_STRING || $manager->getColumnType($propName) == DATA_TYPE_INTEGER) {
            if (is_array($parameterValues)) {
                $is_present = false;
                foreach ($parameterValues as $param => $val) {
                    if (strpos($value, '{' . $param . '}') !== FALSE) {
                        $value = str_replace('{' . $param . '}', $val, $value);
                        $is_present = true;
                    }
                }
                // if parameter not present replace the parameter code with empty string
                if (!$is_present) {
                    $value = preg_replace('/[{].*[}]/U', '', $value);
                }
            }
        } else {
            if ($manager->getColumnType($propName) == DATA_TYPE_DATE || $manager->getColumnType($propName) == DATA_TYPE_DATETIME) {
                $operator = '+';
                if (strpos($value, '+') === false) {
                    $operator = '-';
                }
                $opPos = strpos($value, $operator);
                if ($opPos !== false) {
                    // Is parametric
                    $dateParam = substr($value, 1, strpos($value, '}') - 1);
                    if ($dateParam == 'task_creation') {
                        $date = DateTimeValueLib::now();
                    } else {
                        $date = getDateValue($parameterValues[$dateParam]);
                        if (!$date instanceof DateTimeValue) {
                            $date = DateTimeValueLib::now();
                        }
                        if ($copy instanceof ProjectTask && config_option('use_time_in_task_dates') && $propName == "due_date") {
                            $copy->setUseDueTime(1);
                            $hour_min = getTimeValue(user_config_option('work_day_end_time'));
                            $hour_min['hours'];
                            $hour_min['mins'];
                            $date->setHour($hour_min['hours']);
                            $date->setMinute($hour_min['mins']);
                            $date = $date->add('s', -logged_user()->getTimezone() * 3600);
                        }
                        if ($copy instanceof ProjectTask && config_option('use_time_in_task_dates') && $propName == "start_date") {
                            $copy->setUseStartTime(1);
                            $hour_min = getTimeValue(user_config_option('work_day_start_time'));
                            $hour_min['hours'];
                            $hour_min['mins'];
                            $date->setHour($hour_min['hours']);
                            $date->setMinute($hour_min['mins']);
                            $date = $date->add('s', -logged_user()->getTimezone() * 3600);
                        }
                    }
                    $dateUnit = substr($value, strlen($value) - 1);
                    // d, w or m (for days, weeks or months)
                    if ($dateUnit == 'm') {
                        $dateUnit = 'M';
                        // make month unit uppercase to call DateTimeValue::add with correct parameter
                    }
                    $dateNum = (int) substr($value, strpos($value, $operator), strlen($value) - 2);
                    //Hook::fire('template_param_date_calculation', array('op' => $operator, 'date' => $date, 'template_id' => $object->getTemplateId(), 'original' => $object, 'copy' => $copy), $dateNum);
                    $value = $date->add($dateUnit, $dateNum);
                } else {
                    $value = DateTimeValueLib::dateFromFormatAndString(user_config_option('date_format'), $value);
                }
            }
        }
        if ($value != '') {
            if (!$copy->setColumnValue($propName, $value)) {
                $copy->object->setColumnValue($propName, $value);
            }
            if ($propName == 'text' && $copy->getTypeContent() == 'text') {
                $copy->setText(html_to_text($copy->getText()));
            }
            $copy->save();
        }
    }
    // Ensure that assigned user is subscribed
    if ($copy instanceof ProjectTask && $copy->getAssignedTo() instanceof Contact) {
        $copy->subscribeUser($copy->getAssignedTo());
    }
    $ret = null;
    Hook::fire('after_template_object_param_instantiation', array('template_id' => $object->getTemplateId(), 'original' => $object, 'copy' => $copy, 'parameter_values' => $parameterValues), $ret);
}
开发者ID:abhinay100,项目名称:feng_app,代码行数:88,代码来源:functions.php

示例15: executeReport

	/**
	 * Execute a report and return results
	 *
	 * @param $id
	 * @param $params
	 *
	 * @return array
	 */
	static function executeReport($id, $params, $order_by_col = '', $order_by_asc = true, $offset=0, $limit=50, $to_print = false) {
		if (is_null(active_context())) {
			CompanyWebsite::instance()->setContext(build_context_array(array_var($_REQUEST, 'context')));
		}
		$results = array();
		$report = self::getReport($id);
		if($report instanceof Report){
			$conditionsFields = ReportConditions::getAllReportConditionsForFields($id);
			$conditionsCp = ReportConditions::getAllReportConditionsForCustomProperties($id);
			
			$ot = ObjectTypes::findById($report->getReportObjectTypeId());
			$table = $ot->getTableName();
			
			eval('$managerInstance = ' . $ot->getHandlerClass() . "::instance();");
			eval('$item_class = ' . $ot->getHandlerClass() . '::instance()->getItemClass(); $object = new $item_class();');
			
			$order_by = '';
			if (is_object($params)) {
				$params = get_object_vars($params);				
			}
			
			$report_columns = ReportColumns::getAllReportColumns($id);

			$allConditions = "";
			
			if(count($conditionsFields) > 0){
				foreach($conditionsFields as $condField){
					
					$skip_condition = false;
					$model = $ot->getHandlerClass();
					$model_instance = new $model();
					$col_type = $model_instance->getColumnType($condField->getFieldName());

					$allConditions .= ' AND ';
					$dateFormat = 'm/d/Y';
					if(isset($params[$condField->getId()])){
						$value = $params[$condField->getId()];
						if ($col_type == DATA_TYPE_DATE || $col_type == DATA_TYPE_DATETIME)
						$dateFormat = user_config_option('date_format');
					} else {
						$value = $condField->getValue();
					}
					if ($value == '' && $condField->getIsParametrizable()) $skip_condition = true;
					if (!$skip_condition) {
						if($condField->getCondition() == 'like' || $condField->getCondition() == 'not like'){
							$value = '%'.$value.'%';
						}
						if ($col_type == DATA_TYPE_DATE || $col_type == DATA_TYPE_DATETIME) {
							$dtValue = DateTimeValueLib::dateFromFormatAndString($dateFormat, $value);
							$value = $dtValue->format('Y-m-d');
						}
						if($condField->getCondition() != '%'){
							if ($col_type == DATA_TYPE_INTEGER || $col_type == DATA_TYPE_FLOAT) {
								$allConditions .= '`'.$condField->getFieldName().'` '.$condField->getCondition().' '.DB::escape($value);
							} else {
								if ($condField->getCondition()=='=' || $condField->getCondition()=='<=' || $condField->getCondition()=='>='){
									if ($col_type == DATA_TYPE_DATETIME || $col_type == DATA_TYPE_DATE) {
										$equal = 'datediff('.DB::escape($value).', `'.$condField->getFieldName().'`)=0';
									} else {
										$equal = '`'.$condField->getFieldName().'` '.$condField->getCondition().' '.DB::escape($value);
									}
									switch($condField->getCondition()){
										case '=':
											$allConditions .= $equal;
											break;
										case '<=':
										case '>=':
											$allConditions .= '(`'.$condField->getFieldName().'` '.$condField->getCondition().' '.DB::escape($value).' OR '.$equal.') ';
											break;																
									}										
								} else {
									$allConditions .= '`'.$condField->getFieldName().'` '.$condField->getCondition().' '.DB::escape($value);
								}									
							}
						} else {
							$allConditions .= '`'.$condField->getFieldName().'` like '.DB::escape("%$value");
						}
					} else $allConditions .= ' true';
					
				}
			}
			if(count($conditionsCp) > 0){
				$dateFormat = user_config_option('date_format');
				$date_format_tip = date_format_tip($dateFormat);
				
				foreach($conditionsCp as $condCp){
					$cp = CustomProperties::getCustomProperty($condCp->getCustomPropertyId());

					$skip_condition = false;
					
					if(isset($params[$condCp->getId()."_".$cp->getName()])){
						$value = $params[$condCp->getId()."_".$cp->getName()];
//.........这里部分代码省略.........
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:101,代码来源:Reports.class.php


注:本文中的DateTimeValueLib::dateFromFormatAndString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。