Пример #1
0
 /**
  * Get the data for model edit forms. It should be added to $response['customfields'] in a model controller when loading the edit dialog.
  * It's also usefull to put into calendar or addressbook select combo's so you can update the tabs on change of the combo.
  * 
  * @param string $modelName Model of the customfields
  * @param int $modelId Model of the controlling model a calendar id for the event custom fields for example.
  * @return array array("disable_categories"=>true,"enabled_categories"=>array(1,2)) 
  */
 public static function getEnabledCategoryData($modelName, $modelId)
 {
     $response['disable_categories'] = \GO\Customfields\Model\DisableCategories::isEnabled($modelName, $modelId);
     if ($response['disable_categories']) {
         $response['enabled_categories'] = \GO\Customfields\Model\EnabledCategory::model()->getEnabledIds($modelName, $modelId);
     }
     return $response;
 }
Пример #2
0
 protected function afterDisplay(&$response, &$model, &$params)
 {
     \GO::debug(get_class($this));
     $response['data']['photo_url'] = $model->photoThumbURL;
     $response['data']['original_photo_url'] = $model->photoURL;
     $response['data']['addressbook_name'] = $model->addressbook->name;
     $response['data']['google_maps_link'] = \GO\Base\Util\Common::googleMapsLink($model->address, $model->address_no, $model->city, $model->country);
     $response['data']['formatted_address'] = nl2br($model->getFormattedAddress());
     $response['data']['post_google_maps_link'] = \GO\Base\Util\Common::googleMapsLink($model->post_address, $model->post_address_no, $model->post_city, $model->post_country);
     $response['data']['post_formatted_address'] = nl2br($model->getFormattedPostAddress());
     $response['data']['employees'] = array();
     $sortAlias = \GO::user()->sort_name == "first_name" ? array('first_name', 'last_name') : array('last_name', 'first_name');
     $stmt = $model->contacts(\GO\Base\Db\FindParams::newInstance()->order($sortAlias));
     while ($contact = $stmt->fetch()) {
         $response['data']['employees'][] = array('id' => $contact->id, 'name' => $contact->getName(\GO::user()->sort_name), 'function' => $contact->function, 'email' => $contact->email);
     }
     if (\GO::modules()->customfields && isset($response['data']['customfields']) && \GO\Customfields\Model\DisableCategories::isEnabled("GO\\Addressbook\\Model\\Company", $model->addressbook_id)) {
         $ids = \GO\Customfields\Model\EnabledCategory::model()->getEnabledIds("GO\\Addressbook\\Model\\Company", $model->addressbook_id);
         $enabled = array();
         foreach ($response['data']['customfields'] as $cat) {
             if (in_array($cat['id'], $ids)) {
                 $enabled[] = $cat;
             }
         }
         $response['data']['customfields'] = $enabled;
     }
     if (\GO::modules()->isInstalled('customfields')) {
         $response['data']['items_under_blocks'] = array();
         $enabledBlocksStmt = \GO\Customfields\Model\EnabledBlock::getEnabledBlocks($model->addressbook_id, 'GO\\Addressbook\\Model\\Addressbook', $model->className());
         foreach ($enabledBlocksStmt as $i => $enabledBlockModel) {
             $items = $enabledBlockModel->block->getItemNames($model->id, $model->name);
             if (!empty($items)) {
                 $blockedItemsEl = array('id' => $i, 'block_name' => $enabledBlockModel->block->name, 'items' => $items);
                 $blockedItemsEl['model_name'] = !empty($items[0]) ? $items[0]['model_name'] : '';
                 $modelNameArr = explode('_', $blockedItemsEl['model_name']);
                 $blockedItemsEl['type'] = !empty($modelNameArr[3]) ? $modelNameArr[3] : '';
                 $response['data']['items_under_blocks'][] = $blockedItemsEl;
             }
         }
     }
     return parent::afterDisplay($response, $model, $params);
 }
