Exemplo n.º 1
0
 protected function actionEnable($params)
 {
     $response['success'] = true;
     $enableBlockModel = \GO\Customfields\Model\EnabledBlock::model()->findSingleByAttributes(array('block_id' => $params['block_id'], 'model_id' => $params['model_id'], 'model_type_name' => $params['model_name']));
     if (!empty($params['enable']) && $params['enable'] !== 'false') {
         if (!$enableBlockModel) {
             $enableBlockModel = new \GO\Customfields\Model\EnabledBlock();
             $enableBlockModel->block_id = $params['block_id'];
             $enableBlockModel->model_id = $params['model_id'];
             $enableBlockModel->model_type_name = $params['model_name'];
             $response['success'] = $enableBlockModel->save();
         }
     } else {
         if ($enableBlockModel) {
             $response['success'] = $enableBlockModel->delete();
         }
     }
     echo $this->renderJson($response);
 }
Exemplo n.º 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);
 }
Exemplo n.º 3
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);
 }