Пример #1
0
 function doBulkUpdate($filter, $do, $ids = array())
 {
     @set_time_limit(600);
     // [TODO] Temp!
     $change_fields = array();
     $custom_fields = array();
     // Make sure we have actions
     if (empty($do)) {
         return;
     }
     // Make sure we have checked items if we want a checked list
     if (0 == strcasecmp($filter, "checks") && empty($ids)) {
         return;
     }
     if (is_array($do)) {
         foreach ($do as $k => $v) {
             switch ($k) {
                 case 'status':
                     switch (strtolower($v)) {
                         case 'open':
                             $change_fields[DAO_CrmOpportunity::IS_CLOSED] = 0;
                             $change_fields[DAO_CrmOpportunity::IS_WON] = 0;
                             $change_fields[DAO_CrmOpportunity::CLOSED_DATE] = 0;
                             break;
                         case 'won':
                             $change_fields[DAO_CrmOpportunity::IS_CLOSED] = 1;
                             $change_fields[DAO_CrmOpportunity::IS_WON] = 1;
                             $change_fields[DAO_CrmOpportunity::CLOSED_DATE] = time();
                             break;
                         case 'lost':
                             $change_fields[DAO_CrmOpportunity::IS_CLOSED] = 1;
                             $change_fields[DAO_CrmOpportunity::IS_WON] = 0;
                             $change_fields[DAO_CrmOpportunity::CLOSED_DATE] = time();
                             break;
                     }
                     break;
                 case 'closed_date':
                     $change_fields[DAO_CrmOpportunity::CLOSED_DATE] = intval($v);
                     break;
                 case 'worker_id':
                     $change_fields[DAO_CrmOpportunity::WORKER_ID] = intval($v);
                     break;
                 default:
                     // Custom fields
                     if (substr($k, 0, 3) == "cf_") {
                         $custom_fields[substr($k, 3)] = $v;
                     }
             }
         }
     }
     $pg = 0;
     if (empty($ids)) {
         do {
             list($objects, $null) = DAO_CrmOpportunity::search(array(), $this->params, 100, $pg++, SearchFields_CrmOpportunity::ID, true, false);
             $ids = array_merge($ids, array_keys($objects));
         } while (!empty($objects));
     }
     $batch_total = count($ids);
     for ($x = 0; $x <= $batch_total; $x += 100) {
         $batch_ids = array_slice($ids, $x, 100);
         DAO_CrmOpportunity::update($batch_ids, $change_fields);
         // Custom Fields
         self::_doBulkSetCustomFields(CrmCustomFieldSource_Opportunity::ID, $custom_fields, $batch_ids);
         unset($batch_ids);
     }
     unset($ids);
 }
Пример #2
0
 function doBulkUpdate($filter, $do, $ids = array())
 {
     @set_time_limit(600);
     // [TODO] Temp!
     $change_fields = array();
     $custom_fields = array();
     // Make sure we have actions
     if (empty($do)) {
         return;
     }
     // Make sure we have checked items if we want a checked list
     if (0 == strcasecmp($filter, "checks") && empty($ids)) {
         return;
     }
     if (is_array($do)) {
         foreach ($do as $k => $v) {
             switch ($k) {
                 case 'status':
                     switch (strtolower($v)) {
                         case 'open':
                             $change_fields[DAO_CrmOpportunity::IS_CLOSED] = 0;
                             $change_fields[DAO_CrmOpportunity::IS_WON] = 0;
                             $change_fields[DAO_CrmOpportunity::CLOSED_DATE] = 0;
                             break;
                         case 'won':
                             $change_fields[DAO_CrmOpportunity::IS_CLOSED] = 1;
                             $change_fields[DAO_CrmOpportunity::IS_WON] = 1;
                             $change_fields[DAO_CrmOpportunity::CLOSED_DATE] = time();
                             break;
                         case 'lost':
                             $change_fields[DAO_CrmOpportunity::IS_CLOSED] = 1;
                             $change_fields[DAO_CrmOpportunity::IS_WON] = 0;
                             $change_fields[DAO_CrmOpportunity::CLOSED_DATE] = time();
                             break;
                     }
                     break;
                 case 'closed_date':
                     $change_fields[DAO_CrmOpportunity::CLOSED_DATE] = intval($v);
                     break;
                 case 'worker_id':
                     $change_fields[DAO_CrmOpportunity::WORKER_ID] = intval($v);
                     break;
                 default:
                     // Custom fields
                     if (substr($k, 0, 3) == "cf_") {
                         $custom_fields[substr($k, 3)] = $v;
                     }
             }
         }
     }
     $pg = 0;
     if (empty($ids)) {
         do {
             list($objects, $null) = DAO_CrmOpportunity::search(array(), $this->params, 100, $pg++, SearchFields_CrmOpportunity::ID, true, false);
             $ids = array_merge($ids, array_keys($objects));
         } while (!empty($objects));
     }
     // Broadcast?
     if (isset($do['broadcast'])) {
         $tpl_builder = DevblocksPlatform::getTemplateBuilder();
         $params = $do['broadcast'];
         if (!isset($params['worker_id']) || empty($params['worker_id']) || !isset($params['subject']) || empty($params['subject']) || !isset($params['message']) || empty($params['message'])) {
             break;
         }
         $is_queued = isset($params['is_queued']) && $params['is_queued'] ? true : false;
         if (is_array($ids)) {
             foreach ($ids as $opp_id) {
                 try {
                     CerberusContexts::getContext(CerberusContexts::CONTEXT_OPPORTUNITY, $opp_id, $tpl_labels, $tpl_tokens);
                     $subject = $tpl_builder->build($params['subject'], $tpl_tokens);
                     $body = $tpl_builder->build($params['message'], $tpl_tokens);
                     $fields = array(DAO_MailQueue::TYPE => Model_MailQueue::TYPE_COMPOSE, DAO_MailQueue::TICKET_ID => 0, DAO_MailQueue::WORKER_ID => $params['worker_id'], DAO_MailQueue::UPDATED => time(), DAO_MailQueue::HINT_TO => $tpl_tokens['email_address'], DAO_MailQueue::SUBJECT => $subject, DAO_MailQueue::BODY => $body, DAO_MailQueue::PARAMS_JSON => json_encode(array('to' => $tpl_tokens['email_address'], 'group_id' => $params['group_id'])));
                     if ($is_queued) {
                         $fields[DAO_MailQueue::IS_QUEUED] = 1;
                     }
                     $draft_id = DAO_MailQueue::create($fields);
                 } catch (Exception $e) {
                     // [TODO] ...
                 }
             }
         }
     }
     $batch_total = count($ids);
     for ($x = 0; $x <= $batch_total; $x += 100) {
         $batch_ids = array_slice($ids, $x, 100);
         DAO_CrmOpportunity::update($batch_ids, $change_fields);
         // Custom Fields
         self::_doBulkSetCustomFields(CrmCustomFieldSource_Opportunity::ID, $custom_fields, $batch_ids);
         unset($batch_ids);
     }
     unset($ids);
 }