Пример #3
0
 private function _processCustomFieldsDisplay($model, $response)
 {
     $customAttributes = $model->customfieldsRecord->getAttributes('html');
     //Get all field models and build an array of categories with their
     //fields for display.
     $findParams = \GO\Base\Db\FindParams::newInstance()->order(array('category.sort_index', 't.sort_index'), array('ASC', 'ASC'));
     $findParams->getCriteria()->addCondition('extends_model', $model->customfieldsRecord->extendsModel(), '=', 'category');
     $stmt = \GO\Customfields\Model\Field::model()->find($findParams);
     $categories = array();
     while ($field = $stmt->fetch()) {
         if (!isset($categories[$field->category_id])) {
             $categories[$field->category->id]['id'] = $field->category->id;
             $categories[$field->category->id]['name'] = $field->category->name;
             $categories[$field->category->id]['fields'] = array();
         }
         if (!empty($customAttributes[$field->columnName()])) {
             if ($field->datatype == "GO\\Customfields\\Customfieldtype\\Heading") {
                 $header = array('name' => $field->name, 'value' => $customAttributes[$field->columnName()]);
             }
             if (!empty($header)) {
                 $categories[$field->category->id]['fields'][] = $header;
                 $header = null;
             }
             $categories[$field->category->id]['fields'][] = array('name' => $field->name, 'datatype' => $field->datatype, 'value' => $customAttributes[$field->columnName()]);
         }
     }
     foreach ($categories as $category) {
         if (count($category['fields'])) {
             $response['data']['customfields'][] = $category;
         }
     }
     if (isset($response['data']['customfields']) && method_exists($model, 'getDisabledCustomFieldsCategoriesField') && \GO\Customfields\Model\DisableCategories::isEnabled($model->className(), $model->disabledCustomFieldsCategoriesField)) {
         $ids = \GO\Customfields\Model\EnabledCategory::model()->getEnabledIds($model->className(), $model->getDisabledCustomFieldsCategoriesField());
         $enabled = array();
         foreach ($response['data']['customfields'] as $cat) {
             if (in_array($cat['id'], $ids)) {
                 $enabled[] = $cat;
             }
         }
         $response['data']['customfields'] = $enabled;
     }
     return $response;
 }
Пример #4
0
 protected function afterDisplay(&$response, &$model, &$params)
 {
     $response['data']['name'] = $model->name;
     $response['data']['photo_url'] = $model->photoThumbURL;
     $response['data']['original_photo_url'] = $model->photoURL;
     $response['data']['addressbook_name'] = $model->addressbook->name;
     $company = $model->company();
     if ($company) {
         $response['data']['company_name'] = $company->name;
         $response['data']['company_name2'] = $company->name2;
         $response['data']['company_formatted_address'] = nl2br($company->getFormattedAddress());
         $response['data']['company_google_maps_link'] = \GO\Base\Util\Common::googleMapsLink($company->address, $company->address_no, $company->city, $company->country);
         $response['data']['company_formatted_post_address'] = nl2br($company->getFormattedPostAddress());
         $response['data']['company_google_maps_post_link'] = \GO\Base\Util\Common::googleMapsLink($company->post_address, $company->post_address_no, $company->post_city, $company->post_country);
         $response['data']['company_email'] = $company->email;
         $response['data']['company_phone'] = $company->phone;
     } else {
         $response['data']['company_name'] = '';
         $response['data']['company_name2'] = '';
         $response['data']['company_formatted_address'] = '';
         $response['data']['company_google_maps_link'] = '';
         $response['data']['company_formatted_post_address'] = '';
         $response['data']['company_google_maps_post_link'] = '';
         $response['data']['company_email'] = '';
         $response['data']['company_phone'] = '';
     }
     $response['data']['google_maps_link'] = \GO\Base\Util\Common::googleMapsLink($model->address, $model->address_no, $model->city, $model->country);
     $response['data']['formatted_address'] = nl2br($model->getFormattedAddress());
     $response['data']['action_date'] = \GO\Base\Util\Date::get_timestamp($model->action_date, false);
     if (\GO::modules()->customfields && isset($response['data']['customfields']) && \GO\Customfields\Model\DisableCategories::isEnabled("GO\\Addressbook\\Model\\Contact", $model->addressbook_id)) {
         $ids = \GO\Customfields\Model\EnabledCategory::model()->getEnabledIds("GO\\Addressbook\\Model\\Contact", $model->addressbook_id);
         $enabled = array();
         foreach ($response['data']['customfields'] as $cat) {
             if (in_array($cat['id'], $ids)) {
                 $enabled[] = $cat;
             }
         }
         $response['data']['customfields'] = $enabled;
     }
     if (\GO::modules()->isInstalled('customfields')) {
         $response['data']['items_under_blocks'] = array();
         $enabledBlocksStmt = \GO\Customfields\Model\EnabledBlock::getEnabledBlocks($model->addressbook_id, 'GO\\Addressbook\\Model\\Addressbook', $model->className());
         foreach ($enabledBlocksStmt as $i => $enabledBlockModel) {
             $items = $enabledBlockModel->block->getItemNames($model->id, $model->name);
             if (!empty($items)) {
                 $blockedItemsEl = array('id' => $i, 'block_name' => $enabledBlockModel->block->name, 'items' => $items);
                 $blockedItemsEl['model_name'] = !empty($items[0]) ? $items[0]['model_name'] : '';
                 $modelNameArr = explode('_', $blockedItemsEl['model_name']);
                 $blockedItemsEl['type'] = !empty($modelNameArr[3]) ? $modelNameArr[3] : '';
                 $response['data']['items_under_blocks'][] = $blockedItemsEl;
             }
         }
     }
     return parent::afterDisplay($response, $model, $params);
 }