/** * Return manager instance * * @access protected * @param void * @return ContactWebpages */ function manager() { if (!$this->manager instanceof ContactWidgets) { $this->manager = ContactWidgets::instance(); } return $this->manager; }
function getContactWidgetSettings($contact) { if (!$contact instanceof Contact) { $contact = logged_user(); } $info = $this->getDefaultWidgetSettings(); $contact_widget = ContactWidgets::instance()->findOne(array('conditions' => array('contact_id = ? AND widget_name = ?', $contact->getId(), $this->getName()))); if ($contact_widget instanceof ContactWidget) { $info['order'] = $contact_widget->getOrder(); $info['section'] = $contact_widget->getSection(); $info['options'] = ContactWidgetOptions::instance()->getContactOptions($contact_widget->getWidgetName(), $contact->getId()); } return $info; }
/** * This function will return paginated result. Result is an array where first element is * array of returned object and second populated pagination object that can be used for * obtaining and rendering pagination data using various helpers. * * Items and pagination array vars are indexed with 0 for items and 1 for pagination * because you can't use associative indexing with list() construct * * @access public * @param array $arguments Query argumens (@see find()) Limit and offset are ignored! * @param integer $items_per_page Number of items per page * @param integer $current_page Current page number * @return array */ function paginate($arguments = null, $items_per_page = 10, $current_page = 1) { if (isset ( $this ) && instance_of ( $this, 'ContactWidgets' )) { return parent::paginate ( $arguments, $items_per_page, $current_page ); } else { return ContactWidgets::instance ()->paginate ( $arguments, $items_per_page, $current_page ); } // if } // paginate
static function renderSection($name) { $widgetsToRender = array(); self::$widgets = Widgets::instance()->findAll(array("conditions" => " plugin_id = 0 OR plugin_id IS NULL OR plugin_id IN ( SELECT id FROM " . TABLE_PREFIX . "plugins WHERE is_activated > 0 AND is_installed > 0 )", "order" => "default_order", "order_dir" => "DESC")); // If exists an instance of cw for this section, render the widgets with the options overriden foreach (self::$widgets as $w) { /* @var $w Widget */ if ($cw = ContactWidgets::instance()->findById(array('contact_id' => logged_user()->getId(), 'widget_name' => $w->getName()))) { if ($cw->getSection() == $name) { $w->setOptions($cw->getOptions()); $w->setDefaultOrder($cw->getOrder()); $widgetsToRender[] = $w; } } elseif ($w->getDefaultSection() == $name) { $widgetsToRender[] = $w; } } usort($widgetsToRender, "widget_sort"); foreach ($widgetsToRender as $k => $w) { $w->execute(); } }
function configure_widgets_submit() { ajx_current("empty"); $widgets_data = array_var($_POST, 'widgets'); try { DB::beginWork(); foreach ($widgets_data as $name => $data) { $contact_widget = ContactWidgets::instance()->findOne(array('conditions' => array('contact_id = ? AND widget_name = ?', logged_user()->getId(), $name))); if (!$contact_widget instanceof ContactWidget) { $contact_widget = new ContactWidget(); $contact_widget->setContactId(logged_user()->getId()); $contact_widget->setWidgetName($name); } $contact_widget->setOrder($data['order']); $contact_widget->setSection($data['section']); $contact_widget->save(); if (isset($data['options']) && is_array($data['options'])) { foreach ($data['options'] as $opt_name => $opt_val) { $contact_widget_option = ContactWidgetOptions::instance()->findOne(array('conditions' => array('contact_id=? AND widget_name=? AND `option`=?', logged_user()->getId(), $name, $opt_name))); if (!$contact_widget_option instanceof ContactWidgetOption) { $contact_widget_option = new ContactWidgetOption(); $contact_widget_option->setContactId(logged_user()->getId()); $contact_widget_option->setWidgetName($name); $contact_widget_option->setMemberTypeId(0); $contact_widget_option->setOption($opt_name); } $contact_widget_option->setValue($opt_val); $contact_widget_option->save(); } } } DB::commit(); evt_add('reload tab panel', 'overview-panel'); ajx_current("back"); } catch (Exception $e) { flash_error($e->getMessage()); DB::rollback(); } }