Exemplo n.º 1
0
 /**
  * Checks if a given link already exists creating it if it doesn't
  *
  * @param string $url The link url
  * @param Model_Droplet $droplet_id Droplet id this link belongs to
  * @param Model_Account $account_id Account id this link belongs to 
  * @return Model_Account_Droplet_Link
  */
 public static function get_link($url, $droplet_id, $account_id)
 {
     $orm_link = Model_Link::get_link_by_url($url, TRUE);
     $account_link = ORM::factory('account_droplet_link')->where('droplet_id', '=', $droplet_id)->where('link_id', '=', $orm_link->id)->where('account_id', '=', $account_id)->find();
     if (!$account_link->loaded()) {
         $account_link->link_id = $orm_link->id;
         $account_link->droplet_id = $droplet_id;
         $account_link->account_id = $account_id;
         $account_link->save();
     }
     return $account_link;
 }
Exemplo n.º 2
0
 public function action_index()
 {
     $sort = $this->request->param('sort', 'title');
     $order = $this->request->param('order', 'ASC');
     //Session::instance()->delete('course_id');
     $criteria = array('filters' => array('title' => $this->request->param('filter_title'), 'description' => $this->request->param('filter_description')));
     $total = Model_Link::link_total($criteria);
     $pagination = Pagination::factory(array('total_items' => $total, 'items_per_page' => 5));
     $criteria = array_merge($criteria, array('sort' => $sort, 'order' => $order, 'limit' => $pagination->items_per_page, 'offset' => $pagination->offset));
     $links = Model_Link::links($criteria);
     $sorting = new Sort(array('Title' => 'title', 'Description' => 'description', 'No Of Questions' => '', 'Actions' => ''));
     $url = 'link/index';
     if ($this->request->param('filter_title')) {
         $url .= '/filter_title/' . $this->request->param('filter_title');
         $filter = $this->request->param('filter_title');
         $filter_select = 'filter_title';
     }
     if ($this->request->param('filter_description')) {
         $url .= '/filter_description/' . $this->request->param('filter_description');
         $filter = $this->request->param('filter_description');
         $filter_select = 'filter_description';
     }
     $sorting->set_link($url);
     $sorting->set_order($order);
     $sorting->set_sort($sort);
     $heading = $sorting->render();
     // Render the pagination links
     $pagination = $pagination->render();
     $links_old = array('delete' => URL::site('/link/delete/'), 'edit' => URL::site('/link/edit/'));
     $table = array('data' => $links);
     $filter_title = $this->request->param('filter_title');
     $filter_description = $this->request->param('filter_description');
     $filter_url = URL::site('link/index');
     $success = Session::instance()->get('success');
     Session::instance()->delete('success');
     $view = View::factory('link/list')->bind('table', $table)->bind('count', $total)->bind('links_old', $links_old)->bind('pagination', $pagination)->bind('filter', $filter)->bind('filter_select', $filter_select)->bind('filter_url', $filter_url)->bind('success', $success);
     $this->content = $view;
 }
Exemplo n.º 3
0
 /**
  * Creates a droplets from the given array
  *
  * @param array $droplet
  * @return array
  */
 public static function create_from_array($droplets)
 {
     if (!count($droplets)) {
         return;
     }
     // Populate identities
     Model_Identity::get_identities($droplets);
     // Hash array with droplet_hash as key and index in droplets array that contain that hash
     $droplets_idx = array();
     foreach ($droplets as $key => &$droplet) {
         if (!isset($droplet['id'])) {
             $hash = md5($droplet['identity_orig_id'] . $droplet['channel'] . $droplet['droplet_orig_id']);
             $droplet['droplet_hash'] = $hash;
             if (empty($droplets_idx[$hash])) {
                 $droplets_idx[$hash] = array();
             }
             $droplets_idx[$hash][] = $key;
         }
     }
     // Insert new drops
     $new_droplets = array();
     if (!empty($droplets_idx)) {
         Swiftriver_Mutex::obtain(get_class(), 3600);
         // Find the drops that already exist by their droplet_hash
         $found_query = DB::select('droplet_hash', 'id')->from('droplets')->where('droplet_hash', 'IN', array_keys($droplets_idx));
         $found = $found_query->execute()->as_array();
         // Update the ids of existing drops found in the db and
         // remove them from droplets_idx to leave new drops
         $new_droplet_count = count($droplets_idx);
         foreach ($found as $hash) {
             foreach ($droplets_idx[$hash['droplet_hash']] as $key) {
                 $droplets[$key]['id'] = $hash['id'];
             }
             $new_droplet_count--;
             unset($droplets_idx[$hash['droplet_hash']]);
         }
         if (!empty($droplets_idx)) {
             // Get a range of IDs to be used in inserting the new drops
             $base_id = Model_Droplet::get_ids($new_droplet_count);
             // Insert into the droplets table
             $query = DB::insert('droplets', array('id', 'channel', 'droplet_hash', 'droplet_orig_id', 'droplet_type', 'droplet_title', 'droplet_content', 'droplet_date_pub', 'droplet_date_add', 'identity_id', 'processing_status'));
             foreach ($droplets_idx as $hash => $keys) {
                 foreach ($keys as $key) {
                     $droplets[$key]['id'] = $base_id;
                 }
                 // PHP has reference issues with array so
                 // we cannot copy the element we have but
                 // refeference it in place as below $droplets[$keys[0]]
                 // otherwise the element will be overwriten if we use a
                 // copy. Sigh.
                 $new_droplets[] = $droplets[$keys[0]];
                 $query->values(array('id' => $base_id++, 'channel' => $droplets[$keys[0]]['channel'], 'droplet_hash' => $droplets[$keys[0]]['droplet_hash'], 'droplet_orig_id' => $droplets[$keys[0]]['droplet_orig_id'], 'droplet_type' => $droplets[$keys[0]]['droplet_type'], 'droplet_title' => $droplets[$keys[0]]['droplet_title'], 'droplet_content' => $droplets[$keys[0]]['droplet_content'], 'droplet_date_pub' => $droplets[$keys[0]]['droplet_date_pub'], 'droplet_date_add' => gmdate("Y-m-d H:i:s", time()), 'identity_id' => $droplets[$keys[0]]['identity_id'], 'processing_status' => self::PROCESSING_STATUS_NEW));
             }
             $query->execute();
         }
         Swiftriver_Mutex::release(get_class());
     }
     // Populate metadata IDs into the drops array
     Model_Tag::get_tags($droplets);
     Model_Link::get_links($droplets);
     Model_Place::get_places($droplets);
     Model_Media::get_media($droplets);
     // Populate the drop's metadata tables
     self::add_metadata($droplets);
     return array($droplets, $new_droplets);
 }