Exemplo n.º 1
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);
 }
Exemplo n.º 2
0
 protected function actionSetEnabled($params)
 {
     $categories = json_decode($params['categories'], true);
     foreach ($categories as $category_id) {
         $enabled = \GO\Customfields\Model\EnabledCategory::model()->findByPk(array('category_id' => $category_id, 'model_name' => $params['model_name'], 'model_id' => $params['model_id']));
         if (!$enabled) {
             $enabled = new \GO\Customfields\Model\EnabledCategory();
             $enabled->category_id = $category_id;
             $enabled->model_name = $params['model_name'];
             $enabled->model_id = $params['model_id'];
             $enabled->save();
         }
     }
     $stmt = \GO\Customfields\Model\EnabledCategory::model()->find(\GO\Base\Db\FindParams::newInstance()->criteria(\GO\Base\Db\FindCriteria::newInstance()->addInCondition('category_id', $categories, 't', true, true)->addCondition('model_name', $params['model_name'])->addCondition('model_id', $params['model_id'])));
     $stmt->callOnEach('delete');
     return array('success' => true);
 }
Exemplo n.º 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;
 }
Exemplo n.º 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);
 }